lua-users home
lua-l archive

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

 > I'm glad to say that this is available in 3.1. It's called luaL_verror.
 > It's not part of the official API because it's a convenience function,
 > written enirely with the API, with no inside information. See lauxlib.c.
 > Just for reference -- or if you're using a previous version, here it is:
 > void luaL_verror (char *fmt, ...)
 > {
 >   char buff[500];
 >   va_list argp;
 >   va_start(argp, fmt);
 >   vsprintf(buff, fmt, argp);
 >   va_end(argp);
 >   lua_error(buff);
 > }
 > Unfortunately, until the new ANSI C is out, there is no way to avoid the
 > fixed size buffer and the danger for overflow in vsprintf.

This I have written myself.  It would be more useful to walk the
printf string, find the maximum size of the output, and allocate the
buffer dynamically.  It's not clear to me, however, how to ask Lua for
a dynamic buffer that I intend to write with a string.  Another
alternative would be to use Dave Hanson's Fmt code from; this is not quite as
powerful as printf but is extensible.