Loadstring, how to use?

2

I'm using the loadstring function, but I do not know if this is the right way:

a= "st = {b=1, c=2}"
st = {}
b = loadstring(a)
b()
print(st.b)

Is there any simpler way?

    
asked by anonymous 22.11.2014 / 04:33

1 answer

3

If you do not need to create the global variable st , use

b = loadstring("return {b=1, c=2}")()

If you want to do this many times, consider something like

function eval(x)
  return loadstring("return "..x)()
end
    
23.11.2014 / 12:30