lua-users home
lua-l archive

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


>You will note that argument 2 is pulled from the
>Lua stack, immediately coerced to a time_t, then
>compared with a (time_t) -1. This seems to me a bit
>like travelling from Manhattan to Newark via
>Montreal.

And what more pleasant way is there to travel? :)

Unlike North American geography, which appears to be immutable, one could
decide to compile Lua as integer-only, which would effectively translate
Manhattan to the outskirts of NDG, where it might feel a bit foreign. But
in any case,

There is actually nothing wrong with:

if (lua_isnoneornil(L, 2)
  t = time(NULL);
else if (lua_isnumber(L, 2)
  t = (time_t)lua_tonumber(L, 2);
else
  luaL_typerror(L, 2, "number");

except for the fact that if the argument is coerced, the coercion will
happen twice. One could say that people who coerce strings deserve their
fate. I think I would say that, so I won't go on with the other suggestion
which was going to be something about an API which replaced a stack element
with a numeric version of a coercable number (in analogy with lua_tostring
()), but which would really do nothing other than complicate the API.