Browse Source

new names for string formating functions

v5-2
Roberto Ierusalimschy 23 years ago
parent
commit
955def0348
  1. 48
      lapi.c
  2. 21
      lauxlib.c
  3. 3
      lauxlib.h
  4. 25
      lbaselib.c
  5. 17
      ldblib.c
  6. 6
      ldebug.c
  7. 4
      ldo.c
  8. 16
      llex.c
  9. 8
      lobject.c
  10. 6
      lobject.h
  11. 6
      lparser.c
  12. 18
      lua.h

48
lapi.c

@ -1,5 +1,5 @@
/*
** $Id: lapi.c,v 1.190 2002/05/07 17:36:56 roberto Exp roberto $
** $Id: lapi.c,v 1.191 2002/05/15 18:57:44 roberto Exp roberto $
** Lua API
** See Copyright Notice in lua.h
*/
@ -355,10 +355,23 @@ LUA_API void lua_pushstring (lua_State *L, const char *s) {
}
LUA_API void lua_vpushstr (lua_State *L, const char *fmt, va_list argp) {
LUA_API const char *lua_pushvfstring (lua_State *L, const char *fmt,
va_list argp) {
const char *ret;
lua_lock(L);
luaO_vpushstr(L, fmt, argp);
ret = luaO_pushvfstring(L, fmt, argp);
lua_unlock(L);
return ret;
}
LUA_API const char *lua_pushfstring (lua_State *L, const char *fmt, ...) {
const char *ret;
va_list argp;
va_start(argp, fmt);
ret = lua_pushvfstring(L, fmt, argp);
va_end(argp);
return ret;
}
@ -556,21 +569,16 @@ LUA_API int lua_pcall (lua_State *L, int nargs, int nresults, int errf) {
static int errfile (lua_State *L, const char *filename) {
if (filename == NULL) filename = "stdin";
lua_pushliteral(L, "cannot read ");
lua_pushstring(L, filename);
lua_pushliteral(L, ": ");
lua_pushstring(L, lua_fileerror);
lua_concat(L, 4);
lua_pushfstring(L, "cannot read %s: %s", filename, lua_fileerror);
return LUA_ERRFILE;
}
LUA_API int lua_loadfile (lua_State *L, const char *filename) {
ZIO z;
const char *luafname; /* name used by lua */
int fnindex;
int status;
int bin; /* flag for file mode */
int nlevel; /* level on the stack of filename */
FILE *f = (filename == NULL) ? stdin : fopen(filename, "r");
if (f == NULL) return errfile(L, filename); /* unable to open file */
bin = (ungetc(getc(f), f) == LUA_SIGNATURE[0]);
@ -580,19 +588,17 @@ LUA_API int lua_loadfile (lua_State *L, const char *filename) {
if (f == NULL) return errfile(L, filename); /* unable to reopen file */
}
if (filename == NULL)
lua_pushstring(L, "=stdin");
else {
lua_pushliteral(L, "@");
lua_pushstring(L, filename);
lua_concat(L, 2);
}
nlevel = lua_gettop(L);
luafname = lua_tostring(L, -1); /* luafname = `@'..filename */
luaZ_Fopen(&z, f, luafname);
lua_pushliteral(L, "=stdin");
else
lua_pushfstring(L, "@%s", filename);
fnindex = lua_gettop(L); /* stack index of file name */
luaZ_Fopen(&z, f, lua_tostring(L, fnindex));
status = luaD_protectedparser(L, &z, bin);
if (ferror(f))
lua_remove(L, fnindex);
if (ferror(f)) {
if (status == 0) lua_pop(L, 1); /* remove chunk */
return errfile(L, filename);
lua_remove(L, nlevel); /* remove filename */
}
if (f != stdin)
fclose(f);
return status;

21
lauxlib.c

@ -1,5 +1,5 @@
/*
** $Id: lauxlib.c,v 1.69 2002/05/07 17:36:56 roberto Exp roberto $
** $Id: lauxlib.c,v 1.70 2002/05/15 18:57:44 roberto Exp roberto $
** Auxiliary functions for building Lua libraries
** See Copyright Notice in lua.h
*/
@ -43,8 +43,9 @@ LUALIB_API int luaL_argerror (lua_State *L, int narg, const char *extramsg) {
LUALIB_API int luaL_typerror (lua_State *L, int narg, const char *tname) {
luaL_vstr(L, "%s expected, got %s", tname, lua_typename(L, lua_type(L,narg)));
return luaL_argerror(L, narg, lua_tostring(L, -1));
const char *msg = lua_pushfstring(L, "%s expected, got %s",
tname, lua_typename(L, lua_type(L,narg)));
return luaL_argerror(L, narg, msg);
}
@ -142,25 +143,17 @@ LUALIB_API void luaL_opennamedlib (lua_State *L, const char *libname,
}
LUALIB_API void luaL_vstr (lua_State *L, const char *fmt, ...) {
va_list argp;
va_start(argp, fmt);
lua_vpushstr(L, fmt, argp);
va_end(argp);
}
LUALIB_API int luaL_verror (lua_State *L, const char *fmt, ...) {
lua_Debug ar;
const char *msg;
va_list argp;
va_start(argp, fmt);
lua_vpushstr(L, fmt, argp);
msg = lua_pushvfstring(L, fmt, argp);
va_end(argp);
if (lua_getstack(L, 1, &ar)) { /* check calling function */
lua_getinfo(L, "Snl", &ar);
if (ar.currentline > 0)
luaL_vstr(L, "%s:%d: %s",
ar.short_src, ar.currentline, lua_tostring(L, -1));
lua_pushfstring(L, "%s:%d: %s", ar.short_src, ar.currentline, msg);
}
return lua_errorobj(L);
}

3
lauxlib.h

@ -1,5 +1,5 @@
/*
** $Id: lauxlib.h,v 1.45 2002/05/01 20:40:42 roberto Exp roberto $
** $Id: lauxlib.h,v 1.46 2002/05/06 19:05:10 roberto Exp roberto $
** Auxiliary functions for building Lua libraries
** See Copyright Notice in lua.h
*/
@ -45,7 +45,6 @@ LUALIB_API void luaL_check_type (lua_State *L, int narg, int t);
LUALIB_API void luaL_check_any (lua_State *L, int narg);
LUALIB_API int luaL_verror (lua_State *L, const char *fmt, ...);
LUALIB_API void luaL_vstr (lua_State *L, const char *fmt, ...);
LUALIB_API int luaL_findstring (const char *name,
const char *const list[]);

25
lbaselib.c

@ -1,5 +1,5 @@
/*
** $Id: lbaselib.c,v 1.72 2002/05/06 19:05:10 roberto Exp roberto $
** $Id: lbaselib.c,v 1.73 2002/05/13 13:10:58 roberto Exp roberto $
** Basic library
** See Copyright Notice in lua.h
*/
@ -31,28 +31,6 @@ static int luaB__ALERT (lua_State *L) {
}
/*
** Basic implementation of _ERRORMESSAGE.
** The library `liolib' redefines _ERRORMESSAGE for better error information.
*/
static int luaB__ERRORMESSAGE (lua_State *L) {
lua_Debug ar;
luaL_check_type(L, 1, LUA_TSTRING);
lua_pushliteral(L, "error: ");
lua_pushvalue(L, 1);
if (lua_getstack(L, 1, &ar)) {
lua_getinfo(L, "Sl", &ar);
if (ar.source && ar.currentline > 0) {
luaL_vstr(L, "\n <%s: line %d>", ar.short_src, ar.currentline);
lua_concat(L, 2);
}
}
lua_pushliteral(L, "\n");
lua_concat(L, 3);
return 1;
}
/*
** If your system does not support `stdout', you can just remove this function.
** If you need, you can define your own `print' function, following this
@ -408,7 +386,6 @@ static int luaB_require (lua_State *L) {
static const luaL_reg base_funcs[] = {
{LUA_ALERT, luaB__ALERT},
{"_ERRORMESSAGE", luaB__ERRORMESSAGE},
{"error", luaB_error},
{"metatable", luaB_metatable},
{"globals", luaB_globals},

17
ldblib.c

@ -1,5 +1,5 @@
/*
** $Id: ldblib.c,v 1.51 2002/05/07 17:36:56 roberto Exp roberto $
** $Id: ldblib.c,v 1.52 2002/05/15 18:57:44 roberto Exp roberto $
** Interface from Lua to its debug API
** See Copyright Notice in lua.h
*/
@ -41,7 +41,7 @@ static int getinfo (lua_State *L) {
}
}
else if (lua_isfunction(L, 1)) {
luaL_vstr(L, ">%s", options);
lua_pushfstring(L, ">%s", options);
options = lua_tostring(L, -1);
lua_pushvalue(L, 1);
}
@ -207,23 +207,24 @@ static int errorfb (lua_State *L) {
sprintf(buff, "%4d- ", level-1);
lua_pushstring(L, buff);
lua_getinfo(L, "Snl", &ar);
luaL_vstr(L, "%s:", ar.short_src);
lua_pushfstring(L, "%s:", ar.short_src);
if (ar.currentline > 0)
luaL_vstr(L, "%d:", ar.currentline);
lua_pushfstring(L, "%d:", ar.currentline);
switch (*ar.namewhat) {
case 'g': /* global */
case 'l': /* local */
case 'f': /* field */
case 'm': /* method */
luaL_vstr(L, " in function `%s'", ar.name);
lua_pushfstring(L, " in function `%s'", ar.name);
break;
default: {
if (*ar.what == 'm') /* main? */
luaL_vstr(L, " in main chunk");
lua_pushfstring(L, " in main chunk");
else if (*ar.what == 'C') /* C function? */
luaL_vstr(L, "%s", ar.short_src);
lua_pushfstring(L, "%s", ar.short_src);
else
luaL_vstr(L, " in function <%s:%d>", ar.short_src, ar.linedefined);
lua_pushfstring(L, " in function <%s:%d>",
ar.short_src, ar.linedefined);
}
}
lua_pushliteral(L, "\n");

6
ldebug.c

@ -1,5 +1,5 @@
/*
** $Id: ldebug.c,v 1.115 2002/05/14 17:52:22 roberto Exp roberto $
** $Id: ldebug.c,v 1.116 2002/05/15 18:57:44 roberto Exp roberto $
** Debug Interface
** See Copyright Notice in lua.h
*/
@ -517,13 +517,13 @@ void luaG_runerror (lua_State *L, const char *fmt, ...) {
const char *msg;
va_list argp;
va_start(argp, fmt);
msg = luaO_vpushstr(L, fmt, argp);
msg = luaO_pushvfstring(L, fmt, argp);
va_end(argp);
if (isLmark(L->ci)) {
char buff[LUA_IDSIZE];
int line = currentline(L, L->ci);
luaO_chunkid(buff, getstr(getluaproto(L->ci)->source), LUA_IDSIZE);
msg = luaO_pushstr(L, "%s:%d: %s", buff, line, msg);
msg = luaO_pushfstring(L, "%s:%d: %s", buff, line, msg);
}
luaD_error(L, msg, LUA_ERRRUN);
}

4
ldo.c

@ -1,5 +1,5 @@
/*
** $Id: ldo.c,v 1.174 2002/05/07 17:36:56 roberto Exp roberto $
** $Id: ldo.c,v 1.175 2002/05/15 18:57:44 roberto Exp roberto $
** Stack and Call structure of Lua
** See Copyright Notice in lua.h
*/
@ -424,7 +424,7 @@ int luaD_protectedparser (lua_State *L, ZIO *z, int bin) {
lua_lock(L);
p.z = z; p.bin = bin;
/* before parsing, give a (good) chance to GC */
if (G(L)->nblocks/8 >= G(L)->GCthreshold/10)
if (G(L)->nblocks + G(L)->nblocks/4 >= G(L)->GCthreshold)
luaC_collectgarbage(L);
old_blocks = G(L)->nblocks;
setnilvalue(&p.err);

16
llex.c

@ -1,5 +1,5 @@
/*
** $Id: llex.c,v 1.100 2002/05/07 17:36:56 roberto Exp roberto $
** $Id: llex.c,v 1.101 2002/05/15 18:57:44 roberto Exp roberto $
** Lexical Analyzer
** See Copyright Notice in lua.h
*/
@ -51,7 +51,7 @@ void luaX_init (lua_State *L) {
void luaX_checklimit (LexState *ls, int val, int limit, const char *msg) {
if (val > limit) {
msg = luaO_pushstr(ls->L, "too many %s (limit=%d)", msg, limit);
msg = luaO_pushfstring(ls->L, "too many %s (limit=%d)", msg, limit);
luaX_syntaxerror(ls, msg);
}
}
@ -61,7 +61,7 @@ static void luaX_error (LexState *ls, const char *s, const char *token) {
lua_State *L = ls->L;
char buff[MAXSRC];
luaO_chunkid(buff, getstr(ls->source), MAXSRC);
luaO_pushstr(L, "%s:%d: %s near `%s'", buff, ls->linenumber, s, token);
luaO_pushfstring(L, "%s:%d: %s near `%s'", buff, ls->linenumber, s, token);
luaD_errorobj(L, L->top - 1, LUA_ERRSYNTAX);
}
@ -70,13 +70,13 @@ void luaX_syntaxerror (LexState *ls, const char *msg) {
const char *lasttoken;
switch (ls->t.token) {
case TK_NAME:
lasttoken = luaO_pushstr(ls->L, "%s", getstr(ls->t.seminfo.ts));
lasttoken = luaO_pushfstring(ls->L, "%s", getstr(ls->t.seminfo.ts));
break;
case TK_STRING:
lasttoken = luaO_pushstr(ls->L, "\"%s\"", getstr(ls->t.seminfo.ts));
lasttoken = luaO_pushfstring(ls->L, "\"%s\"", getstr(ls->t.seminfo.ts));
break;
case TK_NUMBER:
lasttoken = luaO_pushstr(ls->L, "%f", ls->t.seminfo.r);
lasttoken = luaO_pushfstring(ls->L, "%f", ls->t.seminfo.r);
break;
default:
lasttoken = luaX_token2str(ls, ls->t.token);
@ -89,7 +89,7 @@ void luaX_syntaxerror (LexState *ls, const char *msg) {
const char *luaX_token2str (LexState *ls, int token) {
if (token < FIRST_RESERVED) {
lua_assert(token == (char)token);
return luaO_pushstr(ls->L, "%c", token);
return luaO_pushfstring(ls->L, "%c", token);
}
else
return token2string[token-FIRST_RESERVED];
@ -397,7 +397,7 @@ int luaX_lex (LexState *LS, SemInfo *seminfo) {
int c = LS->current;
if (iscntrl(c))
luaX_error(LS, "invalid control char",
luaO_pushstr(LS->L, "char(%d)", c));
luaO_pushfstring(LS->L, "char(%d)", c));
next(LS);
return c; /* single-char tokens (+ - / ...) */
}

8
lobject.c

@ -1,5 +1,5 @@
/*
** $Id: lobject.c,v 1.79 2002/05/07 17:36:56 roberto Exp roberto $
** $Id: lobject.c,v 1.80 2002/05/15 18:57:44 roberto Exp roberto $
** Some generic functions over Lua objects
** See Copyright Notice in lua.h
*/
@ -99,7 +99,7 @@ static void pushstr (lua_State *L, const char *str) {
/* this function handles only `%d', `%c', %f, and `%s' formats */
const char *luaO_vpushstr (lua_State *L, const char *fmt, va_list argp) {
const char *luaO_pushvfstring (lua_State *L, const char *fmt, va_list argp) {
int n = 1;
pushstr(L, "");
for (;;) {
@ -141,11 +141,11 @@ const char *luaO_vpushstr (lua_State *L, const char *fmt, va_list argp) {
}
const char *luaO_pushstr (lua_State *L, const char *fmt, ...) {
const char *luaO_pushfstring (lua_State *L, const char *fmt, ...) {
const char *msg;
va_list argp;
va_start(argp, fmt);
msg = luaO_vpushstr(L, fmt, argp);
msg = luaO_pushvfstring(L, fmt, argp);
va_end(argp);
return msg;
}

6
lobject.h

@ -1,5 +1,5 @@
/*
** $Id: lobject.h,v 1.131 2002/05/07 17:36:56 roberto Exp roberto $
** $Id: lobject.h,v 1.132 2002/05/15 18:57:44 roberto Exp roberto $
** Type definitions for Lua objects
** See Copyright Notice in lua.h
*/
@ -250,8 +250,8 @@ void *luaO_openspaceaux (lua_State *L, size_t n);
int luaO_equalObj (const TObject *t1, const TObject *t2);
int luaO_str2d (const char *s, lua_Number *result);
const char *luaO_vpushstr (lua_State *L, const char *fmt, va_list argp);
const char *luaO_pushstr (lua_State *L, const char *fmt, ...);
const char *luaO_pushvfstring (lua_State *L, const char *fmt, va_list argp);
const char *luaO_pushfstring (lua_State *L, const char *fmt, ...);
void luaO_chunkid (char *out, const char *source, int len);

6
lparser.c

@ -1,5 +1,5 @@
/*
** $Id: lparser.c,v 1.182 2002/05/13 13:09:00 roberto Exp roberto $
** $Id: lparser.c,v 1.183 2002/05/14 17:52:22 roberto Exp roberto $
** Lua Parser
** See Copyright Notice in lua.h
*/
@ -70,7 +70,7 @@ static void lookahead (LexState *ls) {
static void error_expected (LexState *ls, int token) {
luaX_syntaxerror(ls,
luaO_pushstr(ls->L, "`%s' expected", luaX_token2str(ls, token)));
luaO_pushfstring(ls->L, "`%s' expected", luaX_token2str(ls, token)));
}
@ -98,7 +98,7 @@ static void check_match (LexState *ls, int what, int who, int where) {
if (where == ls->linenumber)
error_expected(ls, what);
else {
luaX_syntaxerror(ls, luaO_pushstr(ls->L,
luaX_syntaxerror(ls, luaO_pushfstring(ls->L,
"`%s' expected (to close `%s' at line %d)",
luaX_token2str(ls, what), luaX_token2str(ls, who), where));
}

18
lua.h

@ -1,7 +1,7 @@
/*
** $Id: lua.h,v 1.131 2002/05/06 19:05:10 roberto Exp roberto $
** $Id: lua.h,v 1.132 2002/05/07 17:36:56 roberto Exp roberto $
** Lua - An Extensible Extension Language
** TeCGraf: Grupo de Tecnologia em Computacao Grafica, PUC-Rio, Brazil
** Tecgraf: Grupo de Tecnologia em Computacao Grafica, PUC-Rio, Brazil
** e-mail: info@lua.org
** www: http://www.lua.org
** See Copyright Notice at the end of this file
@ -21,7 +21,7 @@
#define LUA_VERSION "Lua 5.0 (alpha)"
#define LUA_COPYRIGHT "Copyright (C) 1994-2002 TeCGraf, PUC-Rio"
#define LUA_COPYRIGHT "Copyright (C) 1994-2002 Tecgraf, PUC-Rio"
#define LUA_AUTHORS "W. Celes, R. Ierusalimschy & L. H. de Figueiredo"
@ -130,7 +130,7 @@ LUA_API int lua_lessthan (lua_State *L, int index1, int index2);
LUA_API lua_Number lua_tonumber (lua_State *L, int index);
LUA_API int lua_toboolean (lua_State *L, int index);
LUA_API const char *lua_tostring (lua_State *L, int index);
LUA_API const char *lua_tostring (lua_State *L, int index);
LUA_API size_t lua_strlen (lua_State *L, int index);
LUA_API lua_CFunction lua_tocfunction (lua_State *L, int index);
LUA_API void *lua_touserdata (lua_State *L, int index);
@ -144,7 +144,9 @@ LUA_API void lua_pushnil (lua_State *L);
LUA_API void lua_pushnumber (lua_State *L, lua_Number n);
LUA_API void lua_pushlstring (lua_State *L, const char *s, size_t len);
LUA_API void lua_pushstring (lua_State *L, const char *s);
LUA_API void lua_vpushstr (lua_State *L, const char *fmt, va_list argp);
LUA_API const char *lua_pushvfstring (lua_State *L, const char *fmt,
va_list argp);
LUA_API const char *lua_pushfstring (lua_State *L, const char *fmt, ...);
LUA_API void lua_pushcclosure (lua_State *L, lua_CFunction fn, int n);
LUA_API void lua_pushboolean (lua_State *L, int b);
LUA_API void lua_pushudataval (lua_State *L, void *p);
@ -319,7 +321,7 @@ LUA_API int lua_pushupvalues (lua_State *L);
/******************************************************************************
* Copyright (C) 1994-2001 TeCGraf, PUC-Rio. All rights reserved.
* Copyright (C) 1994-2001 Tecgraf, PUC-Rio. All rights reserved.
*
* Permission is hereby granted, without written agreement and without license
* or royalty fees, to use, copy, modify, and distribute this software and its
@ -341,14 +343,14 @@ LUA_API int lua_pushupvalues (lua_State *L);
* to, the implied warranties of merchantability and fitness for a particular
* purpose. The software provided hereunder is on an "as is" basis, and the
* authors have no obligation to provide maintenance, support, updates,
* enhancements, or modifications. In no event shall TeCGraf, PUC-Rio, or the
* enhancements, or modifications. In no event shall Tecgraf, PUC-Rio, or the
* authors be held liable to any party for direct, indirect, special,
* incidental, or consequential damages arising out of the use of this software
* and its documentation.
*
* The Lua language and this implementation have been entirely designed and
* written by Waldemar Celes Filho, Roberto Ierusalimschy and
* Luiz Henrique de Figueiredo at TeCGraf, PUC-Rio.
* Luiz Henrique de Figueiredo at Tecgraf, PUC-Rio.
*
* This implementation contains no third-party code.
******************************************************************************/

Loading…
Cancel
Save