aboutsummaryrefslogtreecommitdiff
path: root/lauxlib.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2002-05-16 15:39:46 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2002-05-16 15:39:46 -0300
commit955def034814e96f5f8e42def2e47ca6817ef103 (patch)
treed8eea96980860d1d1e5005ee6ecedb47fa64d594 /lauxlib.c
parent9c3b3f82fe1b0942183ddeef2e16d60bab4f4c06 (diff)
downloadlua-955def034814e96f5f8e42def2e47ca6817ef103.tar.gz
lua-955def034814e96f5f8e42def2e47ca6817ef103.tar.bz2
lua-955def034814e96f5f8e42def2e47ca6817ef103.zip
new names for string formating functions
Diffstat (limited to 'lauxlib.c')
-rw-r--r--lauxlib.c21
1 files changed, 7 insertions, 14 deletions
diff --git a/lauxlib.c b/lauxlib.c
index ecaa6c8f..b7b82661 100644
--- a/lauxlib.c
+++ b/lauxlib.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lauxlib.c,v 1.69 2002/05/07 17:36:56 roberto Exp roberto $ 2** $Id: lauxlib.c,v 1.70 2002/05/15 18:57:44 roberto Exp roberto $
3** Auxiliary functions for building Lua libraries 3** Auxiliary functions for building Lua libraries
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -43,8 +43,9 @@ LUALIB_API int luaL_argerror (lua_State *L, int narg, const char *extramsg) {
43 43
44 44
45LUALIB_API int luaL_typerror (lua_State *L, int narg, const char *tname) { 45LUALIB_API int luaL_typerror (lua_State *L, int narg, const char *tname) {
46 luaL_vstr(L, "%s expected, got %s", tname, lua_typename(L, lua_type(L,narg))); 46 const char *msg = lua_pushfstring(L, "%s expected, got %s",
47 return luaL_argerror(L, narg, lua_tostring(L, -1)); 47 tname, lua_typename(L, lua_type(L,narg)));
48 return luaL_argerror(L, narg, msg);
48} 49}
49 50
50 51
@@ -142,25 +143,17 @@ LUALIB_API void luaL_opennamedlib (lua_State *L, const char *libname,
142} 143}
143 144
144 145
145LUALIB_API void luaL_vstr (lua_State *L, const char *fmt, ...) {
146 va_list argp;
147 va_start(argp, fmt);
148 lua_vpushstr(L, fmt, argp);
149 va_end(argp);
150}
151
152
153LUALIB_API int luaL_verror (lua_State *L, const char *fmt, ...) { 146LUALIB_API int luaL_verror (lua_State *L, const char *fmt, ...) {
154 lua_Debug ar; 147 lua_Debug ar;
148 const char *msg;
155 va_list argp; 149 va_list argp;
156 va_start(argp, fmt); 150 va_start(argp, fmt);
157 lua_vpushstr(L, fmt, argp); 151 msg = lua_pushvfstring(L, fmt, argp);
158 va_end(argp); 152 va_end(argp);
159 if (lua_getstack(L, 1, &ar)) { /* check calling function */ 153 if (lua_getstack(L, 1, &ar)) { /* check calling function */
160 lua_getinfo(L, "Snl", &ar); 154 lua_getinfo(L, "Snl", &ar);
161 if (ar.currentline > 0) 155 if (ar.currentline > 0)
162 luaL_vstr(L, "%s:%d: %s", 156 lua_pushfstring(L, "%s:%d: %s", ar.short_src, ar.currentline, msg);
163 ar.short_src, ar.currentline, lua_tostring(L, -1));
164 } 157 }
165 return lua_errorobj(L); 158 return lua_errorobj(L);
166} 159}