1
vote
1answer
53 views

Corona Runtime Error: “attempt to call a nil value”

The code below is from a class that creates and returns an alien ship to main.lua in a space shooter game. I need to include a function that determines what happens if this ship hits an object, but ...
1
vote
1answer
38 views

attempt to fix global 'SWEP' a nil value

I am trying to create a weapon for a friend on Garry's Mod with Lua. I have made it through all other errors but I keep getting this error: input:22: attempt to index global SWEP (a nil value) I ...
4
votes
3answers
64 views

List Lua functions in a file

How can I list all the functions included in a Lua source file? For example, I have fn.lua which contains function test1() print("Test 1") end function test2() print("Test 2") end ...
1
vote
3answers
55 views

Lua - Execute a Function Stored in a Table

I was able to store functions into a table. But now I have no idea of how to invoke them. The final table will have about 100 calls, so if possible, I'd like to invoke them as if in a foreach loop. ...
4
votes
1answer
62 views

Function creating in Lua

When I create the function by assigning ,"if" condition doesn't work but when I do create the function like in second example below, it works. Can you tell me why? Not working: local start=os.time() ...
3
votes
2answers
66 views

How to pass a function as a parameter in Lua?

Bit confused by all this; so here's what I am attempting to do! Have a def thus: block_basic_DEF = { image = "button.png", name = "basic block", obj_table = ...
1
vote
2answers
51 views

Corona Lua call external function

I have block_basic.lua that I want to call another function in touch_input.lua block_basic.lua does: local screen_touch = require( "touch_input") local onScreenTouch = screen_touch.onScreenTouch ...
0
votes
0answers
50 views

Luabind - Inheritance / virtual functions

I am trying to expose my scenegraph to lua and I am trying to do that using luabind. I fiddled around with luabind and got things to work quite nicely until I stumbled upon the problem with virtual ...
0
votes
3answers
52 views

dynamic tables or arrays

I have a function that is meant to dynamically change the size of a 3D Array or table but it keeps breaking saying that it return value nil because it is out of bounds. Here is the code for it: ...
3
votes
2answers
93 views

Using the 'module' function in Lua 5.2?

I have a VC++ project which uses Lua 5.2 for scripting. I am trying to implement MySQL compatibility into this project. I do not own this project, so I would prefer to change as little source code as ...
1
vote
1answer
46 views

Change the object (car) speed

I need to change the object speed after I changed his rotation. function love.update(dt) if car['speed'] > 0 then car['x'] = car['x'] + math.cos(car['angle']) car['y'] = car['y'] + ...
2
votes
2answers
56 views

Concatenate a Function Name in Lua

This is probably really simple but I'm new so here we go.. How would I code this: local color1 = { 255,0,0 } local color2 = { 1,200,1 } local color3 = { 2,2,150 } for i = 1, 3 do local x = ...
0
votes
2answers
69 views

Can I use the function yes () to return 1

Is the following function is correct? local function yes() return 1 end local function no() return 0 end Can I use it to set the values ​​of the variables in this way? local May_I = yes() if ...
0
votes
1answer
32 views

Getting variable from a function

function isEven(x) print("Checking if "..x.." is even.\nWill return state as 1 if true.") if math.fmod(x, 2) == 0 then state = 1 end return state end I know that I can just ...
4
votes
2answers
71 views

Lua functions — a simple misunderstanding

I'm trying to develop a function which performs math on two values which have the same key: property = {a=120, b=50, c=85} operator = {has = {a, b}, coefficient = {a = 0.45}} function Result(x) ...
3
votes
1answer
89 views

call a Lua function just by writing its name (without parentheses)

I'm looking forward to using a variable like "asdf" instead of writing the name function to check its return (which changes now and then). That's why "asdf" variable should update its value everytime ...
0
votes
3answers
50 views

Call function when class is deleted/garbage collected

I have a class that opens a sqlite database in its constructor. Is there a way to have it close the database when it is destroyed (whether that be due to the programmer destroying it or being ...
1
vote
2answers
52 views

Why does clearing a passed table not work inside the function's scope?

Clearing a table like so causes expected behavior: table1 = { "a" } table1 = {} print(unpack(table1)) -- results in printing a blank line But if you do the same thing inside a function, it ...
0
votes
1answer
122 views

LUA - How to call a function from a string using the _G[x]() method

I'm having a problem with my code and I don't know what's up, I've searched online and the _Gx method was suggested as the best way over ones like loadstring(x)... although I would be happy with ...
0
votes
1answer
155 views

Corona sdk, functions run in wrong order?

I'm trying to save some data in to a table. I get the data from a database and it works ok. My problem is that the data is not saved in the table. It is a lua table like table = {} and NOT a database ...
2
votes
1answer
113 views

Nil error when trying to call a function in Lua

I'm getting a strange error that I can't for the life of me crack. I'm coding a card game and I have two tables of different lengths. One links entries to functions, and the other holds the played ...
3
votes
2answers
124 views

Make two objects touchable which were created with a function (LUA, Corona)

I gues this is a real newbie question, but I have the following code: local function createCircle() [...] circle = display.newCircle( positionX, positionY, circleRadius ) [...] end function ...
2
votes
2answers
402 views

Variables Resetting When Using Parallel Function in Lua with ComputerCraft

I am a beginner designing a Lua program in ComputerCraft (Minecraft) that asks the player for their name the first time they use it, and records it. For now, I want a program that detects if the ...
1
vote
0answers
250 views

LuaInterface/C# - Closures created with .NET objects never get cleaned up

I am using the latest version of LuaInterface (http://code.google.com/p/luainterface/) in a C# application. I'm running into a problem where the Lua class is failing to clean up internal references in ...
4
votes
4answers
134 views

Can lua function references be used as table keys?

A Lua newbie here. Can I store function references as keys in a Lua Table? Something similar to this: local fn = function() print('hello') end local my_table = {} my_table[fn] = 123 This does seem ...
1
vote
3answers
93 views

Lua table read and match efficient

My problem is simple, i used to do this in order to check if any of my lines (see photo) bump into any other line (or trail of any other line). But the way i do this now is by doing a lot of if ...
4
votes
3answers
389 views

Passing array as function parameter in Lua?

I'm trying to alter the class example I found in this video to make it a bit more streamlined to use. Hopefully my comments explain what I'm trying to accomplish well enough. The problem I'm having is ...
0
votes
1answer
270 views

Corona sdk enterframe event issue with director

I am having problems with getting a scene to change based on event listeners and global variables. Basically the scene reiterates after certain selections have been made which increments the ...
1
vote
1answer
754 views

Lua error: string expected, got nil

I need help with my scripts. I tried nearly everything, but I can't figure it out what the problem is. I want look.lua to check if str = str.."\nIt's "..getPokemonAge(thing.uid).." old." Returns with ...
1
vote
2answers
118 views

extracting file data with lua

here's what i've been trying to do with lua. i have a ton of pictures i transfer back and forth between 2+ computers. I always end up having multiple copies of pictures. I would like my lua code to ...
5
votes
3answers
297 views

Trying to call a function in Lua with nested tables

I am trying to create a C function called Dfetch() that is registered in Lua as fetch(). I am looking for it to be tiered such that I can call dog.beagle.fetch() as the function from Lua. It just ...
1
vote
2answers
76 views

Populating a table inside a Lua function isn't reflected outside

I'm trying to populate a table inside one function and then use the values it received in a later call, removing each value after it has been used. For some reason the values aren't persisting between ...
-1
votes
1answer
71 views

Forward function parameter arg in lua

I would like to override a function to inspect its parameter values but the call it and pass the original parameters as normal. Is this possible? I am using Corona SDK by www.coronalabs.com My code ...
5
votes
1answer
195 views

Finding every combination of elements in a table (Lua/PseudoCode)

I'm trying to execute a function with every single combination of elements from a table. (In Lua). The table and the elements can change, but the structure will stay the same. The table is ...
3
votes
1answer
81 views

Receive any notify when call undefined function in lua

In C++ code: class CWindowUI { public CWindowUI(const char* title,int width,int height); ..... }; static int CreateWindow(lua_State *l) { int width,height; char *title; ...
0
votes
1answer
111 views

detecting single nil argument in lua

Is it possible to distinguish the call myFunc() from myFunc(nil) inside the function myFunc?
0
votes
1answer
131 views

Error when defining a function in lua, corona sdk

Please, help me figure out what is the problem in the code. I am defining a function local function goOnLesson() if date.hour==1 then index=1 local subj=schToday[index] local text = ...
0
votes
2answers
93 views

lua post hooking a function

I found one topic that's about post hooking, but I don't think it's the same thing as I want to accomplish. topic i found What I need is the following: local someBoolean = false function ...
1
vote
1answer
195 views

Call Lua function by reference

OK, I searched for this, but to no avail. It's kind of a vague thought/idea so... here goes. Is it possible, in Lua, to call a function (with declared values) and then call it again by reference ...
1
vote
2answers
373 views

Global function in lua

Is there a way to have a function in Lua that can be accessed from any module in a project without having to first require it? something like: module(..., package.seeall); function globFoo() ...
0
votes
1answer
131 views

Concatenation of functions in Lua

I am trying to concatenate a function, as it's really a variable for a player's name, through the use of Lua. The game is once again Command and Conquer: Renegade. The error is: Attempt to ...
0
votes
1answer
203 views

LZW Data Compression In Lua [duplicate]

Possible Duplicate: LZW Compression In Lua Here is my code for compressing data in Lua using the LZW compression method. My problem is that the function is returning the character 'T', ...
2
votes
2answers
246 views

LZW Compression In Lua

Here is the Pseudocode for Lempel-Ziv-Welch Compression. pattern = get input character while ( not end-of-file ) { K = get input character if ( <<pattern, K>> is NOT in ...
0
votes
1answer
191 views

Reverse String in Lua?

I am trying to reverse a string in Lua without using the string.reverse() function. Here is my code - function reverseStr(s) return string.gsub(s, "(.)(.)", "%2%1") end The code is currently ...
1
vote
2answers
173 views

Lua Max Number Finder

Here is my code for a simple program that finds the largest number in a table, and returns the number and it's index. My problem is that the program isn't working with negatives. numbers = {1, 2, ...
1
vote
2answers
544 views

Calling a lua function from table.subtable in C++

im trying to call a lua function from C++ where function is in subtable of global table. Im using lua version 5.2.* compiled from source. Lua function function globaltable.subtable.hello() -- do ...
1
vote
1answer
711 views

C++ & Lua, push Lua table as argument

I'm integrating Lua in C++, and now I have this table that behaves as a 'class', and for some functions it needs a 'self' argument, which actually is the table. The Lua code: a = { numb = 5, create ...
1
vote
2answers
132 views

How do I make Lua pause from runing a while?

I was looking for a way to pause my program to allow the user to read before it closes but the function (os.sleep(timeSeconds)) doesn't exist apparently. Anyone know a work around? Thanks
1
vote
1answer
155 views

How can I resolve function-dependency loops in Lua?

In my Lua code (using the Corona SDK), my issue essentially boils down to this: local function foo() bar() end local function bar() foo() end However, because Lua is done line-by-line, ...
0
votes
2answers
93 views

Creating Lua Functions to avoid code repetition in the same file

I am having following type of code ,that I used 6-7 times in the same file: str=(line):match("constraints(.*)end") for split in string_gsplit(str, '\n', true) do if string.match(split,'%a+') then ...

1 2 3
15 30 50 per page