summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lapi.c7
-rw-r--r--lauxlib.c9
-rw-r--r--ldblib.c26
-rw-r--r--ldebug.c30
-rw-r--r--ldebug.h3
-rw-r--r--ldo.c17
-rw-r--r--ldo.h3
-rw-r--r--llex.c5
-rw-r--r--lmem.c7
-rw-r--r--lobject.c30
-rw-r--r--lobject.h3
-rw-r--r--ltable.c9
-rw-r--r--lua.c24
-rw-r--r--lundump.c20
-rw-r--r--lvm.c16
15 files changed, 113 insertions, 96 deletions
diff --git a/lapi.c b/lapi.c
index 87a2abbe..eae26308 100644
--- a/lapi.c
+++ b/lapi.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lapi.c,v 1.189 2002/05/06 19:05:10 roberto Exp roberto $ 2** $Id: lapi.c,v 1.190 2002/05/07 17:36:56 roberto Exp roberto $
3** Lua API 3** Lua API
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -11,6 +11,7 @@
11#include "lua.h" 11#include "lua.h"
12 12
13#include "lapi.h" 13#include "lapi.h"
14#include "ldebug.h"
14#include "ldo.h" 15#include "ldo.h"
15#include "lfunc.h" 16#include "lfunc.h"
16#include "lgc.h" 17#include "lgc.h"
@@ -521,8 +522,8 @@ LUA_API void lua_setmetatable (lua_State *L, int objindex) {
521 uvalue(obj)->uv.metatable = hvalue(mt); 522 uvalue(obj)->uv.metatable = hvalue(mt);
522 break; 523 break;
523 default: 524 default:
524 luaO_verror(L, "cannot change the meta table of a %s", 525 luaG_runerror(L, "cannot change the meta table of a %s",
525 luaT_typenames[ttype(obj)]); 526 luaT_typenames[ttype(obj)]);
526 } 527 }
527 lua_unlock(L); 528 lua_unlock(L);
528} 529}
diff --git a/lauxlib.c b/lauxlib.c
index 2537ca8c..ecaa6c8f 100644
--- a/lauxlib.c
+++ b/lauxlib.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lauxlib.c,v 1.68 2002/05/06 19:05:10 roberto Exp roberto $ 2** $Id: lauxlib.c,v 1.69 2002/05/07 17:36:56 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*/
@@ -151,10 +151,17 @@ LUALIB_API void luaL_vstr (lua_State *L, const char *fmt, ...) {
151 151
152 152
153LUALIB_API int luaL_verror (lua_State *L, const char *fmt, ...) { 153LUALIB_API int luaL_verror (lua_State *L, const char *fmt, ...) {
154 lua_Debug ar;
154 va_list argp; 155 va_list argp;
155 va_start(argp, fmt); 156 va_start(argp, fmt);
156 lua_vpushstr(L, fmt, argp); 157 lua_vpushstr(L, fmt, argp);
157 va_end(argp); 158 va_end(argp);
159 if (lua_getstack(L, 1, &ar)) { /* check calling function */
160 lua_getinfo(L, "Snl", &ar);
161 if (ar.currentline > 0)
162 luaL_vstr(L, "%s:%d: %s",
163 ar.short_src, ar.currentline, lua_tostring(L, -1));
164 }
158 return lua_errorobj(L); 165 return lua_errorobj(L);
159} 166}
160 167
diff --git a/ldblib.c b/ldblib.c
index 8fe60179..da0a90f5 100644
--- a/ldblib.c
+++ b/ldblib.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ldblib.c,v 1.50 2002/05/06 19:05:10 roberto Exp roberto $ 2** $Id: ldblib.c,v 1.51 2002/05/07 17:36:56 roberto Exp roberto $
3** Interface from Lua to its debug API 3** Interface from Lua to its debug API
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -54,8 +54,7 @@ static int getinfo (lua_State *L) {
54 switch (*options) { 54 switch (*options) {
55 case 'S': 55 case 'S':
56 settabss(L, "source", ar.source); 56 settabss(L, "source", ar.source);
57 if (ar.source) 57 settabss(L, "short_src", ar.short_src);
58 settabss(L, "short_src", ar.short_src);
59 settabsi(L, "linedefined", ar.linedefined); 58 settabsi(L, "linedefined", ar.linedefined);
60 settabss(L, "what", ar.what); 59 settabss(L, "what", ar.what);
61 break; 60 break;
@@ -205,31 +204,28 @@ static int errorfb (lua_State *L) {
205 firstpart = 0; 204 firstpart = 0;
206 continue; 205 continue;
207 } 206 }
208 sprintf(buff, "%4d: ", level-1); 207 sprintf(buff, "%4d- ", level-1);
209 lua_pushstring(L, buff); 208 lua_pushstring(L, buff);
210 lua_getinfo(L, "Snl", &ar); 209 lua_getinfo(L, "Snl", &ar);
210 luaL_vstr(L, "%s:", ar.short_src);
211 if (ar.currentline > 0)
212 luaL_vstr(L, "%d:", ar.currentline);
211 switch (*ar.namewhat) { 213 switch (*ar.namewhat) {
212 case 'g': case 'l': /* global, local */ 214 case 'g': /* global */
213 luaL_vstr(L, "function `%s'", ar.name); 215 case 'l': /* local */
214 break;
215 case 'f': /* field */ 216 case 'f': /* field */
216 case 'm': /* method */ 217 case 'm': /* method */
217 luaL_vstr(L, "method `%s'", ar.name); 218 luaL_vstr(L, " in function `%s'", ar.name);
218 break; 219 break;
219 default: { 220 default: {
220 if (*ar.what == 'm') /* main? */ 221 if (*ar.what == 'm') /* main? */
221 luaL_vstr(L, "main of %s", ar.short_src); 222 luaL_vstr(L, " in main chunk");
222 else if (*ar.what == 'C') /* C function? */ 223 else if (*ar.what == 'C') /* C function? */
223 luaL_vstr(L, "%s", ar.short_src); 224 luaL_vstr(L, "%s", ar.short_src);
224 else 225 else
225 luaL_vstr(L, "function <%d:%s>", ar.linedefined, ar.short_src); 226 luaL_vstr(L, " in function <%s:%d>", ar.short_src, ar.linedefined);
226 ar.source = NULL; /* do not print source again */
227 } 227 }
228 } 228 }
229 if (ar.currentline > 0)
230 luaL_vstr(L, " at line %d", ar.currentline);
231 if (ar.source)
232 luaL_vstr(L, " [%s]", ar.short_src);
233 lua_pushliteral(L, "\n"); 229 lua_pushliteral(L, "\n");
234 lua_concat(L, lua_gettop(L)); 230 lua_concat(L, lua_gettop(L));
235 } 231 }
diff --git a/ldebug.c b/ldebug.c
index 601190e7..eb2aa527 100644
--- a/ldebug.c
+++ b/ldebug.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ldebug.c,v 1.114 2002/05/13 13:09:00 roberto Exp roberto $ 2** $Id: ldebug.c,v 1.115 2002/05/14 17:52:22 roberto Exp roberto $
3** Debug Interface 3** Debug Interface
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -144,11 +144,11 @@ static void funcinfo (lua_State *L, lua_Debug *ar, StkId func) {
144 if (ttype(func) == LUA_TFUNCTION) 144 if (ttype(func) == LUA_TFUNCTION)
145 cl = clvalue(func); 145 cl = clvalue(func);
146 else { 146 else {
147 luaD_runerror(L, "value for `lua_getinfo' is not a function"); 147 luaG_runerror(L, "value for `lua_getinfo' is not a function");
148 cl = NULL; /* to avoid warnings */ 148 cl = NULL; /* to avoid warnings */
149 } 149 }
150 if (cl->c.isC) { 150 if (cl->c.isC) {
151 ar->source = "=C"; 151 ar->source = "=[C]";
152 ar->linedefined = -1; 152 ar->linedefined = -1;
153 ar->what = "C"; 153 ar->what = "C";
154 } 154 }
@@ -481,10 +481,10 @@ void luaG_typeerror (lua_State *L, const TObject *o, const char *op) {
481 if (isinstack(L->ci, o)) 481 if (isinstack(L->ci, o))
482 kind = getobjname(L, L->ci, o - L->ci->base, &name); 482 kind = getobjname(L, L->ci, o - L->ci->base, &name);
483 if (kind) 483 if (kind)
484 luaO_verror(L, "attempt to %s %s `%s' (a %s value)", 484 luaG_runerror(L, "attempt to %s %s `%s' (a %s value)",
485 op, kind, name, t); 485 op, kind, name, t);
486 else 486 else
487 luaO_verror(L, "attempt to %s a %s value", op, t); 487 luaG_runerror(L, "attempt to %s a %s value", op, t);
488} 488}
489 489
490 490
@@ -507,8 +507,24 @@ void luaG_ordererror (lua_State *L, const TObject *p1, const TObject *p2) {
507 const char *t1 = luaT_typenames[ttype(p1)]; 507 const char *t1 = luaT_typenames[ttype(p1)];
508 const char *t2 = luaT_typenames[ttype(p2)]; 508 const char *t2 = luaT_typenames[ttype(p2)];
509 if (t1[2] == t2[2]) 509 if (t1[2] == t2[2])
510 luaO_verror(L, "attempt to compare two %s values", t1); 510 luaG_runerror(L, "attempt to compare two %s values", t1);
511 else 511 else
512 luaO_verror(L, "attempt to compare %s with %s", t1, t2); 512 luaG_runerror(L, "attempt to compare %s with %s", t1, t2);
513}
514
515
516void luaG_runerror (lua_State *L, const char *fmt, ...) {
517 const char *msg;
518 va_list argp;
519 va_start(argp, fmt);
520 msg = luaO_vpushstr(L, fmt, argp);
521 va_end(argp);
522 if (isLmark(L->ci)) {
523 char buff[LUA_IDSIZE];
524 int line = currentline(L, L->ci);
525 luaO_chunkid(buff, getstr(getluaproto(L->ci)->source), LUA_IDSIZE);
526 msg = luaO_pushstr(L, "%s:%d: %s", buff, line, msg);
527 }
528 luaD_error(L, msg, LUA_ERRRUN);
513} 529}
514 530
diff --git a/ldebug.h b/ldebug.h
index 1aafbb72..ef0a046f 100644
--- a/ldebug.h
+++ b/ldebug.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ldebug.h,v 1.19 2002/04/10 12:11:07 roberto Exp roberto $ 2** $Id: ldebug.h,v 1.20 2002/05/02 13:06:20 roberto Exp roberto $
3** Auxiliary functions from Debug Interface module 3** Auxiliary functions from Debug Interface module
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -20,6 +20,7 @@ void luaG_typeerror (lua_State *L, const TObject *o, const char *opname);
20void luaG_concaterror (lua_State *L, StkId p1, StkId p2); 20void luaG_concaterror (lua_State *L, StkId p1, StkId p2);
21void luaG_aritherror (lua_State *L, StkId p1, const TObject *p2); 21void luaG_aritherror (lua_State *L, StkId p1, const TObject *p2);
22void luaG_ordererror (lua_State *L, const TObject *p1, const TObject *p2); 22void luaG_ordererror (lua_State *L, const TObject *p1, const TObject *p2);
23void luaG_runerror (lua_State *L, const char *fmt, ...);
23int luaG_checkcode (const Proto *pt); 24int luaG_checkcode (const Proto *pt);
24 25
25 26
diff --git a/ldo.c b/ldo.c
index 87a78ed8..5b5bad8d 100644
--- a/ldo.c
+++ b/ldo.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ldo.c,v 1.173 2002/05/01 20:40:42 roberto Exp roberto $ 2** $Id: ldo.c,v 1.174 2002/05/07 17:36:56 roberto Exp roberto $
3** Stack and Call structure of Lua 3** Stack and Call structure of Lua
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -113,7 +113,7 @@ static void luaD_growCI (lua_State *L) {
113 else { 113 else {
114 luaD_reallocCI(L, 2*L->size_ci); 114 luaD_reallocCI(L, 2*L->size_ci);
115 if (L->size_ci > LUA_MAXCALLS) 115 if (L->size_ci > LUA_MAXCALLS)
116 luaD_runerror(L, "stack overflow"); 116 luaG_runerror(L, "stack overflow");
117 } 117 }
118 L->ci++; 118 L->ci++;
119} 119}
@@ -279,7 +279,7 @@ void luaD_call (lua_State *L, StkId func, int nResults) {
279 firstResult = luaV_execute(L); /* call it */ 279 firstResult = luaV_execute(L); /* call it */
280 if (firstResult == NULL) { 280 if (firstResult == NULL) {
281 luaD_poscall(L, 0, L->top); 281 luaD_poscall(L, 0, L->top);
282 luaD_runerror(L, "attempt to `yield' across tag-method/C-call boundary"); 282 luaG_runerror(L, "attempt to `yield' across tag-method/C-call boundary");
283 } 283 }
284 } 284 }
285 luaD_poscall(L, nResults, firstResult); 285 luaD_poscall(L, nResults, firstResult);
@@ -335,9 +335,9 @@ LUA_API int lua_resume (lua_State *L, lua_State *co) {
335 lua_lock(L); 335 lua_lock(L);
336 ci = co->ci; 336 ci = co->ci;
337 if (ci == co->base_ci) /* no activation record? ?? */ 337 if (ci == co->base_ci) /* no activation record? ?? */
338 luaD_runerror(L, "thread is dead - cannot be resumed"); 338 luaG_runerror(L, "thread is dead - cannot be resumed");
339 if (co->errorJmp != NULL) /* ?? */ 339 if (co->errorJmp != NULL) /* ?? */
340 luaD_runerror(L, "thread is active - cannot be resumed"); 340 luaG_runerror(L, "thread is active - cannot be resumed");
341 if (L->errorJmp) { 341 if (L->errorJmp) {
342 setobj(&ud.err, L->errorJmp->err); 342 setobj(&ud.err, L->errorJmp->err);
343 } 343 }
@@ -359,7 +359,7 @@ LUA_API int lua_yield (lua_State *L, int nresults) {
359 lua_lock(L); 359 lua_lock(L);
360 ci = L->ci; 360 ci = L->ci;
361 if (ci_func(ci-1)->c.isC) 361 if (ci_func(ci-1)->c.isC)
362 luaD_runerror(L, "cannot `yield' a C function"); 362 luaG_runerror(L, "cannot `yield' a C function");
363 ci->yield_results = nresults; 363 ci->yield_results = nresults;
364 lua_unlock(L); 364 lua_unlock(L);
365 return -1; 365 return -1;
@@ -492,11 +492,6 @@ void luaD_error (lua_State *L, const char *s, int errcode) {
492} 492}
493 493
494 494
495void luaD_runerror (lua_State *L, const char *s) {
496 luaD_error(L, s, LUA_ERRRUN);
497}
498
499
500int luaD_runprotected (lua_State *L, Pfunc f, TObject *ud) { 495int luaD_runprotected (lua_State *L, Pfunc f, TObject *ud) {
501 struct lua_longjmp lj; 496 struct lua_longjmp lj;
502 lj.ci = L->ci; 497 lj.ci = L->ci;
diff --git a/ldo.h b/ldo.h
index 0c4dfbca..914eddaa 100644
--- a/ldo.h
+++ b/ldo.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ldo.h,v 1.43 2002/04/22 14:40:50 roberto Exp roberto $ 2** $Id: ldo.h,v 1.44 2002/05/01 20:40:42 roberto Exp roberto $
3** Stack and Call structure of Lua 3** Stack and Call structure of Lua
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -43,7 +43,6 @@ void luaD_growstack (lua_State *L, int n);
43 43
44void luaD_error (lua_State *L, const char *s, int errcode); 44void luaD_error (lua_State *L, const char *s, int errcode);
45void luaD_errorobj (lua_State *L, const TObject *s, int errcode); 45void luaD_errorobj (lua_State *L, const TObject *s, int errcode);
46void luaD_runerror (lua_State *L, const char *s);
47int luaD_runprotected (lua_State *L, Pfunc f, TObject *ud); 46int luaD_runprotected (lua_State *L, Pfunc f, TObject *ud);
48 47
49 48
diff --git a/llex.c b/llex.c
index 91dd6379..90e6698b 100644
--- a/llex.c
+++ b/llex.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: llex.c,v 1.99 2002/03/08 19:25:24 roberto Exp roberto $ 2** $Id: llex.c,v 1.100 2002/05/07 17:36:56 roberto Exp roberto $
3** Lexical Analyzer 3** Lexical Analyzer
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -61,8 +61,7 @@ static void luaX_error (LexState *ls, const char *s, const char *token) {
61 lua_State *L = ls->L; 61 lua_State *L = ls->L;
62 char buff[MAXSRC]; 62 char buff[MAXSRC];
63 luaO_chunkid(buff, getstr(ls->source), MAXSRC); 63 luaO_chunkid(buff, getstr(ls->source), MAXSRC);
64 luaO_pushstr(L, "%s;\n last token read: `%s' at line %d in %s", 64 luaO_pushstr(L, "%s:%d: %s near `%s'", buff, ls->linenumber, s, token);
65 s, token, ls->linenumber, buff);
66 luaD_errorobj(L, L->top - 1, LUA_ERRSYNTAX); 65 luaD_errorobj(L, L->top - 1, LUA_ERRSYNTAX);
67} 66}
68 67
diff --git a/lmem.c b/lmem.c
index f3d4d309..99b0dafc 100644
--- a/lmem.c
+++ b/lmem.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lmem.c,v 1.53 2002/04/22 14:40:23 roberto Exp roberto $ 2** $Id: lmem.c,v 1.54 2002/05/01 20:40:42 roberto Exp roberto $
3** Interface to Memory Manager 3** Interface to Memory Manager
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -9,6 +9,7 @@
9 9
10#include "lua.h" 10#include "lua.h"
11 11
12#include "ldebug.h"
12#include "ldo.h" 13#include "ldo.h"
13#include "lmem.h" 14#include "lmem.h"
14#include "lobject.h" 15#include "lobject.h"
@@ -34,7 +35,7 @@ void *luaM_growaux (lua_State *L, void *block, int *size, int size_elems,
34 else if (*size >= limit/2) { /* cannot double it? */ 35 else if (*size >= limit/2) { /* cannot double it? */
35 if (*size < limit - MINSIZEARRAY) /* try something smaller... */ 36 if (*size < limit - MINSIZEARRAY) /* try something smaller... */
36 newsize = limit; /* still have at least MINSIZEARRAY free places */ 37 newsize = limit; /* still have at least MINSIZEARRAY free places */
37 else luaD_runerror(L, errormsg); 38 else luaG_runerror(L, errormsg);
38 } 39 }
39 newblock = luaM_realloc(L, block, 40 newblock = luaM_realloc(L, block,
40 cast(lu_mem, *size)*cast(lu_mem, size_elems), 41 cast(lu_mem, *size)*cast(lu_mem, size_elems),
@@ -53,7 +54,7 @@ void *luaM_realloc (lua_State *L, void *block, lu_mem oldsize, lu_mem size) {
53 block = NULL; 54 block = NULL;
54 } 55 }
55 else if (size >= MAX_SIZET) 56 else if (size >= MAX_SIZET)
56 luaD_runerror(L, "memory allocation error: block too big"); 57 luaG_runerror(L, "memory allocation error: block too big");
57 else { 58 else {
58 block = l_realloc(block, oldsize, size); 59 block = l_realloc(block, oldsize, size);
59 if (block == NULL) { 60 if (block == NULL) {
diff --git a/lobject.c b/lobject.c
index 96590aa5..52e81205 100644
--- a/lobject.c
+++ b/lobject.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lobject.c,v 1.78 2002/05/06 15:51:41 roberto Exp roberto $ 2** $Id: lobject.c,v 1.79 2002/05/07 17:36:56 roberto Exp roberto $
3** Some generic functions over Lua objects 3** Some generic functions over Lua objects
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -100,7 +100,8 @@ static void pushstr (lua_State *L, const char *str) {
100 100
101/* this function handles only `%d', `%c', %f, and `%s' formats */ 101/* this function handles only `%d', `%c', %f, and `%s' formats */
102const char *luaO_vpushstr (lua_State *L, const char *fmt, va_list argp) { 102const char *luaO_vpushstr (lua_State *L, const char *fmt, va_list argp) {
103 int n = 0; 103 int n = 1;
104 pushstr(L, "");
104 for (;;) { 105 for (;;) {
105 const char *e = strchr(fmt, '%'); 106 const char *e = strchr(fmt, '%');
106 if (e == NULL) break; 107 if (e == NULL) break;
@@ -150,47 +151,36 @@ const char *luaO_pushstr (lua_State *L, const char *fmt, ...) {
150} 151}
151 152
152 153
153void luaO_verror (lua_State *L, const char *fmt, ...) {
154 const char *msg;
155 va_list argp;
156 va_start(argp, fmt);
157 msg = luaO_vpushstr(L, fmt, argp);
158 va_end(argp);
159 luaD_runerror(L, msg);
160}
161
162
163void luaO_chunkid (char *out, const char *source, int bufflen) { 154void luaO_chunkid (char *out, const char *source, int bufflen) {
164 if (*source == '=') { 155 if (*source == '=') {
165 strncpy(out, source+1, bufflen); /* remove first char */ 156 strncpy(out, source+1, bufflen); /* remove first char */
166 out[bufflen-1] = '\0'; /* ensures null termination */ 157 out[bufflen-1] = '\0'; /* ensures null termination */
167 } 158 }
168 else { /* out = "file `source'", or "file `...source'" */ 159 else { /* out = "source", or "...source" */
169 if (*source == '@') { 160 if (*source == '@') {
170 int l; 161 int l;
171 source++; /* skip the `@' */ 162 source++; /* skip the `@' */
172 bufflen -= sizeof(" file `...' "); 163 bufflen -= sizeof(" `...' ");
173 l = strlen(source); 164 l = strlen(source);
174 strcpy(out, "file `"); 165 strcpy(out, "");
175 if (l>bufflen) { 166 if (l>bufflen) {
176 source += (l-bufflen); /* get last part of file name */ 167 source += (l-bufflen); /* get last part of file name */
177 strcat(out, "..."); 168 strcat(out, "...");
178 } 169 }
179 strcat(out, source); 170 strcat(out, source);
180 strcat(out, "'");
181 } 171 }
182 else { 172 else { /* out = [string "string"] */
183 int len = strcspn(source, "\n"); /* stop at first newline */ 173 int len = strcspn(source, "\n"); /* stop at first newline */
184 bufflen -= sizeof(" string \"...\" "); 174 bufflen -= sizeof(" [string \"...\"] ");
185 if (len > bufflen) len = bufflen; 175 if (len > bufflen) len = bufflen;
186 strcpy(out, "string \""); 176 strcpy(out, "[string \"");
187 if (source[len] != '\0') { /* must truncate? */ 177 if (source[len] != '\0') { /* must truncate? */
188 strncat(out, source, len); 178 strncat(out, source, len);
189 strcat(out, "..."); 179 strcat(out, "...");
190 } 180 }
191 else 181 else
192 strcat(out, source); 182 strcat(out, source);
193 strcat(out, "\""); 183 strcat(out, "\"]");
194 } 184 }
195 } 185 }
196} 186}
diff --git a/lobject.h b/lobject.h
index ad3233f6..fbf57adc 100644
--- a/lobject.h
+++ b/lobject.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lobject.h,v 1.130 2002/05/06 15:51:41 roberto Exp roberto $ 2** $Id: lobject.h,v 1.131 2002/05/07 17:36:56 roberto Exp roberto $
3** Type definitions for Lua objects 3** Type definitions for Lua objects
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -252,7 +252,6 @@ int luaO_str2d (const char *s, lua_Number *result);
252 252
253const char *luaO_vpushstr (lua_State *L, const char *fmt, va_list argp); 253const char *luaO_vpushstr (lua_State *L, const char *fmt, va_list argp);
254const char *luaO_pushstr (lua_State *L, const char *fmt, ...); 254const char *luaO_pushstr (lua_State *L, const char *fmt, ...);
255void luaO_verror (lua_State *L, const char *fmt, ...);
256void luaO_chunkid (char *out, const char *source, int len); 255void luaO_chunkid (char *out, const char *source, int len);
257 256
258 257
diff --git a/ltable.c b/ltable.c
index 546e3527..fdd15b66 100644
--- a/ltable.c
+++ b/ltable.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ltable.c,v 1.106 2002/05/08 17:34:00 roberto Exp roberto $ 2** $Id: ltable.c,v 1.107 2002/05/13 13:38:59 roberto Exp roberto $
3** Lua tables (hash) 3** Lua tables (hash)
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -25,6 +25,7 @@
25 25
26#include "lua.h" 26#include "lua.h"
27 27
28#include "ldebug.h"
28#include "ldo.h" 29#include "ldo.h"
29#include "lmem.h" 30#include "lmem.h"
30#include "lobject.h" 31#include "lobject.h"
@@ -111,7 +112,7 @@ static int luaH_index (lua_State *L, Table *t, const TObject *key) {
111 else { 112 else {
112 const TObject *v = luaH_get(t, key); 113 const TObject *v = luaH_get(t, key);
113 if (v == &luaO_nilobject) 114 if (v == &luaO_nilobject)
114 luaD_runerror(L, "invalid key for `next'"); 115 luaG_runerror(L, "invalid key for `next'");
115 i = cast(int, (cast(const lu_byte *, v) - 116 i = cast(int, (cast(const lu_byte *, v) -
116 cast(const lu_byte *, val(node(t, 0)))) / sizeof(Node)); 117 cast(const lu_byte *, val(node(t, 0)))) / sizeof(Node));
117 return i + t->sizearray; /* hash elements are numbered after array ones */ 118 return i + t->sizearray; /* hash elements are numbered after array ones */
@@ -214,7 +215,7 @@ static void setnodevector (lua_State *L, Table *t, int lsize) {
214 int i; 215 int i;
215 int size = twoto(lsize); 216 int size = twoto(lsize);
216 if (lsize > MAXBITS) 217 if (lsize > MAXBITS)
217 luaD_runerror(L, "table overflow"); 218 luaG_runerror(L, "table overflow");
218 if (lsize == 0) { /* no elements to hash part? */ 219 if (lsize == 0) { /* no elements to hash part? */
219 t->node = G(L)->dummynode; /* use common `dummynode' */ 220 t->node = G(L)->dummynode; /* use common `dummynode' */
220 lua_assert(ttype(key(t->node)) == LUA_TNIL); /* assert invariants: */ 221 lua_assert(ttype(key(t->node)) == LUA_TNIL); /* assert invariants: */
@@ -449,7 +450,7 @@ void luaH_set (lua_State *L, Table *t, const TObject *key, const TObject *val) {
449 settableval(p, val); 450 settableval(p, val);
450 } 451 }
451 else { 452 else {
452 if (ttype(key) == LUA_TNIL) luaD_runerror(L, "table index is nil"); 453 if (ttype(key) == LUA_TNIL) luaG_runerror(L, "table index is nil");
453 newkey(L, t, key, val); 454 newkey(L, t, key, val);
454 } 455 }
455 t->flags = 0; 456 t->flags = 0;
diff --git a/lua.c b/lua.c
index 7508c4aa..344b3a02 100644
--- a/lua.c
+++ b/lua.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lua.c,v 1.84 2002/04/23 14:59:22 roberto Exp roberto $ 2** $Id: lua.c,v 1.85 2002/05/01 20:40:42 roberto Exp roberto $
3** Lua stand-alone interpreter 3** Lua stand-alone interpreter
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -71,7 +71,7 @@ static void report (int status) {
71 else { 71 else {
72 const char *msg = lua_tostring(L, -1); 72 const char *msg = lua_tostring(L, -1);
73 if (msg == NULL) msg = "(no message)"; 73 if (msg == NULL) msg = "(no message)";
74 fprintf(stderr, "error: %s\n", msg); 74 fprintf(stderr, "%s\n", msg);
75 lua_pop(L, 1); 75 lua_pop(L, 1);
76 } 76 }
77} 77}
@@ -152,8 +152,8 @@ static int file_input (const char *name) {
152} 152}
153 153
154 154
155static int dostring (const char *s) { 155static int dostring (const char *s, const char *name) {
156 int status = lua_loadbuffer(L, s, strlen(s), s); 156 int status = lua_loadbuffer(L, s, strlen(s), name);
157 if (status == 0) status = lcall(1); 157 if (status == 0) status = lcall(1);
158 report(status); 158 report(status);
159 return status; 159 return status;
@@ -198,7 +198,7 @@ static const char *get_prompt (int firstline) {
198 198
199static int incomplete (int status) { 199static int incomplete (int status) {
200 if (status == LUA_ERRSYNTAX && 200 if (status == LUA_ERRSYNTAX &&
201 strstr(lua_tostring(L, -1), "last token read: `<eof>'") != NULL) { 201 strstr(lua_tostring(L, -1), "near `<eof>'") != NULL) {
202 lua_pop(L, 1); 202 lua_pop(L, 1);
203 return 1; 203 return 1;
204 } 204 }
@@ -289,7 +289,7 @@ static int handle_argv (char *argv[], int *toclose) {
289 print_usage(); 289 print_usage();
290 return EXIT_FAILURE; 290 return EXIT_FAILURE;
291 } 291 }
292 if (dostring(argv[i]) != 0) { 292 if (dostring(argv[i], "=prog. argument") != 0) {
293 fprintf(stderr, "%s: error running argument `%.99s'\n", 293 fprintf(stderr, "%s: error running argument `%.99s'\n",
294 LUA_PROGNAME, argv[i]); 294 LUA_PROGNAME, argv[i]);
295 return EXIT_FAILURE; 295 return EXIT_FAILURE;
@@ -340,6 +340,16 @@ static void openstdlibs (lua_State *l) {
340} 340}
341 341
342 342
343static int handle_luainit (void) {
344 const char *init = getenv("LUA_INIT");
345 if (init == NULL) return 0; /* status OK */
346 else if (init[0] == '@')
347 return file_input(init+1);
348 else
349 return dostring(init, "=LUA_INIT");
350}
351
352
343int main (int argc, char *argv[]) { 353int main (int argc, char *argv[]) {
344 int status; 354 int status;
345 int toclose = 0; 355 int toclose = 0;
@@ -347,6 +357,8 @@ int main (int argc, char *argv[]) {
347 L = lua_open(); /* create state */ 357 L = lua_open(); /* create state */
348 LUA_USERINIT(L); /* open libraries */ 358 LUA_USERINIT(L); /* open libraries */
349 register_getargs(argv); /* create `getargs' function */ 359 register_getargs(argv); /* create `getargs' function */
360 status = handle_luainit();
361 if (status != 0) return status;
350 status = handle_argv(argv+1, &toclose); 362 status = handle_argv(argv+1, &toclose);
351 if (toclose) 363 if (toclose)
352 lua_close(L); 364 lua_close(L);
diff --git a/lundump.c b/lundump.c
index b9b7b505..78f36ad8 100644
--- a/lundump.c
+++ b/lundump.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lundump.c,v 1.45 2002/03/25 17:47:14 roberto Exp roberto $ 2** $Id: lundump.c,v 1.46 2002/05/07 17:36:56 roberto Exp roberto $
3** load pre-compiled Lua chunks 3** load pre-compiled Lua chunks
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -27,7 +27,7 @@ static const char* ZNAME (ZIO* Z)
27 27
28static void unexpectedEOZ (lua_State* L, ZIO* Z) 28static void unexpectedEOZ (lua_State* L, ZIO* Z)
29{ 29{
30 luaO_verror(L,"unexpected end of file in `%s'",ZNAME(Z)); 30 luaG_runerror(L,"unexpected end of file in `%s'",ZNAME(Z));
31} 31}
32 32
33static int ezgetc (lua_State* L, ZIO* Z) 33static int ezgetc (lua_State* L, ZIO* Z)
@@ -157,7 +157,7 @@ static void LoadConstants (lua_State* L, Proto* f, ZIO* Z, int swap)
157 tsvalue(o)=LoadString(L,Z,swap); 157 tsvalue(o)=LoadString(L,Z,swap);
158 break; 158 break;
159 default: 159 default:
160 luaO_verror(L,"bad constant type (%d) in `%s'",ttype(o),ZNAME(Z)); 160 luaG_runerror(L,"bad constant type (%d) in `%s'",ttype(o),ZNAME(Z));
161 break; 161 break;
162 } 162 }
163 } 163 }
@@ -181,7 +181,7 @@ static Proto* LoadFunction (lua_State* L, TString* p, ZIO* Z, int swap)
181 LoadConstants(L,f,Z,swap); 181 LoadConstants(L,f,Z,swap);
182 LoadCode(L,f,Z,swap); 182 LoadCode(L,f,Z,swap);
183#ifndef TRUST_BINARIES 183#ifndef TRUST_BINARIES
184 if (!luaG_checkcode(f)) luaO_verror(L,"bad code in `%s'",ZNAME(Z)); 184 if (!luaG_checkcode(f)) luaG_runerror(L,"bad code in `%s'",ZNAME(Z));
185#endif 185#endif
186 return f; 186 return f;
187} 187}
@@ -191,14 +191,14 @@ static void LoadSignature (lua_State* L, ZIO* Z)
191 const char* s=LUA_SIGNATURE; 191 const char* s=LUA_SIGNATURE;
192 while (*s!=0 && ezgetc(L,Z)==*s) 192 while (*s!=0 && ezgetc(L,Z)==*s)
193 ++s; 193 ++s;
194 if (*s!=0) luaO_verror(L,"bad signature in `%s'",ZNAME(Z)); 194 if (*s!=0) luaG_runerror(L,"bad signature in `%s'",ZNAME(Z));
195} 195}
196 196
197static void TestSize (lua_State* L, int s, const char* what, ZIO* Z) 197static void TestSize (lua_State* L, int s, const char* what, ZIO* Z)
198{ 198{
199 int r=LoadByte(L,Z); 199 int r=LoadByte(L,Z);
200 if (r!=s) 200 if (r!=s)
201 luaO_verror(L,"virtual machine mismatch in `%s':\n" 201 luaG_runerror(L,"virtual machine mismatch in `%s':\n"
202 " size of %.20s is %d but read %d",ZNAME(Z),what,s,r); 202 " size of %.20s is %d but read %d",ZNAME(Z),what,s,r);
203} 203}
204 204
@@ -212,11 +212,11 @@ static int LoadHeader (lua_State* L, ZIO* Z)
212 LoadSignature(L,Z); 212 LoadSignature(L,Z);
213 version=LoadByte(L,Z); 213 version=LoadByte(L,Z);
214 if (version>VERSION) 214 if (version>VERSION)
215 luaO_verror(L,"`%s' too new:\n" 215 luaG_runerror(L,"`%s' too new:\n"
216 " read version %d.%d; expected at most %d.%d", 216 " read version %d.%d; expected at most %d.%d",
217 ZNAME(Z),V(version),V(VERSION)); 217 ZNAME(Z),V(version),V(VERSION));
218 if (version<VERSION0) /* check last major change */ 218 if (version<VERSION0) /* check last major change */
219 luaO_verror(L,"`%s' too old:\n" 219 luaG_runerror(L,"`%s' too old:\n"
220 " read version %d.%d; expected at least %d.%d", 220 " read version %d.%d; expected at least %d.%d",
221 ZNAME(Z),V(version),V(VERSION)); 221 ZNAME(Z),V(version),V(VERSION));
222 swap=(luaU_endianness()!=LoadByte(L,Z)); /* need to swap bytes? */ 222 swap=(luaU_endianness()!=LoadByte(L,Z)); /* need to swap bytes? */
@@ -230,7 +230,7 @@ static int LoadHeader (lua_State* L, ZIO* Z)
230 TESTSIZE(sizeof(lua_Number), "number"); 230 TESTSIZE(sizeof(lua_Number), "number");
231 x=LoadNumber(L,Z,swap); 231 x=LoadNumber(L,Z,swap);
232 if ((long)x!=(long)tx) /* disregard errors in last bits of fraction */ 232 if ((long)x!=(long)tx) /* disregard errors in last bits of fraction */
233 luaO_verror(L,"unknown number format in `%s':\n" 233 luaG_runerror(L,"unknown number format in `%s':\n"
234 " read " LUA_NUMBER_FMT "; expected " LUA_NUMBER_FMT, 234 " read " LUA_NUMBER_FMT "; expected " LUA_NUMBER_FMT,
235 ZNAME(Z),x,tx); 235 ZNAME(Z),x,tx);
236 return swap; 236 return swap;
@@ -248,7 +248,7 @@ Proto* luaU_undump (lua_State* L, ZIO* Z)
248{ 248{
249 Proto* f=LoadChunk(L,Z); 249 Proto* f=LoadChunk(L,Z);
250 if (zgetc(Z)!=EOZ) 250 if (zgetc(Z)!=EOZ)
251 luaO_verror(L,"`%s' apparently contains more than one chunk",ZNAME(Z)); 251 luaG_runerror(L,"`%s' apparently contains more than one chunk",ZNAME(Z));
252 return f; 252 return f;
253} 253}
254 254
diff --git a/lvm.c b/lvm.c
index ac0cca9d..c5f3e88d 100644
--- a/lvm.c
+++ b/lvm.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lvm.c,v 1.230 2002/05/09 14:14:34 roberto Exp roberto $ 2** $Id: lvm.c,v 1.231 2002/05/13 13:09:00 roberto Exp roberto $
3** Lua virtual machine 3** Lua virtual machine
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -134,7 +134,7 @@ void luaV_gettable (lua_State *L, const TObject *t, TObject *key, StkId res) {
134 if (ttype(tm) == LUA_TFUNCTION) 134 if (ttype(tm) == LUA_TFUNCTION)
135 callTMres(L, tm, t, key, res); 135 callTMres(L, tm, t, key, res);
136 else { 136 else {
137 if (++loop == MAXTAGLOOP) luaD_runerror(L, "loop in gettable"); 137 if (++loop == MAXTAGLOOP) luaG_runerror(L, "loop in gettable");
138 t = tm; 138 t = tm;
139 goto init; /* return luaV_gettable(L, tm, key, res); */ 139 goto init; /* return luaV_gettable(L, tm, key, res); */
140 } 140 }
@@ -164,7 +164,7 @@ void luaV_settable (lua_State *L, const TObject *t, TObject *key, StkId val) {
164 if (ttype(tm) == LUA_TFUNCTION) 164 if (ttype(tm) == LUA_TFUNCTION)
165 callTM(L, tm, t, key, val); 165 callTM(L, tm, t, key, val);
166 else { 166 else {
167 if (++loop == MAXTAGLOOP) luaD_runerror(L, "loop in settable"); 167 if (++loop == MAXTAGLOOP) luaG_runerror(L, "loop in settable");
168 t = tm; 168 t = tm;
169 goto init; /* luaV_settable(L, tm, key, val); */ 169 goto init; /* luaV_settable(L, tm, key, val); */
170 } 170 }
@@ -251,7 +251,7 @@ void luaV_strconc (lua_State *L, int total, int last) {
251 tl += tsvalue(top-n-1)->tsv.len; 251 tl += tsvalue(top-n-1)->tsv.len;
252 n++; 252 n++;
253 } 253 }
254 if (tl > MAX_SIZET) luaD_runerror(L, "string size overflow"); 254 if (tl > MAX_SIZET) luaG_runerror(L, "string size overflow");
255 buffer = luaO_openspace(L, tl, char); 255 buffer = luaO_openspace(L, tl, char);
256 tl = 0; 256 tl = 0;
257 for (i=n; i>0; i--) { /* concat all strings */ 257 for (i=n; i>0; i--) { /* concat all strings */
@@ -276,7 +276,7 @@ static void powOp (lua_State *L, StkId ra, StkId rb, StkId rc) {
276 setsvalue(&o, luaS_newliteral(L, "pow")); 276 setsvalue(&o, luaS_newliteral(L, "pow"));
277 luaV_gettable(L, gt(L), &o, &f); 277 luaV_gettable(L, gt(L), &o, &f);
278 if (ttype(&f) != LUA_TFUNCTION) 278 if (ttype(&f) != LUA_TFUNCTION)
279 luaD_runerror(L, "`pow' (for `^' operator) is not a function"); 279 luaG_runerror(L, "`pow' (for `^' operator) is not a function");
280 callTMres(L, &f, b, c, ra); 280 callTMres(L, &f, b, c, ra);
281 } 281 }
282 else 282 else
@@ -527,11 +527,11 @@ StkId luaV_execute (lua_State *L) {
527 const TObject *plimit = ra+1; 527 const TObject *plimit = ra+1;
528 const TObject *pstep = ra+2; 528 const TObject *pstep = ra+2;
529 if (ttype(ra) != LUA_TNUMBER) 529 if (ttype(ra) != LUA_TNUMBER)
530 luaD_runerror(L, "`for' initial value must be a number"); 530 luaG_runerror(L, "`for' initial value must be a number");
531 if (!tonumber(plimit, ra+1)) 531 if (!tonumber(plimit, ra+1))
532 luaD_runerror(L, "`for' limit must be a number"); 532 luaG_runerror(L, "`for' limit must be a number");
533 if (!tonumber(pstep, ra+2)) 533 if (!tonumber(pstep, ra+2))
534 luaD_runerror(L, "`for' step must be a number"); 534 luaG_runerror(L, "`for' step must be a number");
535 step = nvalue(pstep); 535 step = nvalue(pstep);
536 index = nvalue(ra) + step; /* increment index */ 536 index = nvalue(ra) + step; /* increment index */
537 limit = nvalue(plimit); 537 limit = nvalue(plimit);