lua-users home
lua-l archive

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


Kurt Jung schrieb:

 >What I need to do is to be able to pass these popped lua values to a
 >variadic C function.

 >Note that I can't put the lua interface inside the variadic function
 >directly as I'm using an API for which I only have the library,
 >instead I have to create a C binding that turns around and calls the
 >variadic function.

Most APIs in C have an alternate entry point for each variadic function
which accepts a pointer to a list of arguments instead of an argument
list. In fact, most variadic functions are just wrappers which call
these "worker" functions. For examples in the C standard library, see
the documentation for vsprintf and vscanf.

If the API with which you are working provides this option, it would be
a relatively simple task to bundle your Lua arguments into an array and
call the "v" flavor function.

I'm not sure whether the va_list type and an array type are compatible (a va_list can contain mixed types as members), and there are no va_list constructor functions in ISO C.

AFAIK there is no portable way to do this in general, but you could provide a binding function for the most common cases (say from one argument to 9 arguments).


Kurt Jung


Philipp