[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: lua_type in 4.0b
- From: Luiz Henrique de Figueiredo <lhf@...>
- Date: Sat, 23 Sep 2000 09:46:03 -0300 (EST)
>Another "dirty trick" for checking the type of a value is to check its tag
In C, this is quite all right.
The only thing is that you don't know the predefined tags, although you
can get them by pushing a value of each basic type and then getting its tag
with lua_tag. However, this is not useful for switch statements.
> for i, v in numberlist
> --if type(v) == "number" then end
> if tag(v) == 1 then end
This would make your Lua code non portable because we might change the order
of the TAG_* enum in a later version.
In Lua, string comparisons should be just as cheap as number comparisons,
because it's merely a pointer comparison, specially if you write the code as
if t=="number" then ...
elseif t=="string" then ...
elseif t=="function" then ...
I think the version with type is much more readable.