On 18 June 2011 18:53, Rebel Neurofog
<rebelneurofog@gmail.com> wrote:
>> There's a way to attach a pointer (possibly pointing to structure of
>> several things you will actually use) to lua_State
>> by passing it to lua_newstate () or by setting it with lua_setallocf ().
>
> Actually I think the correct method for this is to set LUAI_EXTRASPACE in
> luaconf.h
2. The feature is per-coroutine rather than per global_State.
So using LUAI_EXTRASPACE would lead to unnecessary allocations and
access to main thread's state like ((void*) (G(L)->mainthread) -
sizeof (void*)).
Looks like Spartaaaaaa!!!!!!!!!!111...
It is still possible to do this at runtime although I would not recommend it, rather I will just give the evil information. From looking at the source we know that when the allocator is called for the creation of an LG then the state pointer in the allocator is NULL so you can set an allocator and identify this situation adding add extra bytes to the front or back of LG. When the state is closing the L and ptr will be the same.
Here is some output of a runtime hooked version of a Lua program.
...
...
[HOOOKED INFO] state 0x1001000b0 cleaned and no leaks
[HOOOKED INFO] Lua 0x1001000b0 free 0x1001000b0 size 616 byte count: 0
[HOOOKED INFO] after hooked function lua_close_hook
after lua_close