|
> // !!!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_pushnil(BWindowHandler->lua);
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.
Thanks,
Kevin