lua-users home
lua-l archive

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


On Thu, Jul 10, 2014 at 11:58 AM, Austin Einter <austin.einter@gmail.com> wrote:
> Hi All
> Lets say I called lua function from C code.
>
> Say Lua function returned 1 integer, 1 double and 1 string.
>
> To check the type I am using below code. Looks for integer and double the
> type is LUA_TNUMBER. How to distinguish if the return value is integer or
> double.
>
>
>
>
>       int i;
>       int top = lua_gettop(L);
>       for (i = 1; i <= top; i++) {  /* repeat for each level */
>         int t = lua_type(L, i);
>         switch (t) {
>
>           case LUA_TSTRING:  /* strings */
>             printf("`%s'", lua_tostring(L, i));
>             break;
>
>           case LUA_TBOOLEAN:  /* booleans */
>             printf(lua_toboolean(L, i) ? "true" : "false");
>             break;
>
>           case LUA_TNUMBER:  /* numbers */
>             printf("%g", lua_tonumber(L, i));
>             break;
>
>           default:  /* other values */
>             printf("%s", lua_typename(L, t));
>             break;
>
>         }
>         printf("  ");  /* put a separator */
>       }
>
>
> Thanks
> Austin

Unless you're using Lua 5.3work, there are no integers, there are only
numbers (which are doubles).

/s/ Adam