lua-users home
lua-l archive

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


This worked just fine, and lets me swap the values.
I do have a meta table(luabind creates it), but i fail to understand
why it is needed here? Was it just for registering the function as a
memberish one( ":"-syntax )?




On Thu, 28 Oct 2004 16:30:08 +0200, Benoit Germain <bgermain@ubisoft.fr> wrote:
> If you have a metatable, I'd do this by registering a C function there that
> does the swapping:
> 
> C:
> // untested!!!
> int do_swap ( lua_State * L )
> {
>         //TODO: make sure that both arguments are indeed full userdata of
> the correct type, etc, etc.
> 
>         // get pointers to the area where the pointers are stored
>         void * * p1 = lua_touserdata ( L , 1 ) ;
>         void * * p2 = lua_touserdata ( L , 2 ) ;
>         // move things around
>         void * p = * p1 ;
>         * p1 = * p2 ;
>         * p2 = p ;
>         // done
>         return 0 ;
> }
> 
> LUA:
> 
> o1 = getMyUserdata()
> o2 = getMyUserdata()
> o3 = getMyUserdata()
> 
> -- swap things around:
> 
> -- direct with ':' operator o1 and o2
> o1:swap(o2)
> 
> -- indirect with '.' operator
> o3.swap(o1,o2)
> 
> Now, I've not used luabind so I don't know how you'd do this wrt the rest of
> the binding system, but you get the idea.
> 
> Regards,
> 
> Benoit.
> 


-- 
Jonas Meyer
meyer@diku.dk