lua-users home
lua-l archive

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

>>Does anyone have any good suggestions for how to deal with getting
>>to some private instance data when in a global C function called by 

>How about upvalues (ie C closures)? There's also the registry, where
you can store anything you want. --lhf

Upvalues won't work. I need a solution that applies to all functions
that could be called by Lua, including tag methods and call/line hooks.

Two people suggesting using the registry??? You guys scare me! :-) If I
were going to do that, I'd rather create a global variable in the lua
state and use that. But the point is I want a VERY fast O(1) map
(because it will be used all the time) from the lua_State to some
pointer into my own stuff. I think I'm going to resort to modifying Lua,
and I would make this a feature request for 4.1. 

Just add the following two functions:
LUA_API void * lua_GetPrivateData(lua_State *L)
    return L->pprivatedata;

LUA_API void * lua_SetPrivateData(lua_State *L, void * p)
    L->pprivatedata = p;
And add
	void * pprivatedata;
to the struct lua_State.