[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Uploaded patch for my "Uniform Compare" mod
- From: Chris Marrin <chris@...>
- Date: Tue, 20 Sep 2005 15:23:22 -0700
I have uploaded a power patch named "Equality operators that work like
arithmetic operators". It allows the comparison of dissimilar lua types.
As long as one has a __eq, __lt or __le metamethod (depending on the
test being performed), it will call that metamethod. This is unlike
today where tests with dissimilar types throws an error.
I did this to allow the creation of userdata objects that are wrappers
around primitive types. For instance my system has an SFDouble object.
This behaves like a number, but can fire events, etc. To Lua it looks
like a userdata. This patch allows you to say:
local n = SFDouble(5.7)
if n < 3 then ...
The __lt metamethod I wrote for this will convert both sides to a
primitive number, perform the numeric comparison, and return the result.
Please see the notes I put in the power patch for caveats to this
approach and a way I believe it could be resolved to better control the
behavior of this sort of operation.
Since this is my first Lua patch, also please let me know if I have done
chris marrin ,""$,
email@example.com b` $ ,,.
mP b' , 1$'
,.` ,b` ,` :$$'
,|` mP ,` ,mm
,b" b" ,` ,mm m$$ ,m ,`P$$
m$` ,b` .` ,mm ,'|$P ,|"1$` ,b$P ,` :$1
b$` ,$: :,`` |$$ ,` $$` ,|` ,$$,,`"$$ .` :$|
b$| _m$`,:` :$1 ,` ,$Pm|` ` :$$,..;"' |$:
P$b, _;b$$b$1" |$$ ,` ,$$" ``' $$
```"```'" `"` `""` ""` ,P`
"As a general rule,don't solve puzzles that open portals to Hell"'