lua-users home
lua-l archive

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

Whilst integrating C++ with Lua which enables the passing of C++ objects to Lua, calling methods, operators and vice versa I have encountered a problem with my current implementation. I use the method with is described on the wiki entitled Luna and which is also described in many other publications such as Game Programming Gems.
The crux of my problem is that a new user data is only created when an object is currently not alive in Lua, when it is the pointer which was returned when the lua_newuserdata was created is pushed onto the stack using lua_pushlightuserdata and has it's metatable attached. This metatable defines the functions to be called for the operators such as __eq and __le; yet a lightuserdata is only equal to itself and does not look at the metatable to see if the operator is defined for the type, whilst it does look at the metatable for methods.

Is there a way whilst still using the operators instead of say a le function (obj:le(rhs)) to accomplish this, or is using this type of function for the operator or using a table to represent the data the only method. Ie. is there a way to trick Lua into looking at the metatable of the lightuserdata for the operators without modifying the source of Lua itself?