lua-users home
lua-l archive

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


Rob Hoelz <rob@hoelz.ro> wrote:

>> I'm writing a binding to libedit, and there's a function el_set with
>> the following signature:
>> 
>> int el_set(EditLine *el, int op, ...)
>> 
>> When op is EL_BIND, the varargs accepted are:
>> 
>> const char *, ..., NULL

In this particular case just use el_parse() that takes argc/argv.


Roberto Ierusalimschy <roberto@inf.puc-rio.br> wrote:

> Probably EL_BIND stops at the first NULL argument, no matter
> how many actual arguments it has. (That is the only possibility
> using vararg.h.) So, you may write simply this:
> 
>  el_set(el, EL_BIND, something,
>    lua_tostring(L, 1),
>    lua_tostring(L, 2),
>    lua_tostring(L, 3),
>    ...
>    lua_tostring(L, 20),  /* accept up to 20 strings */
>    NULL);
> 
> lua_tostring will return NULL at the first absent parameter and
> stop the list for el_set.

Funny thing is that el_set() needs to solve exactly the same problem
to call internal map_bind() with argc/argv, and it also accepts up to
20 strings :)

-uwe