If I have a parameter variable that is a string that holds user input. How can I use that string name to call the assosiated table?
parameter.text("tbl") --user typed "smoke"
smoke = {}
smoke.x = 5
tbl.x --I want to print the smoke table.
If I have a parameter variable that is a string that holds user input. How can I use that string name to call the assosiated table?
parameter.text("tbl") --user typed "smoke"
smoke = {}
smoke.x = 5
tbl.x --I want to print the smoke table.
I was needing to do this for Particular Particle. However Having a bunch of tables with various names could lead to naming conflicts, so I changed my approach.
Although, this is great info to know. Thanks!
The loadstring function should do what you want
smoke={}
smoke.x = 5
parameter.text("tbl")
parameter.action("press",function()
local f = loadstring("print("..tbl..".x)")
f()
end)
Edit: Then some inventive string manipulation for no hard coded bits
Edit 2: Some further info: http://www.lua.org/pil/8.html
Totally didn’t think of that! Thanks.
Or you can access the _G
table:
tbl = "smoke"
smoke = {}
smoke.x = 5
print(_G[tbl].x)
I think this would be faster than loadstring.
Ah nice! - now I totally didn’t think of that !