[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: luaL_verror
- From: Dirk Zoller <Dirk.Zoller@...>
- Date: Sat, 07 Aug 1999 13:20:33 +0200
Hello,
I noticed a misunderstanding in the definition of the luaL_verror
function.
In ANSI-C there are two kinds of printf like functions: those for
immediate use accept a variable number of parameters via ellipses "...",
while those for building other printf-like functions accept a va_list
type which is a disguised pointer to the args passed as ... to a calling
function. The second kind taking va_list instead of ... is customarily
named vsometingf.
At least lua_verror is misnamed as it takes ... and not va_list it
should be named lua_errorf.
That aside, it is not possible to build other printf-like functions on
top of lua_verror. You cannot pass the ellipes on to a called function
as ellipses but only as va_list.
I'd suggest a change as follows:
void luaL_verrorf (lua_State *lua_state, char const *fmt, va_list argp)
{
char buff[500];
vsprintf(buff, fmt, argp);
lua_error(L,buff);
}
void luaL_errorf (lua_State *lua_state,char const *fmt, ...)
{
va_list argp;
va_start(argp, fmt);
luaL_verror (buff, fmt, argp);
va_end(argp);
}
(I'm using the "multistate" variant of Lua which replaces the global
variable lua_state by a parameter to each function.)
With only a few more lines we'd have both flavours and could use
luaL_verrorf() to build more fancy error handlers. One might want to
avoid
breaking old code by
#define luaL_verror luaL_errorf
Regards
--
Dirk Zoller <Dirk.Zoller@rhein-main.netsurf.de>