In a C app when I call a Lua script, do the variables in the code stay with the same value when I call the script again later?
+5
A:
They will still exist in the lua state you created until you close that state. The variables are tied to the state not the script file.
edit
As noted in the comments local variables will be garbage collected when they go out of scope. A further caveat is that Lua supports closures and upvalues so the scope may not always be completely obvious.
Nick
2010-07-12 18:15:13
I would caveat that by stating that *global* variables remain with the Lua state. Local variables within the Lua script will be garbage collected.
Judge Maygarden
2010-07-12 19:47:46
+1 and duly noted
Nick
2010-07-12 23:30:59
and of course upvalues (external locals) stay with the functions in the lua state that they belong to, until the functions can be garbage collected.
kaizer.se
2010-07-13 10:30:39