From 8060193702b21a06af3541555db4cd317c733ce9 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Mon, 11 Sep 2000 17:29:27 -0300 Subject: [PATCH] `lauxlib' is now part of the libraries (not used by core Lua) --- lapi.c | 7 +++--- lauxlib.c | 24 +------------------ lauxlib.h | 3 +-- ldebug.c | 28 +++++++++++++---------- ldo.c | 3 +-- liolib.c | 18 +++++++-------- llex.c | 7 +++--- lobject.c | 36 ++++++++++++++++++++++++++++- lobject.h | 5 +++- ltable.c | 3 +-- ltm.c | 26 +++++++++++++-------- luadebug.h | 10 ++++---- lundump.c | 19 ++++++++-------- makefile | 67 +++++++++++++++++++++++------------------------------- 14 files changed, 134 insertions(+), 122 deletions(-) diff --git a/lapi.c b/lapi.c index dc103bc4..8d5555e4 100644 --- a/lapi.c +++ b/lapi.c @@ -1,5 +1,5 @@ /* -** $Id: lapi.c,v 1.94 2000/09/05 19:33:32 roberto Exp roberto $ +** $Id: lapi.c,v 1.95 2000/09/11 19:45:27 roberto Exp roberto $ ** Lua API ** See Copyright Notice in lua.h */ @@ -10,7 +10,6 @@ #include "lua.h" #include "lapi.h" -#include "lauxlib.h" #include "ldo.h" #include "lfunc.h" #include "lgc.h" @@ -234,7 +233,7 @@ void lua_pushcclosure (lua_State *L, lua_CFunction fn, int n) { void lua_pushusertag (lua_State *L, void *u, int tag) { /* ORDER LUA_T */ luaC_checkGC(L); if (tag != LUA_ANYTAG && tag != TAG_USERDATA && tag < NUM_TAGS) - luaL_verror(L, "invalid tag for a userdata (%d)", tag); + luaO_verror(L, "invalid tag for a userdata (%d)", tag); tsvalue(L->top) = luaS_createudata(L, u, tag); ttype(L->top) = TAG_USERDATA; api_incr_top(L); @@ -387,7 +386,7 @@ void lua_settag (lua_State *L, int tag) { tsvalue(L->top-1)->u.d.tag = tag; break; default: - luaL_verror(L, "cannot change the tag of a %.20s", + luaO_verror(L, "cannot change the tag of a %.20s", luaO_typename(L->top-1)); } L->top--; diff --git a/lauxlib.c b/lauxlib.c index 84ccb3b9..ee715ab5 100644 --- a/lauxlib.c +++ b/lauxlib.c @@ -1,5 +1,5 @@ /* -** $Id: lauxlib.c,v 1.33 2000/08/29 20:43:28 roberto Exp roberto $ +** $Id: lauxlib.c,v 1.34 2000/09/11 17:38:42 roberto Exp roberto $ ** Auxiliary functions for building Lua libraries ** See Copyright Notice in lua.h */ @@ -118,28 +118,6 @@ void luaL_verror (lua_State *L, const char *fmt, ...) { } -#define EXTRALEN sizeof("string \"...\"0") - -void luaL_chunkid (char *out, const char *source, int len) { - if (*source == '(') { - strncpy(out, source+1, len-1); /* remove first char */ - out[len-1] = '\0'; /* make sure `out' has an end */ - out[strlen(out)-1] = '\0'; /* remove last char */ - } - else { - len -= EXTRALEN; - if (*source == '@') - sprintf(out, "file `%.*s'", len, source+1); - else { - const char *b = strchr(source , '\n'); /* stop at first new line */ - int lim = (b && (b-source)source = f->source->str; + ar->linedefined = f->lineDefined; + ar->what = "Lua"; +} + + static void lua_funcinfo (lua_Debug *ar, StkId func) { switch (ttype(func)) { case TAG_LCLOSURE: - ar->source = clvalue(func)->f.l->source->str; - ar->linedefined = clvalue(func)->f.l->lineDefined; - ar->what = "Lua"; + infoLproto(ar, clvalue(func)->f.l); break; case TAG_LMARK: - ar->source = infovalue(func)->func->f.l->source->str; - ar->linedefined = infovalue(func)->func->f.l->lineDefined; - ar->what = "Lua"; + infoLproto(ar, infovalue(func)->func->f.l); break; case TAG_CCLOSURE: case TAG_CMARK: ar->source = "(C)"; @@ -192,6 +195,7 @@ static void lua_funcinfo (lua_Debug *ar, StkId func) { default: LUA_INTERNALERROR("invalid `func' value"); } + luaO_chunkid(ar->source_id, ar->source, sizeof(ar->source_id)); if (ar->linedefined == 0) ar->what = "main"; } @@ -431,10 +435,10 @@ void luaG_typeerror (lua_State *L, StkId o, const char *op) { const char *kind = getobjname(L, o, &name); const char *t = luaO_typename(o); if (kind) - luaL_verror(L, "attempt to %.30s %.20s `%.40s' (a %.10s value)", + luaO_verror(L, "attempt to %.30s %.20s `%.40s' (a %.10s value)", op, kind, name, t); else - luaL_verror(L, "attempt to %.30s a %.10s value", op, t); + luaO_verror(L, "attempt to %.30s a %.10s value", op, t); } @@ -449,8 +453,8 @@ void luaG_ordererror (lua_State *L, StkId top) { const char *t1 = luaO_typename(top-2); const char *t2 = luaO_typename(top-1); if (t1[2] == t2[2]) - luaL_verror(L, "attempt to compare two %.10s values", t1); + luaO_verror(L, "attempt to compare two %.10s values", t1); else - luaL_verror(L, "attempt to compare %.10s with %.10s", t1, t2); + luaO_verror(L, "attempt to compare %.10s with %.10s", t1, t2); } diff --git a/ldo.c b/ldo.c index 1fd993c7..220be2f9 100644 --- a/ldo.c +++ b/ldo.c @@ -1,5 +1,5 @@ /* -** $Id: ldo.c,v 1.93 2000/09/04 18:52:51 roberto Exp roberto $ +** $Id: ldo.c,v 1.94 2000/09/11 17:38:42 roberto Exp roberto $ ** Stack and Call structure of Lua ** See Copyright Notice in lua.h */ @@ -12,7 +12,6 @@ #include "lua.h" -#include "lauxlib.h" #include "ldebug.h" #include "ldo.h" #include "lgc.h" diff --git a/liolib.c b/liolib.c index db9f36d6..055508c5 100644 --- a/liolib.c +++ b/liolib.c @@ -1,5 +1,5 @@ /* -** $Id: liolib.c,v 1.77 2000/09/05 19:33:32 roberto Exp $ +** $Id: liolib.c,v 1.78 2000/09/11 17:38:42 roberto Exp roberto $ ** Standard I/O (and system) library ** See Copyright Notice in lua.h */ @@ -393,8 +393,8 @@ static int io_read (lua_State *L) { firstarg = lastarg = 1; /* correct indices */ lua_pushstring(L, "*l"); /* push default argument */ } - else - luaL_checkstack(L, lastarg-firstarg+1, "too many arguments"); + else /* ensure stack space for all results and for auxlib's buffer */ + luaL_checkstack(L, lastarg-firstarg+1+LUA_MINSTACK, "too many arguments"); for (n = firstarg; n<=lastarg; n++) { int success; if (lua_isnumber(L, n)) @@ -598,7 +598,6 @@ static int errorfb (lua_State *L) { lua_concat(L, 3); while (lua_getstack(L, level++, &ar)) { char buff[120]; /* enough to fit following `sprintf's */ - char buffchunk[60]; int toconcat = 1; /* number of strings in the stack to concat */ if (level > LEVELS1 && firstpart) { /* no more than `LEVELS2' more levels? */ @@ -607,7 +606,7 @@ static int errorfb (lua_State *L) { else { lua_pushstring(L, " ...\n"); /* too many levels */ lua_concat(L, 2); - while (lua_getstack(L, level+LEVELS2, &ar)) /* get last levels */ + while (lua_getstack(L, level+LEVELS2, &ar)) /* find last levels */ level++; } firstpart = 0; @@ -616,7 +615,6 @@ static int errorfb (lua_State *L) { sprintf(buff, "%4d: ", level-1); lua_pushstring(L, buff); toconcat++; lua_getinfo(L, "Snl", &ar); - luaL_chunkid(buffchunk, ar.source, sizeof(buffchunk)); switch (*ar.namewhat) { case 'g': case 'l': /* global, local */ sprintf(buff, "function `%.50s'", ar.name); @@ -629,11 +627,11 @@ static int errorfb (lua_State *L) { break; default: { if (*ar.what == 'm') /* main? */ - sprintf(buff, "main of %.70s", buffchunk); + sprintf(buff, "main of %.70s", ar.source_id); else if (*ar.what == 'C') /* C function? */ - sprintf(buff, "%.70s", buffchunk); + sprintf(buff, "%.70s", ar.source_id); else - sprintf(buff, "function <%d:%.70s>", ar.linedefined, buffchunk); + sprintf(buff, "function <%d:%.70s>", ar.linedefined, ar.source_id); ar.source = NULL; } } @@ -643,7 +641,7 @@ static int errorfb (lua_State *L) { lua_pushstring(L, buff); toconcat++; } if (ar.source) { - sprintf(buff, " [%.70s]", buffchunk); + sprintf(buff, " [%.70s]", ar.source_id); lua_pushstring(L, buff); toconcat++; } lua_pushstring(L, "\n"); toconcat++; diff --git a/llex.c b/llex.c index d16cb99f..e4c4936a 100644 --- a/llex.c +++ b/llex.c @@ -1,5 +1,5 @@ /* -** $Id: llex.c,v 1.68 2000/08/22 20:07:56 roberto Exp $ +** $Id: llex.c,v 1.69 2000/09/11 17:38:42 roberto Exp roberto $ ** Lexical Analyzer ** See Copyright Notice in lua.h */ @@ -11,7 +11,6 @@ #include "lua.h" -#include "lauxlib.h" #include "llex.h" #include "lmem.h" #include "lobject.h" @@ -58,8 +57,8 @@ void luaX_checklimit (LexState *ls, int val, int limit, const char *msg) { void luaX_syntaxerror (LexState *ls, const char *s, const char *token) { char buff[MAXSRC]; - luaL_chunkid(buff, ls->source->str, sizeof(buff)); - luaL_verror(ls->L, "%.100s;\n last token read: `%.50s' at line %d in %.80s", + luaO_chunkid(buff, ls->source->str, sizeof(buff)); + luaO_verror(ls->L, "%.100s;\n last token read: `%.50s' at line %d in %.80s", s, token, ls->linenumber, buff); } diff --git a/lobject.c b/lobject.c index 7f3d71fc..c4f45d8b 100644 --- a/lobject.c +++ b/lobject.c @@ -1,11 +1,14 @@ /* -** $Id: lobject.c,v 1.45 2000/08/11 16:17:28 roberto Exp roberto $ +** $Id: lobject.c,v 1.46 2000/09/11 17:38:42 roberto Exp roberto $ ** Some generic functions over Lua objects ** See Copyright Notice in lua.h */ #include +#include +#include #include +#include #include "lua.h" @@ -123,3 +126,34 @@ int luaO_str2d (const char *s, Number *result) { /* LUA_NUMBER */ return 1; } + +void luaO_verror (lua_State *L, const char *fmt, ...) { + char buff[500]; + va_list argp; + va_start(argp, fmt); + vsprintf(buff, fmt, argp); + va_end(argp); + lua_error(L, buff); +} + + +#define EXTRALEN sizeof("string \"...\"0") + +void luaO_chunkid (char *out, const char *source, int len) { + if (*source == '(') { + strncpy(out, source+1, len-1); /* remove first char */ + out[len-1] = '\0'; /* make sure `out' has an end */ + out[strlen(out)-1] = '\0'; /* remove last char */ + } + else { + len -= EXTRALEN; + if (*source == '@') + sprintf(out, "file `%.*s'", len, source+1); + else { + const char *b = strchr(source , '\n'); /* stop at first new line */ + int lim = (b && (b-source)= IM_N) - luaL_verror(L, "event `%.50s' is deprecated", name); + luaO_verror(L, "event `%.50s' is deprecated", name); if (e == IM_GC && t == TAG_TABLE) - luaL_verror(L, "event `gc' for tables is deprecated"); + luaO_verror(L, "event `gc' for tables is deprecated"); if (e < 0) - luaL_verror(L, "`%.50s' is not a valid event name", name); + luaO_verror(L, "`%.50s' is not a valid event name", name); return e; } @@ -86,12 +94,12 @@ int lua_newtag (lua_State *L) { static void checktag (lua_State *L, int tag) { if (!(0 <= tag && tag <= L->last_tag)) - luaL_verror(L, "%d is not a valid tag", tag); + luaO_verror(L, "%d is not a valid tag", tag); } void luaT_realtag (lua_State *L, int tag) { if (!(NUM_TAGS <= tag && tag <= L->last_tag)) - luaL_verror(L, "tag %d was not created by `newtag'", tag); + luaO_verror(L, "tag %d was not created by `newtag'", tag); } @@ -140,7 +148,7 @@ void lua_settagmethod (lua_State *L, int t, const char *event) { e = luaI_checkevent(L, event, t); checktag(L, t); if (!luaT_validevent(t, e)) - luaL_verror(L, "cannot change `%.20s' tag method for type `%.20s'%.20s", + luaO_verror(L, "cannot change `%.20s' tag method for type `%.20s'%.20s", luaT_eventname[e], luaO_typenames[t], (t == TAG_TABLE || t == TAG_USERDATA) ? " with default tag" : ""); diff --git a/luadebug.h b/luadebug.h index 67472ad9..f81496e1 100644 --- a/luadebug.h +++ b/luadebug.h @@ -1,5 +1,5 @@ /* -** $Id: luadebug.h,v 1.12 2000/08/11 16:17:28 roberto Exp roberto $ +** $Id: luadebug.h,v 1.13 2000/08/28 17:57:04 roberto Exp roberto $ ** Debugging API ** See Copyright Notice in lua.h */ @@ -26,16 +26,18 @@ lua_Hook lua_setcallhook (lua_State *L, lua_Hook func); lua_Hook lua_setlinehook (lua_State *L, lua_Hook func); +#define LUA_IDSIZE 60 struct lua_Debug { const char *event; /* `call', `return' */ - const char *source; /* (S) */ - int linedefined; /* (S) */ - const char *what; /* (S) `Lua' function, `C' function, Lua `main' */ int currentline; /* (l) */ const char *name; /* (n) */ const char *namewhat; /* (n) `global', `tag method', `local', `field' */ int nups; /* (u) number of upvalues */ + int linedefined; /* (S) */ + const char *what; /* (S) `Lua' function, `C' function, Lua `main' */ + const char *source; /* (S) */ + char source_id[LUA_IDSIZE]; /* (S) */ /* private part */ struct lua_TObject *_func; /* active function */ }; diff --git a/lundump.c b/lundump.c index 95690033..d8f74758 100644 --- a/lundump.c +++ b/lundump.c @@ -1,5 +1,5 @@ /* -** $Id: lundump.c,v 1.27 2000/09/04 18:53:41 roberto Exp roberto $ +** $Id: lundump.c,v 1.28 2000/09/11 17:38:42 roberto Exp roberto $ ** load bytecodes from files ** See Copyright Notice in lua.h */ @@ -7,7 +7,6 @@ #include #include -#include "lauxlib.h" #include "lfunc.h" #include "lmem.h" #include "lopcodes.h" @@ -26,7 +25,7 @@ static const char* ZNAME(ZIO* Z) static void unexpectedEOZ (lua_State* L, ZIO* Z) { - luaL_verror(L,"unexpected end of file in `%.255s'",ZNAME(Z)); + luaO_verror(L,"unexpected end of file in `%.255s'",ZNAME(Z)); } static int ezgetc (lua_State* L, ZIO* Z) @@ -100,7 +99,7 @@ static void LoadCode (lua_State* L, Proto* tf, ZIO* Z, int swap) #if 0 if (swap) SwapBytes(tf->code,sizeof(*tf->code),size); #endif - if (tf->code[size-1]!=OP_END) luaL_verror(L,"bad code in `%.255s'",ZNAME(Z)); + if (tf->code[size-1]!=OP_END) luaO_verror(L,"bad code in `%.255s'",ZNAME(Z)); } static void LoadLocals (lua_State* L, Proto* tf, ZIO* Z, int swap) @@ -167,14 +166,14 @@ static void LoadSignature (lua_State* L, ZIO* Z) const char* s=SIGNATURE; while (*s!=0 && ezgetc(L,Z)==*s) ++s; - if (*s!=0) luaL_verror(L,"bad signature in `%.255s'",ZNAME(Z)); + if (*s!=0) luaO_verror(L,"bad signature in `%.255s'",ZNAME(Z)); } static void TestSize (lua_State* L, int s, const char* what, ZIO* Z) { int r=ezgetc(L,Z); if (r!=s) - luaL_verror(L,"virtual machine mismatch in `%.255s':\n" + luaO_verror(L,"virtual machine mismatch in `%.255s':\n" " %s is %d but read %d",ZNAME(Z),what,r,s); } @@ -188,11 +187,11 @@ static int LoadHeader (lua_State* L, ZIO* Z) LoadSignature(L,Z); version=ezgetc(L,Z); if (version>VERSION) - luaL_verror(L,"`%.255s' too new:\n" + luaO_verror(L,"`%.255s' too new:\n" " read version %d.%d; expected at most %d.%d", ZNAME(Z),V(version),V(VERSION)); if (version