|
|
||
|
|
I had some luck with using a NAN value with a metatable for numbers. So
now I have: NIL+x -> NIL NIL[x] -> NIL NIL[x]=5 -> no error #NIL -> 0 NIL>20 -> false But I'm still having 2 problems: 1) NIL==NIL gives false. That's because the __eq metamethod is not being called for numbers at all, and normally NAN!=NAN. Is there a trick to get this to work? It is important because otherwise there is no convenient way to detect when the value is really NIL. Basically I want to do: if (obj.mass==NIL) ... 2) Since I'm replacing the __index and __newindex for numbers, when I try to index a regular number I'm getting: bad argument #1 to '?' (can't index a number value) instead of the nicer standard message produced by the luaG_typeerror function: attempt to index global 'a' (a number value) Is there a way to use the luaG_typeerror myself? It requires a const TValue * argument and I don't know how to get it in my function. Ivo Duncan Cross wrote: Unfortunately I don't think there is a way to get what you want without a custom modification of Lua, in a way that could potentially make comparisons slightly slower. The only thing I'd mention is that you could use "or" to specify a default - instead of the cumbersome 'if obj.mass and obj.mass > 20' you could do 'if (obj.mass or 0) > 20'. -Duncan On Sun, May 31, 2009 at 7:41 PM, Ivo Beltchev <ivo@roadrunner.com> wrote: |