[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: [C API] Can I delete a chunk from my lua_State?
- From: Kevin Martin <kev82@...>
- Date: Mon, 3 Mar 2014 12:23:06 +0000
On 3 Mar 2014, at 12:06, Felipe Ferreira da Silva <felipefsdev@gmail.com> 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_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