lua-users home
lua-l archive

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


>Another "dirty trick" for checking the type of a value is to check its tag 
>value.

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

	local t=type(v)
	if t=="number" then ...
	elseif t=="string" then ...
	elseif t=="function" then ...

I think the version with type is much more readable.
--lhf