lua-users home
lua-l archive

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



thanks this function works good but i dont want change 0 and null string to true value, there is noway to fix it in Lua, so 0 and null string have false value by default ?

--- On Mon, 8/16/10, Peter Cawley <[email protected]> wrote:

From: Peter Cawley <[email protected]>
Subject: Re: _expression_ statements
To: "Lua list" <[email protected]>
Date: Monday, August 16, 2010, 11:14 AM

On Mon, Aug 16, 2010 at 4:36 PM, Peyman <[email protected]> wrote:
Hi All,
From Lua manual :
"in particular, the number 0 and the empty string are also true"
so my question is there anyway to create lua that 0 an empty string become true ? is there any work or patch for lua source ? in Lua 5.2 this is possible ?

thanks,
Peyman.


I don't know if it is what you're asking, but:

function toboolean(x) return not not x end
print(toboolean(0)) --> true
print(toboolean("")) --> true
print(toboolean(nil)) --> false