lua-users home
lua-l archive

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


Hi,

Given this Lua function:

function write_log(level, ...)
local str = string.format(...)
logger:log(logging.level[level], str)
end


Is it possible to pass varargs  from C to Lua like so:

int wrlog(int level, ...)
{
lua_getglobal(L, "write_log");
<slick code that passes varags goes here>
lua_call(L, lua_gettop(L)-1, 0);
}


I've found this on stack overflow:
///Rh - Replaced old call for 5.3 syntax
//lua_getfield
(L, LUA_GLOBALSINDEX, "print");
lua_getglobal(L, "write_log");
lua_insert
(L, 1); lua_call(L, lua_gettop(L)-1, 0);

But I'm still not getting what I want. I also found call_va from in the online 5.2 PIL, but it requires I know how many parameters I am passing in and what type they are.  I was also trying to avoid sprintf because I'm lazy and want Lua to do all the heavy lifting.

Thoughts (other than 'don't be so lazy')?
Russ