lua-users home
lua-l archive

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


On Sun, Apr 7, 2019 at 1:05 PM Marc Balmer <marc@msys.ch> wrote:

> Are both variants valid?

Userdata is the only option here, because Lua strings are immutable, and this should not be violated by clever C code.

Frankly, the whole approach, which would then involve creating more Lua strings and calling luaL_checkoption on them, seems heavy-footed to me.

If you need this to pass optional flags, I would instead consider passing them as multiple arguments, so that the Lua code could do this:

dlopen('whatever') -- no flags
dlopen('whatever ', 'lazy')
dlopen('whatever ', 'lazy', 'global')  

This leaves the entire question of parsing to Lua's parser, the user does not have to learn your syntax, and all you need to do is something like this:

int flags = 0, top = lua_gettop(L);
for (int i = 2; i <= top; ++i)
    flags |= (1 << luaL_checkoption(L, i, 0, list));

Cheers,
V.