lua-users home
lua-l archive

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


Ok, this is good! Please correct me if I am wrong with the following. The LUA_USERSTATE would have to be added somewhere very low level - lua.h perhaps? The only example of use is in luser_tests.h, which, although being sufficient, is not used anywhere. Supposing I did the same thing, mylua.h, would you recommend including this file into lua.h or had it better be some other file? All I need is a void* in there. I have also noticed that there a thing called LUSER_ALLIGNMENT_T, already having void* in the union. Would this thing be safe to use? In this case I could just add LUA_USERSTATE define at compiler level and have my void* with no code changes to original Lua sources. Does this make sense?

I thought I had missed these facilities in Lua 4 but apparently it was not there.

Thanks,
AB  

-----Original Message-----
From: Roberto Ierusalimschy [mailto:roberto@inf.puc-rio.br]
Sent: Thursday, January 30, 2003 8:14 AM
To: Multiple recipients of list
Subject: Re: is this a bug in lua core 5.0b ? 

> I did add one more member variable (void* mpMy Data) to lua_State
> structure that I placed before CommonHeader.

You should not do that. Lua assumes that "CommonHeader" is the first
thing in a lua_State, because it can point to a lua_State through a
generic pointer of type GCObject*. If you want to add data to lua_State,
use the LUA_USERSTATE facility. It puts your data before CommonHeader,
but makes the pointer lua_State point to CommonHeader; that is,
you must access your data with something like this:

  ... (lua_State *L) {
    MyData *d = ((MyData *)L - 1);
    ...

-- Roberto