lua-users home
lua-l archive

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


On Fri, Aug 1, 2014 at 12:57 PM, Sean Conner <sean@conman.org> wrote:

>   One situation I hit in C was the following:
>
>         static int foobar___index(lua_State *L)
>         {
>           foobar__s *foo = luaL_checkudata(L,1,TYPE_FOO);
>
>           if (lua_isstring(L,2))
>             ...
>           else if (lua_isnumber(L,2))
>             ...
>         }
>
> Odd bugs until I actually read the description for lua_isstring():
>
>         Returns 1 if the value at the given index is a string or a number
>         (which is always convertible to a string), and 0 otherwise.
>
> lua_to[l]string() will do a convertion if the target is a number.  I'm sure
> it's convenient in some cases, but not in others.
>
>   Oddly enough, I dont' have an issue with lua_isboolean() or
> lua_toboolean() even though they do a conversion as well (nil or false as
> false, anything else is true).

I think I've just made it a habit to use luaL_checktype(), I can see
how that might be confusing to use the is<type>() functions, though