My metamethods only have a special behavior if the number is a very
specific NAN value. There are billions of NANs, so the chance of this
value occurring normally is negligible. And the special behavior is
limited to __index, __newindex and __len, which should not be used in
normal numeric operations anyway (aside from __eq, if I get it to work
somehow).
Hi I am embedding Lua in my application and I want to expose some objects to the Lua scripts. Different objects have different sets of properties. For example object1 can have speed and length and object2 can have mass and friction. Currently if the script wants to check if an object has mass>20 it has to do: if (obj.mass and obj.mass>20)... because obj.mass may be nil and then comparing it to 20 fails. So for properties that don't exist I want to create a special object (NIL) that can be safely used in expressions: NIL+x -> NIL NIL..x -> NIL NIL[x] -> NIL #NIL -> 0 NIL==NIL -> true NIL==nil -> true (not so sure about this) NIL>20 -> false ... You get the idea. Then I can simply write: if (obj.mass>20) ... However the __lt metamethod is not being called when I compare NIL to a number. It is used only if the two values are of the same type. Otherwise Lua throws an error. Any ideas how to do this? A NAN value almost d
oes what I want but it can't be indexed, and also NAN~=NAN. Thanks Ivo