From dea6b6da9422f34ad91c8f6ad9ad3ed650e95713 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Tue, 7 May 2002 14:36:56 -0300 Subject: new function `lua_vpushstr' to replace uses of `sprintf' --- lauxlib.c | 34 +++------------------------------- 1 file changed, 3 insertions(+), 31 deletions(-) (limited to 'lauxlib.c') diff --git a/lauxlib.c b/lauxlib.c index 7be33892..2537ca8c 100644 --- a/lauxlib.c +++ b/lauxlib.c @@ -1,5 +1,5 @@ /* -** $Id: lauxlib.c,v 1.67 2002/05/01 20:40:42 roberto Exp roberto $ +** $Id: lauxlib.c,v 1.68 2002/05/06 19:05:10 roberto Exp roberto $ ** Auxiliary functions for building Lua libraries ** See Copyright Notice in lua.h */ @@ -142,38 +142,10 @@ LUALIB_API void luaL_opennamedlib (lua_State *L, const char *libname, } -static void vstr (lua_State *L, const char *fmt, va_list argp) { - luaL_Buffer b; - luaL_buffinit(L, &b); - for (;;) { - const char *e = strchr(fmt, '%'); - if (e == NULL) break; - luaL_addlstring(&b, fmt, e-fmt); - switch (*(e+1)) { - case 's': - luaL_addstring(&b, va_arg(argp, char *)); - break; - case 'd': - lua_pushnumber(L, va_arg(argp, int)); - luaL_addvalue (&b); - break; - case '%': - luaL_putchar(&b, '%'); - break; - default: - lua_error(L, "invalid format option"); - } - fmt = e+2; - } - luaL_addstring(&b, fmt); - luaL_pushresult(&b); -} - - LUALIB_API void luaL_vstr (lua_State *L, const char *fmt, ...) { va_list argp; va_start(argp, fmt); - vstr(L, fmt, argp); + lua_vpushstr(L, fmt, argp); va_end(argp); } @@ -181,7 +153,7 @@ LUALIB_API void luaL_vstr (lua_State *L, const char *fmt, ...) { LUALIB_API int luaL_verror (lua_State *L, const char *fmt, ...) { va_list argp; va_start(argp, fmt); - vstr(L, fmt, argp); + lua_vpushstr(L, fmt, argp); va_end(argp); return lua_errorobj(L); } -- cgit v1.2.3-55-g6feb