lua-users home
lua-l archive

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


I've been working on a Lua binding generator/C preprocessor, and one
thing I'd love to support is to be able to write a function definition
like (in C):
@function myfunc(integer n, boolean b, integer n2 = 12) { ... }
that would translate to something like:
int myfunc(lua_State *L) {
    lua_Integer n = luaL_checkinteger(L, 1);
    bool b = luaL_checkboolean(L, 2);
    lua_Integer n2 = luaL_optint(L, 3, 12);
}

Unfortunately the C API lacks some useful functions, which makes this
a bit difficult and creates some inconsistency in the API. e.g. none
of the following exist:
-lua_isinteger
-luaL_optbool (or luaL_optboolean)
-luaL_checkbool[ean]
-luaL_checkuserdata (there is luaL_checkudata, but it expects the
userdata to be created with its own mechanism)

These can be resolved by defining them myself as preprocessor macros
(#define lua_isinteger lua_isnumber), but that seems like a hack
that's likely to interfere with something (if other libraries do
similar or Lua ever adds these). Are there any plans to add these
functions to the API, so that we can be nice and comfy knowing that
for every lua_to* there exists a corresponding lua_is*, luaL_check*
and luaL_opt*?

-- 
Sent from my toaster.