lua-users home
lua-l archive

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


Ah, it seems I have to use Core.HB_FALSE and Core.HB_TRUE. ToLua generated this
code:

int tolua_hbCoreTypes_open (lua_State* tolua_S)
{
 tolua_open(tolua_S);
 toluaI_reg_types(tolua_S);
 tolua_module(tolua_S,"Habitat");
 tolua_module(tolua_S,"Core");
 tolua_constant(tolua_S,"Core","HB_FALSE",HB_FALSE);
 tolua_constant(tolua_S,"Core","HB_TRUE",HB_TRUE);
}

Thanks again
Mike

Quoting Ariel Manzur <listas@anime.com.ar>:

> 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
> 
>