lua-users home
lua-l archive

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

> Anyway, I think it is a problem with the luaL_* API,
> and possibly the lua_tonumber API as well. Although
> "bulkier", the following is more useful:
> [...]

A simpler solution for that particular kind of problem would be to
define luaL_opt* as macros:

  #define luaL_optinteger(L,n,d)  \
       (lua_isnoneornil(L, (n)) ? (d) : luaL_checkinteger(L, (n)))

With them, we could simply change unpack to this:

      e = luaL_optint(L, 3, luaL_getn(L, 1));

The only drawback is that the macro evaluates n twice...

-- Roberto