Posted 09 June 2013 - 11:13 AM
How can I call a variable from a string name? I mean like if I enter the name of a variable it returns the value.
_G[name]()
Where _G is the table the variable is member of. If the variable is local, you can't do this, unless you put it into a local table. If it's an ordinary function like fs.open, it's part of _G, a global table provided by Lua. name is a name like "fs.open" without parentheses.local func = loadstring(name)
if not func then func = loadstring("return " .. name) end
if func then func() end
name is a name like "fs.open()" with parentheses.