[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Howto return kind userdata from C to Lua?
- From: Sean Conner <sean@...>
- Date: Sun, 8 Nov 2020 18:14:26 -0500
It was thus said that the Great Ranier Vilela once stated:
> Em dom., 8 de nov. de 2020 às 01:02, Ranier Vilela <ranier.vf@gmail.com>
> escreveu:
>
> > Em sáb., 7 de nov. de 2020 às 22:07, Sean Conner <sean@conman.org>
> > escreveu:
> > // You can solve this several ways---one is to call lua_pop(L,1) to pop
> >
> >> // MyItem off the stack, or to use lua_pushvalue(L,-2) to copy MyValue
> >> to
> >> // the top of the stack. Another way is to generate the uservalues in
> >> // reverse order, thus avoiding the lua_pop() or lua_pushvalue() calls.
> >>
> > Many thanks, I will try.
> > In reverse order, I think it is not possible, MyItem is part of MyValue.
> > But I think of using it (MyItem) independently of MyValue, when this is
> > possible.
> >
>
> lua_pushvalue, works, but only if disable that:
> //luaL_getmetatable(L, MYITEM_REGISTRY);
> //lua_setmetatable(L, -2);
> lua_pushvalue(L, -2);
>
> How to discover what MyValue position is?
> Why does the register metatable MYITEM_REGISTRY confuse MYVALUE_REGISTRY?
When I need to figure out the Lua stack in C, I use this function:
static int cstack(lua_State *L)
{
int max = lua_gettop(L);
fprintf(stderr,"Stack dump\n");
for (int i = 1 ; i <= max ; i++)
{
fprintf(
stderr,
"%d %d - %s %s\n",
i,
i - max - 1,
luaL_typename(L,i),
luaL_tolstring(L,i,NULL)
);
lua_pop(L,1);
}
fprintf(stderr,"Stack done\n");
return max;
}
Call it where ever you feel the need to see the contents of the Lua stack.
As for your second question, I don't have any ideas for that.
-spc