lua-users home
lua-l archive

Re: What's the point of LUA_USERSTATE?

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


Hi,
> I was trying to see if I can get away with defining LUA_USERSTATE before
> including lua.h instead of modifying Lua to store and expose user data
> (which I do currently), but since the definition of lua_State isn't
> included in lua.h, how are you supposed to access LUA_USERSTATE given a
> lua_State?
Let's say you want to store a (void *) in LUA_USERSTATE.
Define LUA_USER_H to be "your.h" and define LUA_USERSTATE to be something
like:
 #define LUA_USER_H void *yourfield;
Since all lua files include lua.h, and lua.h includes LUA_USER_H, 
all lua files will notice your definition.
After that, since LUA_USERSTATE is included as the first field of
lua_State, you can cast your lua_State *pointer to a (void **) and access
yourfield.
 *((void **) L) = NULL; /* for instance */
Regards,
Diego.

AltStyle によって変換されたページ (->オリジナル) /