lua-users home
lua-l archive

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


On Mon, Feb 26, 2007 at 05:13:28PM -0800, Graham Wakefield wrote:
> Hi, Sorry for not being clearer.  Hope this helps:
> 
> On Feb 26, 2007, at 4:38 PM, Sam Roberts wrote:
> 
> >On Mon, Feb 26, 2007 at 02:59:39PM -0800, Graham Wakefield wrote:
> >>Thanks, but I think perhaps I wasn't clear enough about my needs; see
> >>below:
> >
> >I'm certainly not understanding :-)
> 
> OK.  I run a chunk of lua code in a lua_State.  Some calls in this  
> lua code call lua_CFunctions that will create my table/c++ instance  
> pairs.

...and then store the udata somewhere? If you don't somehow arrange for
the lua_State to have a reference to the udata objects you create, they
will be garbage collected after the chunk is run, and will no longer
exist, won't it?

> Somehow I need to get the userdata back onto the lua stack, based  
> upon the identity of the C++ instance pointer.  getfenv() will not  
> help, since it requires that the call was made as the result of a  
> lua_CFunction call from Lua, not a lua_pcall from C.

I really don't know what you mean here.

> This will not work because it is only valid in the context of a  
> lua_CFunction call, and my call comes from a later C++ triggered  
> lua_pcall().

I don't know what you mean by that, either, sorry, it sounds like you
are doing pretty much exactly what I am doing with swirl inside
callbacks from vortex, a C BEEP implementation. The Vortex kernel calls
a C function, and I use a lua_State to map addresses back to their udata
objects.

See v_obj_get():

http://luaforge.net/plugins/scmcvs/cvsweb.php/swirl/vmain.c?rev=1.3;cvsroot=swirl

After doing v_obj_get() I could call lua_getfenv() to get the table from
the udata object.

Sam