lua-users home
lua-l archive

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


Sorry, just to clarify, when you guys mentioned the registry, my brain
immediately misinterpreted that you were referring to the Windows
registry. I wasn't familiar with the Lua registry, which I just
discovered. I'll check that out.

-----Original Message-----
From: Curt Carpenter [mailto:curtc@microsoft.com] 
Sent: Wednesday, October 03, 2001 2:59 PM
To: Multiple recipients of list
Subject: RE: Private data


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

>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.