lua-users home
lua-l archive

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


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.