[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Lua 4, ToLua, False, True and booleans
- From: Ariel Manzur <listas@...>
- Date: Sun, 27 Apr 2003 00:46:56 -0300
Hi..
I'm not sure but tolua might be including the #defined stuff inside the
modules, so you might have to use Habitat.Core.HB_TRUE
Anyway, tolua has it's own boolean implementation (I think I saw a
tolua_pushbool() function on the library, they just push a number or nil),
so you can safely use functions and variables of type 'bool'. You should
also know that (as far as I know, someone please correct me) 0 is _true_ on
lua:
$ lua
Lua 4.0.1 Copyright (C) 1994-2000 TeCGraf, PUC-Rio
> a = 0
> if a then print "a is true" end
a is true
> a = nil
> if a then print "a is true" end
> ^Z
it took me a while to figure that out.. I guess '0' is a value of type
number, and that's better that just 'nil' ;) we usually have the lines
'true = 1' and 'false = nil' at the begining of our scripts to avoid
confusion..
Hope that helps.. bye.
Ariel.
At 22:39 26/04/2003 -0400, you wrote:
>From my reading Lua doesn't support booleans. No problem I thought; I'll
just
define TRUE and FALSE and typedef unsigned char to be my own boolean type, and
then expose them using ToLua.
So this is my C++ code:
namespace Habitat
{
namespace Core
{
typedef unsigned char HBboolean;
#define HB_TRUE 1
#define HB_FALSE 0
}
}
And this is my package file:
module Habitat
{
module Core
{
typedef unsigned char HBboolean;
#define HB_TRUE 1
#define HB_FALSE 0
}
}
Now when I try to use these in my Lua scripts, nothing works:
flag = HB_FALSE
flag2 = HB_TRUE
Log:Print(type(HB_FALSE))
Log:Print(type(HB_TRUE))
Log:Print(type(flag))
Log:Print(type(flag2))
These all display:
nil
Am I missing something really obvious? Any help greatly appreciated.
Thanks
Mike
Ariel.
http://Anime.com.ar
snm