[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Zero as False
- From: Paige DePol <lual@...>
- Date: Mon, 18 Nov 2013 12:30:08 -0600
So, I was poking around in the Lua 5.2 code and I found this in lobject.h:
#define l_isfalse(o) (ttisnil(o) || (ttisboolean(o) && bvalue(o) == 0))
Since I am in the process of heavily hacking Lua (and in the process creating a scripting language for my game engine) I decided I really wanted numeric '0' to also be false.
To that end I changed the above macro as follows:
#define l_isfalse(o) (ttisnil(o) || (ttisnumber(o) && nvalue(o) == 0) || \
(ttisboolean(o) && bvalue(o) == 0) )
Not surprisingly this works very well, numeric zero is now a false value and logic statements now work as expected when the result of an expression is zero.
I grep'd 'l_isfalse' and can not see anywhere that this change would adversely affect anything in the Lua core itself. So, if anyone else is working on a Lua variant and would like zero to be false, this seems to be the ticket!
This, of course, breaks with the official Lua rules, however, I am not too concerned about that. I am using Lua as the base for a scripting language I am calling LUNiA (my game engine is called ONiA).
Just thought I would share the discovery and see if anyone knows anything I missed that makes this change a bad idea.
~pmd~