lua-users home
lua-l archive

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


Oops, the "TP:" should read "TO:"

Offlist someone asked if this would have an effect on the parser, however, from what I can tell it will not. It seems the two functions are only used when encoding if/else statements, which is exactly where you'd want numeric 0 to be false. ;)

I know that this patch probably won't be used by anyone else, however, I do think it is interesting how easy a patch it is to make zero's be false, albeit at the cost of additional checks for constants and numbers instead of defaulting them all to true.

~pmd~



On Nov 19, 2013, at 4:07 PM, Paige DePol <lual@serfnet.org> wrote:

> Replying to myself just to add one change also required for making Zero as False work.
> 
> In the luaK_goiftrue function in lparser.c one line needs to be changed:
> 
> FROM: case VK: case VKNUM: case VTRUE: {
>  TP: case VTRUE: {
> 
> This way constants and numbers will be checked if they are numeric 0 or not.
> 
> Again, if anyone knows why this is a bad idea (other than because it changes the semantics of the language, but remember I am creating a new variant of Lua so that is not a problem) please let me know.
> 
> So far, however, it does seem to work quite well, and since 0 has been false for as long as I have been coding it just makes me happy to have it work that way in my scripting language as well! ;)
> 
> ~pmd~