Posted 02 March 2013 - 10:00 AM
Hi, long time stalker, new poster here.
I'm trying to build an array of computers counting items through tubes, reporting to a master server and I've hit a problem I can't seem to be able to fix on my own (lua-users, google, other searches, this forum, etc) I might be asking the question wrong, which is why I can't find what I'm looking for.
I have a background writing OOP in AS3, Java and PHP and I've done quite a bit of scripting (AS2, PHP, JavaScript) but I'm very new to Lua so there's quite a lot I don't grasp yet.
So simplifying my code down to the issue itself (removing irrelevant code, like the double table lookups and the params I want to call with the function etc) I've got something like this:
There were more attempts as well, but they all fall back on these techniques.
And I don't understand the error from the second loadstring at all.
Hope some of you can help, thanks! :)/>/>
PS: Not a native English speaker, so I apologize for any grammar errors in advance. :)/>/>
I'm trying to build an array of computers counting items through tubes, reporting to a master server and I've hit a problem I can't seem to be able to fix on my own (lua-users, google, other searches, this forum, etc) I might be asking the question wrong, which is why I can't find what I'm looking for.
I have a background writing OOP in AS3, Java and PHP and I've done quite a bit of scripting (AS2, PHP, JavaScript) but I'm very new to Lua so there's quite a lot I don't grasp yet.
So simplifying my code down to the issue itself (removing irrelevant code, like the double table lookups and the params I want to call with the function etc) I've got something like this:
-- Calling a function from a string, setup and attempt log. (I called the app test)
-- function and string.
local function foo()
print("Hello, world!")
end
local str = "foo"
--Now I attempt to call local str as a function,
--These are some of my attempts, neither of which works.
--All commented out, with the thrown error included.
-- loadstring(str)() --> test:15: attempt to call nil (line 15 is this line)
-- loadstring(str .. "()")() --> string:1: attempt to call nil (line 1 is the first comment?!?)
-- _G[str]() --> test:17: attempt to call nil (line 17 is this line)
-- _G[str .. "()"]() --> test:18: attempt to call nil (line 18 is this line)
-- wits end..
There were more attempts as well, but they all fall back on these techniques.
And I don't understand the error from the second loadstring at all.
Hope some of you can help, thanks! :)/>/>
PS: Not a native English speaker, so I apologize for any grammar errors in advance. :)/>/>