lua-users home
lua-l archive

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


In my C++ code, I have successfully

1)created a lua thread,

2)set a key-value pair (
pushlightuserdata(newThread),pushlightuserdata(this) ) into GLOBAL space

3)resumed the thread/coroutine

4)fielded a callback from the lua coroutine to C++ that retrieves the
key-value pair from GLOBAL space

It worked.

But then I decided to change the above so that the key-value pair is kept in
the registry rather than in global space.  When I do that, step 4 above does
not successfully retrieve the key-value pair.  Instead the value it
retrieves is 0, rather than the C++ "this" pointer I had expected.

Why is this?

The retrieval function used in step #4 above looks like this:

static ILuaScript* GetScriptObject(lua_State *l)
{
	ILuaScript *s;
	lua_pushlightuserdata(l, l);
    lua_gettable(l, LUA_GLOBALSINDEX );
    s = (ILuaScript *)lua_touserdata(l, -1);
	lua_pop(l, 1);
	return s;
}

The sample above is the working version, where the GLOBAL space is assumed.
The non-working version simply replaces the GLOBAL with the REGISTRY both
here, and symmetrically in the code related to step #2 above.

Thanks,

-Brent