lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

Thank you, guys.
As Kevin stated, I will try recreating the lua state.

Tables of functions seems jerry-rigged, since I don't know what the user will write in the script.
Garbage collector seems nice, but I still don't fully understand it (need to read more about it).

Thank you!

2014-03-03 9:23 GMT-03:00 Kevin Martin <>:
On 3 Mar 2014, at 12:06, Felipe Ferreira da Silva <> wrote:

>       // !!!Delete the chunk here!!!

The chunk itself will be subject to garbage collection after your first pcall, as there are no longer any references to it. However, it doesn't appear to be the chunk you're worried about, but rather the side effects of running the chunk, which I don't think there is a general solution (other than recreate the lua_State)

Obviously you could remove the global called function (bad name for a variable, but whatever) as follows

lua_setglobal(BWindowHandler->lua, "function");

but this won't undo any other side effects of the script, nor will it remove any other references to that value.

If re-opening the state is an option, I would consider that, else rewrite your user scripts to work more like modules and return tables of functions, rather than modifying the global state.


- Felipe Ferreira da Silva