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:

>           case LUA_TNUMBER:  /* numbers */
>             printf("%g", lua_tonumber(L, i));
>             break;

I think you could cast to lua_Integer and compare -- if they're not
equal you've got a double?  something like: lua_Number n =
lua_tonumber(L, i); if ( ((lua_Integer) n) == n ) { puts("I'm an
integer!"); }

When you cast to lua_Integer it will then promote the type back to
lua_Number since I imagine it would be ~wider~, so it's like you're
truncating to the integral portion, and then converting it back to the
double it normally is -- and then checking equality.

Others can correct me if I'm wrong ~