lua-users home
lua-l archive

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


Many C++ binding frameworks do not store the object itself in a
userdata, but instead a pointer to the object. As lua_touserdata gives
a pointer to the userdata, you'll likely need to do something along
the lines of:

FComponent* value = *(FComponent**)lua_touserdata(L, 1);

2008/11/5 Michael Bauroth <Michael.Bauroth@falcom.de>:
> Hi,
>
> I'm using an ARM port of Lua (Lua5.1-CE). Don't know if this matters.
> Additionally I'm using Lunar / Luna to register a class and some functions
> to Lua, e.g.
>
> const char FComponent::className[] = "Component";
> FLuna< FComponent >::RegType FComponent::methods[] = {
>    method( FComponent, SetPosition ),
>    method( FComponent, SetDimensions ),
>    method( FComponent, SetBackground ),
>    method( FComponent, SetParent ),
>    { 0, 0 }
> };
>
> Creating the object from Lua works well, e.g.
>
> comp = Component:new()
> print( comp )
>
> result in Lua is: Button (000ADE70)
> pointer in C++: 0x000ade70
>
> Both sides (C++ and Lua) show the same pointer value.
> When I use this value in the next step to send it back from Lua to C++, the
> value differs in C++ !?
>
> comp = Component:new()
> print( comp )
> comp:SetParent( comp )
>
> --> comp is 000ADE70
>
> int FComponent::SetParent( lua_State *L )
> {
>    void* value = ( void*)lua_touserdata( L, 1 );
>    return 0;
> }
>
> --> value is 0x000adf28
>
>
> What happens here? Am I missing something?
> Help / hints would be very appreciated.
>
> Thanks in advance.
> Micha
>
>