summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lapi.c39
-rw-r--r--lapi.h4
-rw-r--r--lbuffer.c8
-rw-r--r--lbuiltin.c53
-rw-r--r--lbuiltin.h51
-rw-r--r--lcode.c4
-rw-r--r--ldblib.c8
-rw-r--r--ldebug.c4
-rw-r--r--ldo.c10
-rw-r--r--lfunc.c4
-rw-r--r--liolib.c13
-rw-r--r--llex.c18
-rw-r--r--llex.h11
-rw-r--r--lmem.c17
-rw-r--r--lobject.c4
-rw-r--r--lobject.h35
-rw-r--r--lopcodes.h15
-rw-r--r--lparser.c10
-rw-r--r--lparser.h12
-rw-r--r--lref.c9
-rw-r--r--lstring.c4
-rw-r--r--lstring.h6
-rw-r--r--lstrlib.c46
-rw-r--r--ltable.c4
-rw-r--r--ltm.c4
-rw-r--r--ltm.h7
-rw-r--r--lua.c24
-rw-r--r--lundump.c118
-rw-r--r--lundump.h3
-rw-r--r--lvm.c16
-rw-r--r--lvm.h6
-rw-r--r--lzio.c6
32 files changed, 280 insertions, 293 deletions
diff --git a/lapi.c b/lapi.c
index 01579561..d915696b 100644
--- a/lapi.c
+++ b/lapi.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lapi.c,v 1.71 2000/02/08 16:34:31 roberto Exp roberto $ 2** $Id: lapi.c,v 1.72 2000/02/22 17:54:16 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*/
@@ -41,9 +41,10 @@ const TObject *luaA_protovalue (const TObject *o) {
41} 41}
42 42
43 43
44void luaA_checkCparams (lua_State *L, int nParams) { 44void luaA_checkCargs (lua_State *L, int nargs) {
45 if (nParams > L->top-L->Cstack.base) 45 if (nargs > L->top-L->Cstack.base)
46 lua_error(L, "API error - wrong number of arguments in C2lua stack"); 46 luaL_verror(L, "Lua API error - "
47 "expected at least %d arguments in C2lua stack", nargs);
47} 48}
48 49
49 50
@@ -70,7 +71,7 @@ static void top2LC (lua_State *L, int n) {
70 71
71 72
72lua_Object lua_pop (lua_State *L) { 73lua_Object lua_pop (lua_State *L) {
73 luaA_checkCparams(L, 1); 74 luaA_checkCargs(L, 1);
74 return luaA_putObjectOnTop(L); 75 return luaA_putObjectOnTop(L);
75} 76}
76 77
@@ -103,10 +104,10 @@ lua_Object lua_gettagmethod (lua_State *L, int tag, const char *event) {
103 104
104lua_Object lua_settagmethod (lua_State *L, int tag, const char *event) { 105lua_Object lua_settagmethod (lua_State *L, int tag, const char *event) {
105 TObject *method; 106 TObject *method;
106 luaA_checkCparams(L, 1); 107 luaA_checkCargs(L, 1);
107 method = L->top-1; 108 method = L->top-1;
108 if ((ttype(method) != LUA_T_NIL) && (*lua_type(L, method) != 'f')) 109 if ((ttype(method) != LUA_T_NIL) && (*lua_type(L, method) != 'f'))
109 lua_error(L, "API error - tag method must be a function or nil"); 110 lua_error(L, "Lua API error - tag method must be a function or nil");
110 luaT_settagmethod(L, tag, event, method); 111 luaT_settagmethod(L, tag, event, method);
111 return luaA_putObjectOnTop(L); 112 return luaA_putObjectOnTop(L);
112} 113}
@@ -114,7 +115,7 @@ lua_Object lua_settagmethod (lua_State *L, int tag, const char *event) {
114 115
115lua_Object lua_seterrormethod (lua_State *L) { 116lua_Object lua_seterrormethod (lua_State *L) {
116 lua_Object temp; 117 lua_Object temp;
117 luaA_checkCparams(L, 1); 118 luaA_checkCargs(L, 1);
118 temp = lua_getglobal(L, "_ERRORMESSAGE"); 119 temp = lua_getglobal(L, "_ERRORMESSAGE");
119 lua_setglobal(L, "_ERRORMESSAGE"); 120 lua_setglobal(L, "_ERRORMESSAGE");
120 return temp; 121 return temp;
@@ -122,7 +123,7 @@ lua_Object lua_seterrormethod (lua_State *L) {
122 123
123 124
124lua_Object lua_gettable (lua_State *L) { 125lua_Object lua_gettable (lua_State *L) {
125 luaA_checkCparams(L, 2); 126 luaA_checkCargs(L, 2);
126 luaV_gettable(L, L->top--); 127 luaV_gettable(L, L->top--);
127 return luaA_putObjectOnTop(L); 128 return luaA_putObjectOnTop(L);
128} 129}
@@ -130,7 +131,7 @@ lua_Object lua_gettable (lua_State *L) {
130 131
131lua_Object lua_rawgettable (lua_State *L) { 132lua_Object lua_rawgettable (lua_State *L) {
132 lua_Object res; 133 lua_Object res;
133 luaA_checkCparams(L, 2); 134 luaA_checkCargs(L, 2);
134 if (ttype(L->top-2) != LUA_T_ARRAY) 135 if (ttype(L->top-2) != LUA_T_ARRAY)
135 lua_error(L, "indexed expression not a table in rawgettable"); 136 lua_error(L, "indexed expression not a table in rawgettable");
136 res = luaA_putluaObject(L, luaH_get(L, avalue(L->top-2), L->top-1)); 137 res = luaA_putluaObject(L, luaH_get(L, avalue(L->top-2), L->top-1));
@@ -141,7 +142,7 @@ lua_Object lua_rawgettable (lua_State *L) {
141 142
142void lua_settable (lua_State *L) { 143void lua_settable (lua_State *L) {
143 StkId top; 144 StkId top;
144 luaA_checkCparams(L, 3); 145 luaA_checkCargs(L, 3);
145 top = L->top; 146 top = L->top;
146 luaV_settable(L, top-3, top); 147 luaV_settable(L, top-3, top);
147 L->top = top-3; /* pop table, index, and value */ 148 L->top = top-3; /* pop table, index, and value */
@@ -149,7 +150,7 @@ void lua_settable (lua_State *L) {
149 150
150 151
151void lua_rawsettable (lua_State *L) { 152void lua_rawsettable (lua_State *L) {
152 luaA_checkCparams(L, 3); 153 luaA_checkCargs(L, 3);
153 luaV_rawsettable(L, L->top-3); 154 luaV_rawsettable(L, L->top-3);
154} 155}
155 156
@@ -176,14 +177,14 @@ lua_Object lua_rawgetglobal (lua_State *L, const char *name) {
176 177
177 178
178void lua_setglobal (lua_State *L, const char *name) { 179void lua_setglobal (lua_State *L, const char *name) {
179 luaA_checkCparams(L, 1); 180 luaA_checkCargs(L, 1);
180 luaV_setglobal(L, luaS_assertglobalbyname(L, name), L->top--); 181 luaV_setglobal(L, luaS_assertglobalbyname(L, name), L->top--);
181} 182}
182 183
183 184
184void lua_rawsetglobal (lua_State *L, const char *name) { 185void lua_rawsetglobal (lua_State *L, const char *name) {
185 GlobalVar *gv = luaS_assertglobalbyname(L, name); 186 GlobalVar *gv = luaS_assertglobalbyname(L, name);
186 luaA_checkCparams(L, 1); 187 luaA_checkCargs(L, 1);
187 gv->value = *(--L->top); 188 gv->value = *(--L->top);
188} 189}
189 190
@@ -296,8 +297,8 @@ void lua_pushstring (lua_State *L, const char *s) {
296 297
297void lua_pushcclosure (lua_State *L, lua_CFunction fn, int n) { 298void lua_pushcclosure (lua_State *L, lua_CFunction fn, int n) {
298 if (fn == NULL) 299 if (fn == NULL)
299 lua_error(L, "API error - attempt to push a NULL Cfunction"); 300 lua_error(L, "Lua API error - attempt to push a NULL Cfunction");
300 luaA_checkCparams(L, n); 301 luaA_checkCargs(L, n);
301 ttype(L->top) = LUA_T_CPROTO; 302 ttype(L->top) = LUA_T_CPROTO;
302 fvalue(L->top) = fn; 303 fvalue(L->top) = fn;
303 incr_top; 304 incr_top;
@@ -321,7 +322,7 @@ void luaA_pushobject (lua_State *L, const TObject *o) {
321 322
322void lua_pushobject (lua_State *L, lua_Object o) { 323void lua_pushobject (lua_State *L, lua_Object o) {
323 if (o == LUA_NOOBJECT) 324 if (o == LUA_NOOBJECT)
324 lua_error(L, "API error - attempt to push a NOOBJECT"); 325 lua_error(L, "Lua API error - attempt to push a NOOBJECT");
325 *L->top = *o; 326 *L->top = *o;
326 incr_top; 327 incr_top;
327} 328}
@@ -339,7 +340,7 @@ int lua_tag (lua_State *L, lua_Object o) {
339 340
340 341
341void lua_settag (lua_State *L, int tag) { 342void lua_settag (lua_State *L, int tag) {
342 luaA_checkCparams(L, 1); 343 luaA_checkCargs(L, 1);
343 luaT_realtag(L, tag); 344 luaT_realtag(L, tag);
344 switch (ttype(L->top-1)) { 345 switch (ttype(L->top-1)) {
345 case LUA_T_ARRAY: 346 case LUA_T_ARRAY:
@@ -406,7 +407,7 @@ int luaA_next (lua_State *L, const Hash *t, int i) {
406 407
407int lua_next (lua_State *L, lua_Object t, int i) { 408int lua_next (lua_State *L, lua_Object t, int i) {
408 if (ttype(t) != LUA_T_ARRAY) 409 if (ttype(t) != LUA_T_ARRAY)
409 lua_error(L, "API error - object is not a table in `lua_next'"); 410 lua_error(L, "Lua API error - object is not a table in `lua_next'");
410 i = luaA_next(L, avalue(t), i); 411 i = luaA_next(L, avalue(t), i);
411 top2LC(L, (i==0) ? 0 : 2); 412 top2LC(L, (i==0) ? 0 : 2);
412 return i; 413 return i;
diff --git a/lapi.h b/lapi.h
index 469fb272..5fb3e90d 100644
--- a/lapi.h
+++ b/lapi.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lapi.h,v 1.12 1999/12/23 18:19:57 roberto Exp roberto $ 2** $Id: lapi.h,v 1.13 2000/01/19 12:00:45 roberto Exp roberto $
3** Auxiliary functions from Lua API 3** Auxiliary functions from Lua API
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -11,7 +11,7 @@
11#include "lobject.h" 11#include "lobject.h"
12 12
13 13
14void luaA_checkCparams (lua_State *L, int nParams); 14void luaA_checkCargs (lua_State *L, int nargs);
15const TObject *luaA_protovalue (const TObject *o); 15const TObject *luaA_protovalue (const TObject *o);
16void luaA_pushobject (lua_State *L, const TObject *o); 16void luaA_pushobject (lua_State *L, const TObject *o);
17GlobalVar *luaA_nextvar (lua_State *L, TaggedString *g); 17GlobalVar *luaA_nextvar (lua_State *L, TaggedString *g);
diff --git a/lbuffer.c b/lbuffer.c
index 2525ea02..f584936d 100644
--- a/lbuffer.c
+++ b/lbuffer.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lbuffer.c,v 1.10 1999/11/10 15:40:46 roberto Exp roberto $ 2** $Id: lbuffer.c,v 1.11 1999/11/22 13:12:07 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*/
@@ -19,10 +19,14 @@
19-------------------------------------------------------*/ 19-------------------------------------------------------*/
20 20
21 21
22/*
23** amount of extra space (pre)allocated when buffer is reallocated
24*/
22#define EXTRABUFF 32 25#define EXTRABUFF 32
23 26
24 27
25#define openspace(L, size) if (L->Mbuffnext+(size) > L->Mbuffsize) Openspace(L, size) 28#define openspace(L, size) if (L->Mbuffnext+(size) > L->Mbuffsize) \
29 Openspace(L, size)
26 30
27static void Openspace (lua_State *L, int size) { 31static void Openspace (lua_State *L, int size) {
28 L->Mbuffsize = (L->Mbuffnext+size+EXTRABUFF)*2; 32 L->Mbuffsize = (L->Mbuffnext+size+EXTRABUFF)*2;
diff --git a/lbuiltin.c b/lbuiltin.c
index 7e0c832c..3a57e814 100644
--- a/lbuiltin.c
+++ b/lbuiltin.c
@@ -1,10 +1,19 @@
1/* 1/*
2** $Id: lbuiltin.c,v 1.92 2000/01/19 16:50:30 roberto Exp roberto $ 2** $Id: lbuiltin.c,v 1.93 2000/02/22 18:12:46 roberto Exp roberto $
3** Built-in functions 3** Built-in functions
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
6 6
7 7
8/*
9** =========================================================================
10** All built-in functions are public (i.e. not static) and are named luaB_f,
11** where f is the function name in Lua. So, if you do not need all these
12** functions, you may register manually only the ones that you need.
13** =========================================================================
14*/
15
16
8#include <ctype.h> 17#include <ctype.h>
9#include <stdio.h> 18#include <stdio.h>
10#include <stdlib.h> 19#include <stdlib.h>
@@ -91,7 +100,7 @@ static Hash *gettable (lua_State *L, int arg) {
91 100
92 101
93/* 102/*
94** If your system does not support "stderr", redefine this function, or 103** If your system does not support `stderr', redefine this function, or
95** redefine _ERRORMESSAGE so that it won't need _ALERT. 104** redefine _ERRORMESSAGE so that it won't need _ALERT.
96*/ 105*/
97void luaB__ALERT (lua_State *L) { 106void luaB__ALERT (lua_State *L) {
@@ -116,9 +125,9 @@ void luaB__ERRORMESSAGE (lua_State *L) {
116 125
117 126
118/* 127/*
119** If your system does not support "stdout", you can just remove this function. 128** If your system does not support `stdout', you can just remove this function.
120** If you need, you can define your own "print" function, following this 129** If you need, you can define your own `print' function, following this
121** model but changing "fputs" to put the strings at a proper place 130** model but changing `fputs' to put the strings at a proper place
122** (a console window or a log file, for instance). 131** (a console window or a log file, for instance).
123*/ 132*/
124#ifndef MAXPRINT 133#ifndef MAXPRINT
@@ -174,17 +183,17 @@ void luaB_error (lua_State *L) {
174} 183}
175 184
176void luaB_setglobal (lua_State *L) { 185void luaB_setglobal (lua_State *L) {
177 const char *n = luaL_check_string(L, 1); 186 const char *name = luaL_check_string(L, 1);
178 lua_Object value = luaL_nonnullarg(L, 2); 187 lua_Object value = luaL_nonnullarg(L, 2);
179 lua_pushobject(L, value); 188 lua_pushobject(L, value);
180 lua_setglobal(L, n); 189 lua_setglobal(L, name);
181} 190}
182 191
183void luaB_rawsetglobal (lua_State *L) { 192void luaB_rawsetglobal (lua_State *L) {
184 const char *n = luaL_check_string(L, 1); 193 const char *name = luaL_check_string(L, 1);
185 lua_Object value = luaL_nonnullarg(L, 2); 194 lua_Object value = luaL_nonnullarg(L, 2);
186 lua_pushobject(L, value); 195 lua_pushobject(L, value);
187 lua_rawsetglobal(L, n); 196 lua_rawsetglobal(L, name);
188} 197}
189 198
190void luaB_getglobal (lua_State *L) { 199void luaB_getglobal (lua_State *L) {
@@ -236,7 +245,7 @@ void luaB_settagmethod (lua_State *L) {
236 "function or nil expected"); 245 "function or nil expected");
237#ifndef LUA_COMPAT_GC 246#ifndef LUA_COMPAT_GC
238 if (strcmp(event, "gc") == 0 && tag != LUA_T_NIL) 247 if (strcmp(event, "gc") == 0 && tag != LUA_T_NIL)
239 lua_error(L, "cannot set this tag method from Lua"); 248 lua_error(L, "cannot set this `gc' tag method from Lua");
240#endif 249#endif
241 lua_pushobject(L, nf); 250 lua_pushobject(L, nf);
242 lua_pushobject(L, lua_settagmethod(L, tag, event)); 251 lua_pushobject(L, lua_settagmethod(L, tag, event));
@@ -325,7 +334,7 @@ void luaB_call (lua_State *L) {
325 return; /* return nil to signal the error */ 334 return; /* return nil to signal the error */
326 } 335 }
327 else 336 else
328 lua_error(L, NULL); 337 lua_error(L, NULL); /* propagate error without additional messages */
329 } 338 }
330 else { /* no errors */ 339 else { /* no errors */
331 if (strchr(options, 'p')) { /* pack results? */ 340 if (strchr(options, 'p')) { /* pack results? */
@@ -340,14 +349,14 @@ void luaB_call (lua_State *L) {
340 349
341void luaB_nextvar (lua_State *L) { 350void luaB_nextvar (lua_State *L) {
342 lua_Object o = luaL_nonnullarg(L, 1); 351 lua_Object o = luaL_nonnullarg(L, 1);
343 TaggedString *g; 352 TaggedString *name;
344 if (ttype(o) == LUA_T_NIL) 353 if (ttype(o) == LUA_T_NIL)
345 g = NULL; 354 name = NULL;
346 else { 355 else {
347 luaL_arg_check(L, ttype(o) == LUA_T_STRING, 1, "variable name expected"); 356 luaL_arg_check(L, ttype(o) == LUA_T_STRING, 1, "variable name expected");
348 g = tsvalue(o); 357 name = tsvalue(o);
349 } 358 }
350 if (!luaA_nextvar(L, g)) 359 if (!luaA_nextvar(L, name))
351 lua_pushnil(L); 360 lua_pushnil(L);
352} 361}
353 362
@@ -355,7 +364,7 @@ void luaB_nextvar (lua_State *L) {
355void luaB_next (lua_State *L) { 364void luaB_next (lua_State *L) {
356 const Hash *a = gettable(L, 1); 365 const Hash *a = gettable(L, 1);
357 lua_Object k = luaL_nonnullarg(L, 2); 366 lua_Object k = luaL_nonnullarg(L, 2);
358 int i; /* will get first element after `i' */ 367 int i; /* `luaA_next' gets first element after `i' */
359 if (ttype(k) == LUA_T_NIL) 368 if (ttype(k) == LUA_T_NIL)
360 i = 0; /* get first */ 369 i = 0; /* get first */
361 else { 370 else {
@@ -390,7 +399,8 @@ void luaB_tostring (lua_State *L) {
390 sprintf(buff, "function: %p", o->value.f); 399 sprintf(buff, "function: %p", o->value.f);
391 break; 400 break;
392 case LUA_T_USERDATA: 401 case LUA_T_USERDATA:
393 sprintf(buff, "userdata: %p", o->value.ts->u.d.value); 402 sprintf(buff, "userdata: %p(%d)", o->value.ts->u.d.value,
403 o->value.ts->u.d.tag);
394 break; 404 break;
395 case LUA_T_NIL: 405 case LUA_T_NIL:
396 lua_pushstring(L, "nil"); 406 lua_pushstring(L, "nil");
@@ -435,7 +445,7 @@ void luaB_foreachi (lua_State *L) {
435 luaD_call(L, L->top-3, 1); 445 luaD_call(L, L->top-3, 1);
436 if (ttype(L->top-1) != LUA_T_NIL) 446 if (ttype(L->top-1) != LUA_T_NIL)
437 return; 447 return;
438 L->top--; 448 L->top--; /* remove nil result */
439 } 449 }
440} 450}
441 451
@@ -499,7 +509,7 @@ void luaB_tinsert (lua_State *L) {
499 pos = n+1; 509 pos = n+1;
500 } 510 }
501 luaV_setn(L, a, n+1); /* a.n = n+1 */ 511 luaV_setn(L, a, n+1); /* a.n = n+1 */
502 for ( ;n>=pos; n--) 512 for (; n>=pos; n--)
503 luaH_move(L, a, n, n+1); /* a[n+1] = a[n] */ 513 luaH_move(L, a, n, n+1); /* a[n+1] = a[n] */
504 luaH_setint(L, a, pos, v); /* a[pos] = v */ 514 luaH_setint(L, a, pos, v); /* a[pos] = v */
505} 515}
@@ -521,6 +531,7 @@ void luaB_tremove (lua_State *L) {
521/* 531/*
522** {====================================================== 532** {======================================================
523** Quicksort 533** Quicksort
534** (based on `Algorithms in MODULA-3', Robert Sedgewick; Addison-Wesley, 1993.)
524*/ 535*/
525 536
526static void swap (lua_State *L, Hash *a, int i, int j) { 537static void swap (lua_State *L, Hash *a, int i, int j) {
@@ -602,7 +613,7 @@ void luaB_sort (lua_State *L) {
602 lua_Object func = lua_getparam(L, 2); 613 lua_Object func = lua_getparam(L, 2);
603 luaL_arg_check(L, func == LUA_NOOBJECT || lua_isfunction(L, func), 2, 614 luaL_arg_check(L, func == LUA_NOOBJECT || lua_isfunction(L, func), 2,
604 "function expected"); 615 "function expected");
605 luaD_checkstack(L, 4); /* for Pivot, f, a, b (sort_comp) */ 616 luaD_checkstack(L, 4); /* for pivot, f, a, b (sort_comp) */
606 auxsort(L, a, 1, n, func); 617 auxsort(L, a, 1, n, func);
607 lua_pushobject(L, t); 618 lua_pushobject(L, t);
608} 619}
@@ -640,7 +651,7 @@ static const struct luaL_reg builtin_funcs[] = {
640 {"tonumber", luaB_tonumber}, 651 {"tonumber", luaB_tonumber},
641 {"tostring", luaB_tostring}, 652 {"tostring", luaB_tostring},
642 {"type", luaB_type}, 653 {"type", luaB_type},
643 /* "Extra" functions */ 654/* "Extra" functions */
644 {"assert", luaB_assert}, 655 {"assert", luaB_assert},
645 {"foreach", luaB_foreach}, 656 {"foreach", luaB_foreach},
646 {"foreachi", luaB_foreachi}, 657 {"foreachi", luaB_foreachi},
diff --git a/lbuiltin.h b/lbuiltin.h
index 565cd3ac..031bcd82 100644
--- a/lbuiltin.h
+++ b/lbuiltin.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lbuiltin.h,v 1.4 1999/12/27 17:33:22 roberto Exp roberto $ 2** $Id: lbuiltin.h,v 1.5 1999/12/28 19:23:41 roberto Exp roberto $
3** Built-in functions 3** Built-in functions
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -11,39 +11,38 @@
11 11
12void luaB__ALERT (lua_State *L); 12void luaB__ALERT (lua_State *L);
13void luaB__ERRORMESSAGE (lua_State *L); 13void luaB__ERRORMESSAGE (lua_State *L);
14void luaB_print (lua_State *L); 14void luaB_assert (lua_State *L);
15void luaB_tonumber (lua_State *L); 15void luaB_call (lua_State *L);
16void luaB_collectgarbage (lua_State *L);
17void luaB_copytagmethods (lua_State *L);
18void luaB_dofile (lua_State *L);
19void luaB_dostring (lua_State *L);
16void luaB_error (lua_State *L); 20void luaB_error (lua_State *L);
17void luaB_setglobal (lua_State *L); 21void luaB_foreach (lua_State *L);
18void luaB_rawsetglobal (lua_State *L); 22void luaB_foreachi (lua_State *L);
23void luaB_foreachvar (lua_State *L);
19void luaB_getglobal (lua_State *L); 24void luaB_getglobal (lua_State *L);
20void luaB_rawgetglobal (lua_State *L); 25void luaB_getn (lua_State *L);
21void luaB_tag (lua_State *L); 26void luaB_gettagmethod (lua_State *L);
22void luaB_settag (lua_State *L);
23void luaB_newtag (lua_State *L); 27void luaB_newtag (lua_State *L);
24void luaB_copytagmethods (lua_State *L); 28void luaB_next (lua_State *L);
29void luaB_nextvar (lua_State *L);
30void luaB_print (lua_State *L);
31void luaB_rawgetglobal (lua_State *L);
25void luaB_rawgettable (lua_State *L); 32void luaB_rawgettable (lua_State *L);
33void luaB_rawsetglobal (lua_State *L);
26void luaB_rawsettable (lua_State *L); 34void luaB_rawsettable (lua_State *L);
27void luaB_settagmethod (lua_State *L);
28void luaB_gettagmethod (lua_State *L);
29void luaB_seterrormethod (lua_State *L); 35void luaB_seterrormethod (lua_State *L);
30void luaB_collectgarbage (lua_State *L); 36void luaB_setglobal (lua_State *L);
31void luaB_type (lua_State *L); 37void luaB_settag (lua_State *L);
32void luaB_dostring (lua_State *L); 38void luaB_settagmethod (lua_State *L);
33void luaB_dofile (lua_State *L); 39void luaB_sort (lua_State *L);
34void luaB_call (lua_State *L); 40void luaB_tag (lua_State *L);
35void luaB_nextvar (lua_State *L);
36void luaB_next (lua_State *L);
37void luaB_tostring (lua_State *L);
38void luaB_assert (lua_State *L);
39void luaB_foreachi (lua_State *L);
40void luaB_foreach (lua_State *L);
41void luaB_foreachvar (lua_State *L);
42void luaB_getn (lua_State *L);
43void luaB_tinsert (lua_State *L); 41void luaB_tinsert (lua_State *L);
42void luaB_tonumber (lua_State *L);
43void luaB_tostring (lua_State *L);
44void luaB_tremove (lua_State *L); 44void luaB_tremove (lua_State *L);
45void luaB_sort (lua_State *L); 45void luaB_type (lua_State *L);
46
47 46
48void luaB_predefine (lua_State *L); 47void luaB_predefine (lua_State *L);
49 48
diff --git a/lcode.c b/lcode.c
index 9ca8de7e..cf9aee47 100644
--- a/lcode.c
+++ b/lcode.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lcode.c,v 1.1 2000/02/22 13:30:11 roberto Exp roberto $ 2** $Id: lcode.c,v 1.2 2000/03/03 12:33:59 roberto Exp roberto $
3** Code generator for Lua 3** Code generator for Lua
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -152,7 +152,7 @@ int luaK_kstr (LexState *ls, int c) {
152#endif 152#endif
153 153
154static int real_constant (LexState *ls, real r) { 154static int real_constant (LexState *ls, real r) {
155 /* check whether `r' has appeared within the last LIM entries */ 155 /* check whether `r' has appeared within the last LOOKBACKNUMS entries */
156 TProtoFunc *f = ls->fs->f; 156 TProtoFunc *f = ls->fs->f;
157 int c = f->nknum; 157 int c = f->nknum;
158 int lim = c < LOOKBACKNUMS ? 0 : c-LOOKBACKNUMS; 158 int lim = c < LOOKBACKNUMS ? 0 : c-LOOKBACKNUMS;
diff --git a/ldblib.c b/ldblib.c
index 3634d213..ce6cfa2a 100644
--- a/ldblib.c
+++ b/ldblib.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ldblib.c,v 1.9 1999/12/21 18:04:41 roberto Exp roberto $ 2** $Id: ldblib.c,v 1.10 2000/01/19 12:00:45 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*/
@@ -50,7 +50,7 @@ static void getstack (lua_State *L) {
50 lua_Object res = lua_createtable(L); 50 lua_Object res = lua_createtable(L);
51 if (!lua_getinfo(L, options, &ar)) 51 if (!lua_getinfo(L, options, &ar))
52 luaL_argerror(L, 2, "invalid option"); 52 luaL_argerror(L, 2, "invalid option");
53 for ( ;*options; options++) { 53 for (; *options; options++) {
54 switch (*options) { 54 switch (*options) {
55 case 'S': 55 case 'S':
56 settabss(L, res, "source", ar.source); 56 settabss(L, res, "source", ar.source);
@@ -103,6 +103,10 @@ static void setlocal (lua_State *L) {
103} 103}
104 104
105 105
106/*
107** because of these variables, this module is not reentrant, and should
108** not be used in multiple states
109*/
106 110
107static int linehook = LUA_NOREF; /* Lua reference to line hook function */ 111static int linehook = LUA_NOREF; /* Lua reference to line hook function */
108static int callhook = LUA_NOREF; /* Lua reference to call hook function */ 112static int callhook = LUA_NOREF; /* Lua reference to call hook function */
diff --git a/ldebug.c b/ldebug.c
index da473b08..45214b8f 100644
--- a/ldebug.c
+++ b/ldebug.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ldebug.c,v 1.8 2000/02/11 16:52:54 roberto Exp roberto $ 2** $Id: ldebug.c,v 1.9 2000/02/17 18:30:36 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*/
@@ -187,7 +187,7 @@ static void lua_getobjname (lua_State *L, StkId f, lua_Dbgactreg *ar) {
187int lua_getinfo (lua_State *L, const char *what, lua_Dbgactreg *ar) { 187int lua_getinfo (lua_State *L, const char *what, lua_Dbgactreg *ar) {
188 StkId func = ar->_func; 188 StkId func = ar->_func;
189 LUA_ASSERT(L, is_T_MARK(ttype(func)), "invalid activation record"); 189 LUA_ASSERT(L, is_T_MARK(ttype(func)), "invalid activation record");
190 for ( ;*what; what++) { 190 for (; *what; what++) {
191 switch (*what) { 191 switch (*what) {
192 case 'S': 192 case 'S':
193 lua_funcinfo(ar); 193 lua_funcinfo(ar);
diff --git a/ldo.c b/ldo.c
index 694da7bf..be7a4266 100644
--- a/ldo.c
+++ b/ldo.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ldo.c,v 1.66 2000/01/19 12:00:45 roberto Exp roberto $ 2** $Id: ldo.c,v 1.67 2000/02/08 16:34:31 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*/
@@ -52,7 +52,7 @@ void luaD_checkstack (lua_State *L, int n) {
52 if (L->stack_last-L->stack > (L->stacksize-1)) { 52 if (L->stack_last-L->stack > (L->stacksize-1)) {
53 /* overflow while handling overflow: do what?? */ 53 /* overflow while handling overflow: do what?? */
54 L->top -= EXTRA_STACK; 54 L->top -= EXTRA_STACK;
55 lua_error(L, "BAD STACK OVERFLOW! DATA CORRUPTED!!"); 55 lua_error(L, "BAD STACK OVERFLOW! DATA CORRUPTED!");
56 } 56 }
57 else { 57 else {
58 lua_Dbgactreg dummy; 58 lua_Dbgactreg dummy;
@@ -62,7 +62,7 @@ void luaD_checkstack (lua_State *L, int n) {
62 lua_error(L, "Lua2C - C2Lua overflow"); 62 lua_error(L, "Lua2C - C2Lua overflow");
63 } 63 }
64 else 64 else
65 lua_error(L, "stack size overflow"); 65 lua_error(L, "stack overflow; possible recursion loop");
66 } 66 }
67 } 67 }
68} 68}
@@ -254,7 +254,7 @@ void lua_error (lua_State *L, const char *s) {
254 if (L->errorJmp) 254 if (L->errorJmp)
255 longjmp(L->errorJmp->b, 1); 255 longjmp(L->errorJmp->b, 1);
256 else { 256 else {
257 message(L, "unable to recover. exiting.\n"); 257 message(L, "unable to recover; exiting\n");
258 exit(1); 258 exit(1);
259 } 259 }
260} 260}
@@ -301,7 +301,7 @@ static int protectedparser (lua_State *L, ZIO *z, int bin) {
301 TProtoFunc *volatile tf; 301 TProtoFunc *volatile tf;
302 struct lua_longjmp *volatile oldErr = L->errorJmp; 302 struct lua_longjmp *volatile oldErr = L->errorJmp;
303 L->errorJmp = &myErrorJmp; 303 L->errorJmp = &myErrorJmp;
304 L->top = base; /* erase C2Lua */ 304 L->top = base; /* clear C2Lua */
305 if (setjmp(myErrorJmp.b) == 0) { 305 if (setjmp(myErrorJmp.b) == 0) {
306 tf = bin ? luaU_undump1(L, z) : luaY_parser(L, z); 306 tf = bin ? luaU_undump1(L, z) : luaY_parser(L, z);
307 status = 0; 307 status = 0;
diff --git a/lfunc.c b/lfunc.c
index c2ea14f4..fad91ace 100644
--- a/lfunc.c
+++ b/lfunc.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lfunc.c,v 1.17 2000/01/25 13:57:18 roberto Exp roberto $ 2** $Id: lfunc.c,v 1.18 2000/01/28 16:53:00 roberto Exp roberto $
3** Auxiliary functions to manipulate prototypes and closures 3** Auxiliary functions to manipulate prototypes and closures
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -14,7 +14,7 @@
14#include "lstate.h" 14#include "lstate.h"
15 15
16#define gcsizeproto(L, p) numblocks(L, 0, sizeof(TProtoFunc)) 16#define gcsizeproto(L, p) numblocks(L, 0, sizeof(TProtoFunc))
17#define gcsizeclosure(L, c) numblocks(L, c->nelems, sizeof(Closure)) 17#define gcsizeclosure(L, c) numblocks(L, c->nelems, sizeof(Closure))
18 18
19 19
20 20
diff --git a/liolib.c b/liolib.c
index 0d75ac0d..b65d5ae4 100644
--- a/liolib.c
+++ b/liolib.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: liolib.c,v 1.56 2000/01/19 12:00:45 roberto Exp roberto $ 2** $Id: liolib.c,v 1.57 2000/02/08 16:34:31 roberto Exp roberto $
3** Standard I/O (and system) library 3** Standard I/O (and system) library
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -97,7 +97,7 @@ static FILE *gethandle (lua_State *L, lua_Object f) {
97static FILE *getfilebyname (lua_State *L, const char *name) { 97static FILE *getfilebyname (lua_State *L, const char *name) {
98 FILE *handle = gethandle(L, lua_rawgetglobal(L, name)); 98 FILE *handle = gethandle(L, lua_rawgetglobal(L, name));
99 if (!handle) 99 if (!handle)
100 luaL_verror(L, "global variable `%.50s' is not a file handle", name); 100 luaL_verror(L, "`%.50s' is not a file handle", name);
101 return handle; 101 return handle;
102} 102}
103 103
@@ -286,7 +286,7 @@ static int read_pattern (lua_State *L, FILE *f, const char *p) {
286 286
287#else 287#else
288 288
289#define read_pattern(L, f,p) (lua_error(L, "read patterns are deprecated"), 0) 289#define read_pattern(L, f, p) (lua_error(L, "read patterns are deprecated"), 0)
290 290
291#endif 291#endif
292 292
@@ -525,9 +525,6 @@ static void io_debug (lua_State *L) {
525#define MAXMESSAGE (MESSAGESIZE*10) 525#define MAXMESSAGE (MESSAGESIZE*10)
526 526
527 527
528#define MAXSRC 60
529
530
531static void errorfb (lua_State *L) { 528static void errorfb (lua_State *L) {
532 char buff[MAXMESSAGE]; 529 char buff[MAXMESSAGE];
533 int level = 1; /* skip level 0 (it's this function) */ 530 int level = 1; /* skip level 0 (it's this function) */
@@ -535,10 +532,10 @@ static void errorfb (lua_State *L) {
535 lua_Object alertfunc = lua_rawgetglobal(L, "_ALERT"); 532 lua_Object alertfunc = lua_rawgetglobal(L, "_ALERT");
536 sprintf(buff, "error: %.200s\n", lua_getstring(L, lua_getparam(L, 1))); 533 sprintf(buff, "error: %.200s\n", lua_getstring(L, lua_getparam(L, 1)));
537 while (lua_getstack(L, level++, &ar)) { 534 while (lua_getstack(L, level++, &ar)) {
538 char buffchunk[MAXSRC]; 535 char buffchunk[60];
539 lua_getinfo(L, "Snl", &ar); 536 lua_getinfo(L, "Snl", &ar);
540 luaL_chunkid(buffchunk, ar.source, sizeof(buffchunk)); 537 luaL_chunkid(buffchunk, ar.source, sizeof(buffchunk));
541 if (level == 2) strcat(buff, "Active Stack:\n"); 538 if (level == 2) strcat(buff, "Stack traceback:\n");
542 strcat(buff, " "); 539 strcat(buff, " ");
543 if (strlen(buff) > MAXMESSAGE-MESSAGESIZE) { 540 if (strlen(buff) > MAXMESSAGE-MESSAGESIZE) {
544 strcat(buff, "...\n"); 541 strcat(buff, "...\n");
diff --git a/llex.c b/llex.c
index 19edb8f0..6745fbbc 100644
--- a/llex.c
+++ b/llex.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: llex.c,v 1.50 2000/01/26 18:51:49 roberto Exp roberto $ 2** $Id: llex.c,v 1.51 2000/02/08 16:34:31 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*/
@@ -23,7 +23,7 @@
23 23
24 24
25 25
26#define next(LS) (LS->current = zgetc(LS->lex_z)) 26#define next(LS) (LS->current = zgetc(LS->z))
27 27
28 28
29#define save(L, c) luaL_addchar(L, c) 29#define save(L, c) luaL_addchar(L, c)
@@ -37,7 +37,7 @@ static const char *const token2string [] = {"and", "do", "else", "elseif", "end"
37 37
38 38
39void luaX_init (lua_State *L) { 39void luaX_init (lua_State *L) {
40 unsigned int i; 40 int i;
41 for (i=0; i<NUM_RESERVED; i++) { 41 for (i=0; i<NUM_RESERVED; i++) {
42 TaggedString *ts = luaS_new(L, token2string[i]); 42 TaggedString *ts = luaS_new(L, token2string[i]);
43 ts->marked = (unsigned char)(RESERVEDMARK+i); /* reserved word */ 43 ts->marked = (unsigned char)(RESERVEDMARK+i); /* reserved word */
@@ -49,7 +49,7 @@ void luaX_init (lua_State *L) {
49 49
50void luaX_syntaxerror (LexState *ls, const char *s, const char *token) { 50void luaX_syntaxerror (LexState *ls, const char *s, const char *token) {
51 char buff[MAXSRC]; 51 char buff[MAXSRC];
52 luaL_chunkid(buff, zname(ls->lex_z), sizeof(buff)); 52 luaL_chunkid(buff, zname(ls->z), sizeof(buff));
53 luaL_verror(ls->L, "%.100s;\n last token read: `%.50s' at line %d in %.80s", 53 luaL_verror(ls->L, "%.100s;\n last token read: `%.50s' at line %d in %.80s",
54 s, token, ls->linenumber, buff); 54 s, token, ls->linenumber, buff);
55} 55}
@@ -86,10 +86,10 @@ static void luaX_invalidchar (LexState *ls, int c) {
86 86
87static void firstline (LexState *LS) 87static void firstline (LexState *LS)
88{ 88{
89 int c = zgetc(LS->lex_z); 89 int c = zgetc(LS->z);
90 if (c == '#') 90 if (c == '#')
91 while ((c=zgetc(LS->lex_z)) != '\n' && c != EOZ) /* skip first line */; 91 while ((c=zgetc(LS->z)) != '\n' && c != EOZ) /* skip first line */;
92 zungetc(LS->lex_z); 92 zungetc(LS->z);
93} 93}
94 94
95 95
@@ -100,7 +100,7 @@ void luaX_setinput (lua_State *L, LexState *LS, ZIO *z) {
100 LS->iflevel = 0; 100 LS->iflevel = 0;
101 LS->ifstate[0].skip = 0; 101 LS->ifstate[0].skip = 0;
102 LS->ifstate[0].elsepart = 1; /* to avoid a free $else */ 102 LS->ifstate[0].elsepart = 1; /* to avoid a free $else */
103 LS->lex_z = z; 103 LS->z = z;
104 LS->fs = NULL; 104 LS->fs = NULL;
105 firstline(LS); 105 firstline(LS);
106 luaL_resetbuffer(L); 106 luaL_resetbuffer(L);
@@ -322,7 +322,7 @@ int luaX_lex (LexState *LS) {
322 for (;;) { 322 for (;;) {
323 switch (LS->current) { 323 switch (LS->current) {
324 324
325 case ' ': case '\t': case '\r': /* CR: to avoid problems with DOS */ 325 case ' ': case '\t': case '\r': /* `\r' to avoid problems with DOS */
326 next(LS); 326 next(LS);
327 continue; 327 continue;
328 328
diff --git a/llex.h b/llex.h
index 8b11cd64..93097010 100644
--- a/llex.h
+++ b/llex.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: llex.h,v 1.17 2000/01/25 18:44:21 roberto Exp roberto $ 2** $Id: llex.h,v 1.18 2000/02/08 16:34:31 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*/
@@ -11,7 +11,7 @@
11#include "lzio.h" 11#include "lzio.h"
12 12
13 13
14#define FIRST_RESERVED 260 14#define FIRST_RESERVED 257
15 15
16/* maximum length of a reserved word (+1 for final 0) */ 16/* maximum length of a reserved word (+1 for final 0) */
17#define TOKEN_LEN 15 17#define TOKEN_LEN 15
@@ -30,7 +30,8 @@ enum RESERVED {
30 NAME, CONC, DOTS, EQ, GE, LE, NE, NUMBER, STRING, EOS 30 NAME, CONC, DOTS, EQ, GE, LE, NE, NUMBER, STRING, EOS
31}; 31};
32 32
33#define NUM_RESERVED (WHILE-FIRST_RESERVED+1) /* number of reserved words */ 33/* number of reserved words */
34#define NUM_RESERVED ((int)(WHILE-FIRST_RESERVED+1))
34 35
35 36
36#ifndef MAX_IFS 37#ifndef MAX_IFS
@@ -49,13 +50,13 @@ struct ifState {
49typedef struct LexState { 50typedef struct LexState {
50 int current; /* look ahead character */ 51 int current; /* look ahead character */
51 int token; /* look ahead token */ 52 int token; /* look ahead token */
52 struct FuncState *fs; /* `FuncState' is private for the parser */ 53 struct FuncState *fs; /* `FuncState' is private to the parser */
53 struct lua_State *L; 54 struct lua_State *L;
54 union { 55 union {
55 real r; 56 real r;
56 TaggedString *ts; 57 TaggedString *ts;
57 } seminfo; /* semantics information */ 58 } seminfo; /* semantics information */
58 struct zio *lex_z; /* input stream */ 59 struct zio *z; /* input stream */
59 int linenumber; /* input line counter */ 60 int linenumber; /* input line counter */
60 int iflevel; /* level of nested $if's (for lexical analysis) */ 61 int iflevel; /* level of nested $if's (for lexical analysis) */
61 struct ifState ifstate[MAX_IFS]; 62 struct ifState ifstate[MAX_IFS];
diff --git a/lmem.c b/lmem.c
index c8cbb0fe..9c9073f0 100644
--- a/lmem.c
+++ b/lmem.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lmem.c,v 1.24 2000/01/13 16:30:47 roberto Exp roberto $ 2** $Id: lmem.c,v 1.25 2000/02/08 16:34:31 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*/
@@ -43,7 +43,9 @@
43#define free(b) debug_realloc(b, 0) 43#define free(b) debug_realloc(b, 0)
44 44
45 45
46#define HEADER (sizeof(double)) /* maximum alignment */ 46/* ensures maximum alignment for HEADER */
47#define HEADER (sizeof(double)>sizeof(long) ? sizeof(double) : sizeof(long))
48
47#define MARKSIZE 16 49#define MARKSIZE 16
48#define MARK 0x55 /* 01010101 (a nice pattern) */ 50#define MARK 0x55 /* 01010101 (a nice pattern) */
49 51
@@ -77,21 +79,21 @@ static void freeblock (void *block) {
77 79
78 80
79static void *debug_realloc (void *block, size_t size) { 81static void *debug_realloc (void *block, size_t size) {
80 size_t realsize = HEADER+size+MARKSIZE;
81 if (size == 0) { 82 if (size == 0) {
82 freeblock(block); 83 freeblock(block);
83 return NULL; 84 return NULL;
84 } 85 }
85 else { 86 else {
87 size_t realsize = HEADER+size+MARKSIZE;
86 char *newblock = (char *)(malloc)(realsize); /* alloc a new block */ 88 char *newblock = (char *)(malloc)(realsize); /* alloc a new block */
87 int i; 89 int i;
90 if (newblock == NULL) return NULL;
88 if (block) { 91 if (block) {
89 size_t oldsize = *blocksize(block); 92 size_t oldsize = *blocksize(block);
90 if (oldsize > size) oldsize = size; 93 if (oldsize > size) oldsize = size;
91 memcpy(newblock+HEADER, block, oldsize); 94 memcpy(newblock+HEADER, block, oldsize);
92 freeblock(block); /* erase (and check) old copy */ 95 freeblock(block); /* erase (and check) old copy */
93 } 96 }
94 if (newblock == NULL) return NULL;
95 memdebug_total += size; 97 memdebug_total += size;
96 memdebug_numblocks++; 98 memdebug_numblocks++;
97 *(unsigned long *)newblock = size; 99 *(unsigned long *)newblock = size;
@@ -123,14 +125,13 @@ void *luaM_growaux (lua_State *L, void *block, unsigned long nelems,
123** generic allocation routine. 125** generic allocation routine.
124*/ 126*/
125void *luaM_realloc (lua_State *L, void *block, unsigned long size) { 127void *luaM_realloc (lua_State *L, void *block, unsigned long size) {
126 size_t s = (size_t)size;
127 if (s != size)
128 lua_error(L, "memory allocation error: block too big");
129 if (size == 0) { 128 if (size == 0) {
130 free(block); /* block may be NULL; that is OK for free */ 129 free(block); /* block may be NULL; that is OK for free */
131 return NULL; 130 return NULL;
132 } 131 }
133 block = realloc(block, s); 132 else if ((size_t)size != size)
133 lua_error(L, "memory allocation error: block too big");
134 block = realloc(block, size);
134 if (block == NULL) 135 if (block == NULL)
135 lua_error(L, memEM); 136 lua_error(L, memEM);
136 return block; 137 return block;
diff --git a/lobject.c b/lobject.c
index af98ebf6..617815d8 100644
--- a/lobject.c
+++ b/lobject.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lobject.c,v 1.30 2000/01/25 18:44:21 roberto Exp roberto $ 2** $Id: lobject.c,v 1.31 2000/02/17 18:30:36 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*/
@@ -16,7 +16,7 @@
16const char *const luaO_typenames[] = { /* ORDER LUA_T */ 16const char *const luaO_typenames[] = { /* ORDER LUA_T */
17 "userdata", "number", "string", "table", "function", "function", "nil", 17 "userdata", "number", "string", "table", "function", "function", "nil",
18 "function", "function", "function", "function", "function", "function", 18 "function", "function", "function", "function", "function", "function",
19 "line", "global", "local", "field", NULL 19 "line", NULL
20}; 20};
21 21
22 22
diff --git a/lobject.h b/lobject.h
index a5eb77d7..20368bdf 100644
--- a/lobject.h
+++ b/lobject.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lobject.h,v 1.48 2000/02/17 18:30:36 roberto Exp roberto $ 2** $Id: lobject.h,v 1.49 2000/02/21 18:33:26 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*/
@@ -14,15 +14,13 @@
14 14
15 15
16#ifdef DEBUG 16#ifdef DEBUG
17#ifdef NDEBUG
18#undef NDEBUG 17#undef NDEBUG
19#endif
20#include <assert.h> 18#include <assert.h>
21#define LUA_INTERNALERROR(L,s) assert(0) 19#define LUA_INTERNALERROR(L,s) assert(0)
22#define LUA_ASSERT(L,c,s) assert(c) 20#define LUA_ASSERT(L,c,s) assert(c)
23#else 21#else
24#define LUA_INTERNALERROR(L,s) /* empty */ 22#define LUA_INTERNALERROR(L,s) /* empty */
25#define LUA_ASSERT(L,c,s) /* empty */ 23#define LUA_ASSERT(L,c,s) /* empty */
26#endif 24#endif
27 25
28 26
@@ -51,7 +49,7 @@ typedef unsigned long Instruction;
51 49
52/* conversion of pointer to int (for hashing only) */ 50/* conversion of pointer to int (for hashing only) */
53/* (the shift removes bits that are usually 0 because of alignment) */ 51/* (the shift removes bits that are usually 0 because of alignment) */
54#define IntPoint(L, p) (((unsigned int)(p)) >> 3) 52#define IntPoint(L, p) (((unsigned long)(p)) >> 3)
55 53
56 54
57/* 55/*
@@ -68,21 +66,21 @@ typedef unsigned long Instruction;
68** grep "ORDER LUA_T" 66** grep "ORDER LUA_T"
69*/ 67*/
70typedef enum { 68typedef enum {
71 LUA_T_USERDATA = 0, /* default tag for userdata */ 69 LUA_T_USERDATA = 0, /* default tag for userdata */
72 LUA_T_NUMBER = -1, /* fixed tag for numbers */ 70 LUA_T_NUMBER = -1, /* fixed tag for numbers */
73 LUA_T_STRING = -2, /* fixed tag for strings */ 71 LUA_T_STRING = -2, /* fixed tag for strings */
74 LUA_T_ARRAY = -3, /* default tag for tables (or arrays) */ 72 LUA_T_ARRAY = -3, /* default tag for tables (or arrays) */
75 LUA_T_LPROTO = -4, /* fixed tag for Lua functions */ 73 LUA_T_LPROTO = -4, /* fixed tag for Lua functions */
76 LUA_T_CPROTO = -5, /* fixed tag for C functions */ 74 LUA_T_CPROTO = -5, /* fixed tag for C functions */
77 LUA_T_NIL = -6, /* last "pre-defined" tag */ 75 LUA_T_NIL = -6, /* last "pre-defined" tag */
78 76
79 LUA_T_LCLOSURE = -7, /* Lua closure */ 77 LUA_T_LCLOSURE = -7, /* Lua closure */
80 LUA_T_CCLOSURE = -8, /* C closure */ 78 LUA_T_CCLOSURE = -8, /* C closure */
81 79
82 LUA_T_LCLMARK = -9 ,/* mark for Lua closures */ 80 LUA_T_LCLMARK = -9 ,/* mark for Lua closures */
83 LUA_T_CCLMARK = -10,/* mark for C closures */ 81 LUA_T_CCLMARK = -10,/* mark for C closures */
84 LUA_T_LMARK = -11, /* mark for Lua prototypes */ 82 LUA_T_LMARK = -11,/* mark for Lua prototypes */
85 LUA_T_CMARK = -12, /* mark for C prototypes */ 83 LUA_T_CMARK = -12,/* mark for C prototypes */
86 84
87 LUA_T_LINE = -13 85 LUA_T_LINE = -13
88} lua_Type; 86} lua_Type;
@@ -93,7 +91,7 @@ typedef enum {
93#define LAST_REGULAR_TAG LUA_T_CCLOSURE /* after that, are all marks */ 91#define LAST_REGULAR_TAG LUA_T_CCLOSURE /* after that, are all marks */
94 92
95/* 93/*
96** chech whether `t' is a mark; ttypes are negative numbers, so the 94** check whether `t' is a mark; ttypes are negative numbers, so the
97** comparisons look reversed. (ORDER LUA_T) 95** comparisons look reversed. (ORDER LUA_T)
98*/ 96*/
99#define is_T_MARK(t) (LUA_T_CMARK <= (t) && (t) <= LUA_T_LCLMARK) 97#define is_T_MARK(t) (LUA_T_CMARK <= (t) && (t) <= LUA_T_LCLMARK)
@@ -221,6 +219,7 @@ typedef struct Hash {
221 219
222 220
223extern const char *const luaO_typenames[]; 221extern const char *const luaO_typenames[];
222extern const TObject luaO_nilobject;
224 223
225#define luaO_typename(o) luaO_typenames[-ttype(o)] 224#define luaO_typename(o) luaO_typenames[-ttype(o)]
226 225
@@ -228,11 +227,7 @@ extern const char *const luaO_typenames[];
228 227
229unsigned long luaO_power2 (unsigned long n); 228unsigned long luaO_power2 (unsigned long n);
230 229
231extern const TObject luaO_nilobject; 230#define luaO_equalObj(t1,t2) (ttype(t1) == ttype(t2) && luaO_equalval(t1,t2))
232
233
234#define luaO_equalObj(t1,t2) ((ttype(t1) != ttype(t2)) ? 0 \
235 : luaO_equalval(t1,t2))
236int luaO_equalval (const TObject *t1, const TObject *t2); 231int luaO_equalval (const TObject *t1, const TObject *t2);
237int luaO_redimension (lua_State *L, int oldsize); 232int luaO_redimension (lua_State *L, int oldsize);
238int luaO_str2d (const char *s, real *result); 233int luaO_str2d (const char *s, real *result);
diff --git a/lopcodes.h b/lopcodes.h
index 16f22d45..c822049c 100644
--- a/lopcodes.h
+++ b/lopcodes.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lopcodes.h,v 1.41 2000/02/22 13:30:11 roberto Exp roberto $ 2** $Id: lopcodes.h,v 1.42 2000/03/02 12:32:53 roberto Exp roberto $
3** Opcodes for Lua virtual machine 3** Opcodes for Lua virtual machine
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -21,9 +21,11 @@
21 2nd unsigned argument in the middle 8 bits (`B') 21 2nd unsigned argument in the middle 8 bits (`B')
22 22
23 The signed argument is represented in excess 2^23; that is, the real value 23 The signed argument is represented in excess 2^23; that is, the real value
24 is 2^23 minus the usigned value. 24 is the usigned value minus 2^23.
25===========================================================================*/ 25===========================================================================*/
26 26
27#define EXCESS_S (1<<23) /* == 2^23 */
28
27/* 29/*
28** the following macros help to manipulate instructions 30** the following macros help to manipulate instructions
29*/ 31*/
@@ -35,13 +37,13 @@
35 37
36#define GET_OPCODE(i) ((OpCode)((i)&0xFF)) 38#define GET_OPCODE(i) ((OpCode)((i)&0xFF))
37#define GETARG_U(i) ((int)((i)>>8)) 39#define GETARG_U(i) ((int)((i)>>8))
38#define GETARG_S(i) ((int)((i)>>8)-(1<<23)) 40#define GETARG_S(i) ((int)((i)>>8)-EXCESS_S)
39#define GETARG_A(i) ((int)((i)>>16)) 41#define GETARG_A(i) ((int)((i)>>16))
40#define GETARG_B(i) ((int)(((i)>>8) & 0xFF)) 42#define GETARG_B(i) ((int)(((i)>>8) & 0xFF))
41 43
42#define SET_OPCODE(i,o) (((i)&0xFFFFFF00u) | (Instruction)(o)) 44#define SET_OPCODE(i,o) (((i)&0xFFFFFF00u) | (Instruction)(o))
43#define SETARG_U(i,u) (((i)&0x000000FFu) | ((Instruction)(u)<<8)) 45#define SETARG_U(i,u) (((i)&0x000000FFu) | ((Instruction)(u)<<8))
44#define SETARG_S(i,s) (((i)&0x000000FFu) | ((Instruction)((s)+(1<<23))<<8)) 46#define SETARG_S(i,s) (((i)&0x000000FFu) | ((Instruction)((s)+EXCESS_S)<<8))
45#define SETARG_A(i,a) (((i)&0x0000FFFFu) | ((Instruction)(a)<<16)) 47#define SETARG_A(i,a) (((i)&0x0000FFFFu) | ((Instruction)(a)<<16))
46#define SETARG_B(i,b) (((i)&0xFFFF00FFu) | ((Instruction)(b)<<8)) 48#define SETARG_B(i,b) (((i)&0xFFFF00FFu) | ((Instruction)(b)<<8))
47 49
@@ -55,8 +57,9 @@
55*/ 57*/
56 58
57typedef enum { 59typedef enum {
58/* name parm before after side effect 60/*----------------------------------------------------------------------
59-----------------------------------------------------------------------------*/ 61name args stack before stack after side effects
62------------------------------------------------------------------------*/
60ENDCODE,/* - - (return) */ 63ENDCODE,/* - - (return) */
61RETCODE,/* U - (return) */ 64RETCODE,/* U - (return) */
62 65
diff --git a/lparser.c b/lparser.c
index 643dce0f..1cdc35b6 100644
--- a/lparser.c
+++ b/lparser.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lparser.c,v 1.60 2000/02/22 13:30:11 roberto Exp roberto $ 2** $Id: lparser.c,v 1.61 2000/03/03 12:33:59 roberto Exp roberto $
3** LL(1) Parser and code generator for Lua 3** LL(1) Parser and code generator for Lua
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -434,7 +434,7 @@ static int funcparams (LexState *ls, int slf) {
434 break; 434 break;
435 435
436 case STRING: /* funcparams -> STRING */ 436 case STRING: /* funcparams -> STRING */
437 code_string(ls, ls->seminfo.ts); /* must use 'seminfo' before `next' */ 437 code_string(ls, ls->seminfo.ts); /* must use `seminfo' before `next' */
438 next(ls); 438 next(ls);
439 break; 439 break;
440 440
@@ -660,7 +660,7 @@ static void simpleexp (LexState *ls, expdesc *v) {
660 } 660 }
661 661
662 case STRING: /* simpleexp -> STRING */ 662 case STRING: /* simpleexp -> STRING */
663 /* must use 'seminfo' before `next' */ 663 /* must use `seminfo' before `next' */
664 v->info = code_string(ls, ls->seminfo.ts); 664 v->info = code_string(ls, ls->seminfo.ts);
665 next(ls); 665 next(ls);
666 break; 666 break;
@@ -930,7 +930,7 @@ static void namestat (LexState *ls) {
930 check_debugline(ls); 930 check_debugline(ls);
931 var_or_func(ls, &v); 931 var_or_func(ls, &v);
932 if (v.k == VEXP) { /* stat -> func */ 932 if (v.k == VEXP) { /* stat -> func */
933 if (!luaK_iscall(ls, v.info)) /* is just an upper value? */ 933 if (!luaK_iscall(ls, v.info)) /* is just an upvalue? */
934 luaK_error(ls, "syntax error"); 934 luaK_error(ls, "syntax error");
935 luaK_setcallreturns(ls, v.info, 0); /* call statement uses no results */ 935 luaK_setcallreturns(ls, v.info, 0); /* call statement uses no results */
936 } 936 }
@@ -1006,7 +1006,7 @@ static int stat (LexState *ls) {
1006 return 1; 1006 return 1;
1007 1007
1008 case RETURN: case ';': case ELSE: case ELSEIF: 1008 case RETURN: case ';': case ELSE: case ELSEIF:
1009 case END: case UNTIL: case EOS: /* 'stat' follow */ 1009 case END: case UNTIL: case EOS: /* `stat' follow */
1010 return 0; 1010 return 0;
1011 1011
1012 default: 1012 default:
diff --git a/lparser.h b/lparser.h
index 2414a14c..a3568a6f 100644
--- a/lparser.h
+++ b/lparser.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lparser.h,v 1.6 2000/02/22 13:30:11 roberto Exp roberto $ 2** $Id: lparser.h,v 1.7 2000/03/03 12:33:59 roberto Exp roberto $
3** LL(1) Parser and code generator for Lua 3** LL(1) Parser and code generator for Lua
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -14,31 +14,31 @@
14 14
15/* maximum number of local variables */ 15/* maximum number of local variables */
16#ifndef MAXLOCALS 16#ifndef MAXLOCALS
17#define MAXLOCALS 200 /* arbitrary limit (<=MAXARG_B) */ 17#define MAXLOCALS 200 /* arbitrary limit (<=MAXARG_B) */
18#endif 18#endif
19 19
20 20
21/* maximum number of upvalues */ 21/* maximum number of upvalues */
22#ifndef MAXUPVALUES 22#ifndef MAXUPVALUES
23#define MAXUPVALUES 32 /* arbitrary limit (<=MAXARG_B) */ 23#define MAXUPVALUES 32 /* arbitrary limit (<=MAXARG_B) */
24#endif 24#endif
25 25
26 26
27/* maximum number of variables in the left side of an assignment */ 27/* maximum number of variables in the left side of an assignment */
28#ifndef MAXVARSLH 28#ifndef MAXVARSLH
29#define MAXVARSLH 100 /* arbitrary limit (<=MAXARG_B) */ 29#define MAXVARSLH 100 /* arbitrary limit (<=MAXARG_B) */
30#endif 30#endif
31 31
32 32
33/* maximum number of parameters in a function */ 33/* maximum number of parameters in a function */
34#ifndef MAXPARAMS 34#ifndef MAXPARAMS
35#define MAXPARAMS 100 /* arbitrary limit (<=MAXLOCALS) */ 35#define MAXPARAMS 100 /* arbitrary limit (<=MAXLOCALS) */
36#endif 36#endif
37 37
38 38
39/* maximum stack size in a function */ 39/* maximum stack size in a function */
40#ifndef MAXSTACK 40#ifndef MAXSTACK
41#define MAXSTACK 256 /* arbitrary limit (<=MAXARG_A) */ 41#define MAXSTACK 256 /* arbitrary limit (<=MAXARG_A) */
42#endif 42#endif
43 43
44 44
diff --git a/lref.c b/lref.c
index 2bfa773f..eeb720a2 100644
--- a/lref.c
+++ b/lref.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lref.c,v 1.6 1999/12/27 17:33:22 roberto Exp roberto $ 2** $Id: lref.c,v 1.7 2000/02/08 16:34:31 roberto Exp roberto $
3** reference mechanism 3** reference mechanism
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -16,7 +16,7 @@
16 16
17int lua_ref (lua_State *L, int lock) { 17int lua_ref (lua_State *L, int lock) {
18 int ref; 18 int ref;
19 luaA_checkCparams(L, 1); 19 luaA_checkCargs(L, 1);
20 if (ttype(L->top-1) == LUA_T_NIL) 20 if (ttype(L->top-1) == LUA_T_NIL)
21 ref = LUA_REFNIL; 21 ref = LUA_REFNIL;
22 else { 22 else {
@@ -39,7 +39,8 @@ int lua_ref (lua_State *L, int lock) {
39void lua_unref (lua_State *L, int ref) { 39void lua_unref (lua_State *L, int ref) {
40 if (ref >= 0) { 40 if (ref >= 0) {
41 if (ref >= L->refSize || L->refArray[ref].st >= 0) 41 if (ref >= L->refSize || L->refArray[ref].st >= 0)
42 lua_error(L, "API error - invalid parameter for function `lua_unref'"); 42 lua_error(L, "Lua API error - "
43 "invalid argument for function `lua_unref'");
43 L->refArray[ref].st = L->refFree; 44 L->refArray[ref].st = L->refFree;
44 L->refFree = ref; 45 L->refFree = ref;
45 } 46 }
@@ -67,7 +68,7 @@ void lua_beginblock (lua_State *L) {
67 68
68void lua_endblock (lua_State *L) { 69void lua_endblock (lua_State *L) {
69 if (L->numCblocks <= 0) 70 if (L->numCblocks <= 0)
70 lua_error(L, "API error - no block to end"); 71 lua_error(L, "Lua API error - no block to end");
71 --L->numCblocks; 72 --L->numCblocks;
72 L->Cstack = L->Cblocks[L->numCblocks]; 73 L->Cstack = L->Cblocks[L->numCblocks];
73 L->top = L->Cstack.base; 74 L->top = L->Cstack.base;
diff --git a/lstring.c b/lstring.c
index 85ede619..42cf255f 100644
--- a/lstring.c
+++ b/lstring.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lstring.c,v 1.30 1999/11/26 18:59:20 roberto Exp roberto $ 2** $Id: lstring.c,v 1.31 1999/12/14 18:42:57 roberto Exp roberto $
3** String table (keeps all strings handled by Lua) 3** String table (keeps all strings handled by Lua)
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -18,7 +18,7 @@
18 18
19 19
20#define gcsizestring(L, l) numblocks(L, 0, sizeof(TaggedString)+l) 20#define gcsizestring(L, l) numblocks(L, 0, sizeof(TaggedString)+l)
21#define gcsizeudata gcsizestring(L, 0) 21#define gcsizeudata gcsizestring(L, 0)
22 22
23 23
24 24
diff --git a/lstring.h b/lstring.h
index 040a590c..1bc3bac0 100644
--- a/lstring.h
+++ b/lstring.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lstring.h,v 1.14 1999/11/26 18:59:20 roberto Exp roberto $ 2** $Id: lstring.h,v 1.15 1999/12/14 18:42:57 roberto Exp roberto $
3** String table (keep all strings handled by Lua) 3** String table (keep all strings handled by Lua)
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -12,8 +12,8 @@
12#include "lstate.h" 12#include "lstate.h"
13 13
14 14
15#define NUM_HASHSTR 31 /* a prime not in array `dimensions' */ 15#define NUM_HASHSTR 31
16#define NUM_HASHUDATA 31 /* idem */ 16#define NUM_HASHUDATA 31
17#define NUM_HASHS (NUM_HASHSTR+NUM_HASHUDATA) 17#define NUM_HASHS (NUM_HASHSTR+NUM_HASHUDATA)
18 18
19 19
diff --git a/lstrlib.c b/lstrlib.c
index 713cc72e..3a1d8ba3 100644
--- a/lstrlib.c
+++ b/lstrlib.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lstrlib.c,v 1.39 1999/12/27 17:33:22 roberto Exp roberto $ 2** $Id: lstrlib.c,v 1.40 2000/02/08 16:34:31 roberto Exp roberto $
3** Standard library for string operations and pattern-matching 3** Standard library for string operations and pattern-matching
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -116,8 +116,8 @@ static void str_char (lua_State *L) {
116** ======================================================= 116** =======================================================
117*/ 117*/
118 118
119#ifndef MAX_CAPT 119#ifndef MAX_CAPTURES
120#define MAX_CAPT 32 /* arbitrary limit */ 120#define MAX_CAPTURES 32 /* arbitrary limit */
121#endif 121#endif
122 122
123 123
@@ -127,12 +127,12 @@ struct Capture {
127 struct { 127 struct {
128 const char *init; 128 const char *init;
129 int len; /* -1 signals unfinished capture */ 129 int len; /* -1 signals unfinished capture */
130 } capture[MAX_CAPT]; 130 } capture[MAX_CAPTURES];
131}; 131};
132 132
133 133
134#define ESC '%' 134#define ESC '%'
135#define SPECIALS "^$*+?.([%-" 135#define SPECIALS "^$*+?.([%-"
136 136
137 137
138static void push_captures (lua_State *L, struct Capture *cap) { 138static void push_captures (lua_State *L, struct Capture *cap) {
@@ -145,7 +145,7 @@ static void push_captures (lua_State *L, struct Capture *cap) {
145} 145}
146 146
147 147
148static int check_cap (lua_State *L, int l, struct Capture *cap) { 148static int check_capture (lua_State *L, int l, struct Capture *cap) {
149 l -= '1'; 149 l -= '1';
150 if (!(0 <= l && l < cap->level && cap->capture[l].len != -1)) 150 if (!(0 <= l && l < cap->level && cap->capture[l].len != -1))
151 lua_error(L, "invalid capture index"); 151 lua_error(L, "invalid capture index");
@@ -165,12 +165,12 @@ static int capture_to_close (lua_State *L, struct Capture *cap) {
165const char *luaI_classend (lua_State *L, const char *p) { 165const char *luaI_classend (lua_State *L, const char *p) {
166 switch (*p++) { 166 switch (*p++) {
167 case ESC: 167 case ESC:
168 if (*p == '\0') lua_error(L, "incorrect pattern (ends with `%')"); 168 if (*p == '\0') lua_error(L, "malformed pattern (ends with `%')");
169 return p+1; 169 return p+1;
170 case '[': 170 case '[':
171 if (*p == '^') p++; 171 if (*p == '^') p++;
172 do { /* look for a ']' */ 172 do { /* look for a ']' */
173 if (*p == '\0') lua_error(L, "incorrect pattern (missing `]')"); 173 if (*p == '\0') lua_error(L, "malformed pattern (missing `]')");
174 if (*(p++) == ESC && *p != '\0') p++; /* skip escapes (e.g. '%]') */ 174 if (*(p++) == ESC && *p != '\0') p++; /* skip escapes (e.g. '%]') */
175 } while (*p != ']'); 175 } while (*p != ']');
176 return p+1; 176 return p+1;
@@ -180,7 +180,7 @@ const char *luaI_classend (lua_State *L, const char *p) {
180} 180}
181 181
182 182
183static int matchclass (int c, int cl) { 183static int match_class (int c, int cl) {
184 int res; 184 int res;
185 switch (tolower(cl)) { 185 switch (tolower(cl)) {
186 case 'a' : res = isalpha(c); break; 186 case 'a' : res = isalpha(c); break;
@@ -209,7 +209,7 @@ static int matchbracketclass (int c, const char *p, const char *endclass) {
209 while (++p < endclass) { 209 while (++p < endclass) {
210 if (*p == ESC) { 210 if (*p == ESC) {
211 p++; 211 p++;
212 if (matchclass(c, (unsigned char)*p)) 212 if (match_class(c, (unsigned char)*p))
213 return sig; 213 return sig;
214 } 214 }
215 else if ((*(p+1) == '-') && (p+2 < endclass)) { 215 else if ((*(p+1) == '-') && (p+2 < endclass)) {
@@ -217,7 +217,7 @@ static int matchbracketclass (int c, const char *p, const char *endclass) {
217 if ((int)(unsigned char)*(p-2) <= c && c <= (int)(unsigned char)*p) 217 if ((int)(unsigned char)*(p-2) <= c && c <= (int)(unsigned char)*p)
218 return sig; 218 return sig;
219 } 219 }
220 else if ((unsigned char)*p == c) return sig; 220 else if ((int)(unsigned char)*p == c) return sig;
221 } 221 }
222 return !sig; 222 return !sig;
223} 223}
@@ -229,7 +229,7 @@ int luaI_singlematch (int c, const char *p, const char *ep) {
229 case '.': /* matches any char */ 229 case '.': /* matches any char */
230 return 1; 230 return 1;
231 case ESC: 231 case ESC:
232 return matchclass(c, (unsigned char)*(p+1)); 232 return match_class(c, (unsigned char)*(p+1));
233 case '[': 233 case '[':
234 return matchbracketclass(c, p, ep-1); 234 return matchbracketclass(c, p, ep-1);
235 default: 235 default:
@@ -289,11 +289,11 @@ static const char *min_expand (lua_State *L, const char *s, const char *p, const
289} 289}
290 290
291 291
292static const char *start_capt (lua_State *L, const char *s, const char *p, 292static const char *start_capture (lua_State *L, const char *s, const char *p,
293 struct Capture *cap) { 293 struct Capture *cap) {
294 const char *res; 294 const char *res;
295 int level = cap->level; 295 int level = cap->level;
296 if (level >= MAX_CAPT) lua_error(L, "too many captures"); 296 if (level >= MAX_CAPTURES) lua_error(L, "too many captures");
297 cap->capture[level].init = s; 297 cap->capture[level].init = s;
298 cap->capture[level].len = -1; 298 cap->capture[level].len = -1;
299 cap->level = level+1; 299 cap->level = level+1;
@@ -303,8 +303,8 @@ static const char *start_capt (lua_State *L, const char *s, const char *p,
303} 303}
304 304
305 305
306static const char *end_capt (lua_State *L, const char *s, const char *p, 306static const char *end_capture (lua_State *L, const char *s, const char *p,
307 struct Capture *cap) { 307 struct Capture *cap) {
308 int l = capture_to_close(L, cap); 308 int l = capture_to_close(L, cap);
309 const char *res; 309 const char *res;
310 cap->capture[l].len = s - cap->capture[l].init; /* close capture */ 310 cap->capture[l].len = s - cap->capture[l].init; /* close capture */
@@ -316,7 +316,7 @@ static const char *end_capt (lua_State *L, const char *s, const char *p,
316 316
317static const char *match_capture (lua_State *L, const char *s, int level, 317static const char *match_capture (lua_State *L, const char *s, int level,
318 struct Capture *cap) { 318 struct Capture *cap) {
319 int l = check_cap(L, level, cap); 319 int l = check_capture(L, level, cap);
320 int len = cap->capture[l].len; 320 int len = cap->capture[l].len;
321 if (cap->src_end-s >= len && 321 if (cap->src_end-s >= len &&
322 memcmp(cap->capture[l].init, s, len) == 0) 322 memcmp(cap->capture[l].init, s, len) == 0)
@@ -329,9 +329,9 @@ static const char *match (lua_State *L, const char *s, const char *p, struct Cap
329 init: /* using goto's to optimize tail recursion */ 329 init: /* using goto's to optimize tail recursion */
330 switch (*p) { 330 switch (*p) {
331 case '(': /* start capture */ 331 case '(': /* start capture */
332 return start_capt(L, s, p, cap); 332 return start_capture(L, s, p, cap);
333 case ')': /* end capture */ 333 case ')': /* end capture */
334 return end_capt(L, s, p, cap); 334 return end_capture(L, s, p, cap);
335 case ESC: /* may be %[0-9] or %b */ 335 case ESC: /* may be %[0-9] or %b */
336 if (isdigit((unsigned char)(*(p+1)))) { /* capture? */ 336 if (isdigit((unsigned char)(*(p+1)))) { /* capture? */
337 s = match_capture(L, s, *(p+1), cap); 337 s = match_capture(L, s, *(p+1), cap);
@@ -444,7 +444,7 @@ static void add_s (lua_State *L, lua_Object newp, struct Capture *cap) {
444 if (!isdigit((unsigned char)news[i])) 444 if (!isdigit((unsigned char)news[i]))
445 luaL_addchar(L, news[i]); 445 luaL_addchar(L, news[i]);
446 else { 446 else {
447 int level = check_cap(L, news[i], cap); 447 int level = check_capture(L, news[i], cap);
448 addnchar(L, cap->capture[level].init, cap->capture[level].len); 448 addnchar(L, cap->capture[level].init, cap->capture[level].len);
449 } 449 }
450 } 450 }
@@ -576,7 +576,7 @@ static void str_format (lua_State *L) {
576 long l; 576 long l;
577 const char *s = luaL_check_lstr(L, arg, &l); 577 const char *s = luaL_check_lstr(L, arg, &l);
578 if (cap.capture[1].len == 0 && l >= 100) { 578 if (cap.capture[1].len == 0 && l >= 100) {
579 /* no precision and string is too big to be formatted; 579 /* no precision and string is too long to be formatted;
580 keep original string */ 580 keep original string */
581 addnchar(L, s, l); 581 addnchar(L, s, l);
582 continue; /* skip the "addsize" at the end */ 582 continue; /* skip the "addsize" at the end */
diff --git a/ltable.c b/ltable.c
index bd250e53..be45da44 100644
--- a/ltable.c
+++ b/ltable.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ltable.c,v 1.33 1999/12/23 18:19:57 roberto Exp roberto $ 2** $Id: ltable.c,v 1.34 2000/02/08 16:34:31 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*/
@@ -32,7 +32,7 @@
32 32
33 33
34 34
35#define TagDefault LUA_T_ARRAY; 35#define TagDefault LUA_T_ARRAY
36 36
37 37
38 38
diff --git a/ltm.c b/ltm.c
index f9812bc9..3a79d48b 100644
--- a/ltm.c
+++ b/ltm.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ltm.c,v 1.31 2000/01/19 12:00:45 roberto Exp roberto $ 2** $Id: ltm.c,v 1.32 2000/02/22 18:12:46 roberto Exp roberto $
3** Tag methods 3** Tag methods
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -147,7 +147,7 @@ void luaT_settagmethod (lua_State *L, int t, const char *event, TObject *func) {
147 e = luaI_checkevent(L, event, luaT_eventname); 147 e = luaI_checkevent(L, event, luaT_eventname);
148 checktag(L, t); 148 checktag(L, t);
149 if (!luaT_validevent(t, e)) 149 if (!luaT_validevent(t, e))
150 luaL_verror(L, "cannot change tag method `%.20s' for type `%.20s'%.20s", 150 luaL_verror(L, "cannot change `%.20s' tag method for type `%.20s'%.20s",
151 luaT_eventname[e], luaO_typenames[-t], 151 luaT_eventname[e], luaO_typenames[-t],
152 (t == LUA_T_ARRAY || t == LUA_T_USERDATA) ? " with default tag" 152 (t == LUA_T_ARRAY || t == LUA_T_USERDATA) ? " with default tag"
153 : ""); 153 : "");
diff --git a/ltm.h b/ltm.h
index 3d517e3e..21eec17c 100644
--- a/ltm.h
+++ b/ltm.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ltm.h,v 1.8 1999/11/22 13:12:07 roberto Exp roberto $ 2** $Id: ltm.h,v 1.9 2000/02/22 18:12:46 roberto Exp roberto $
3** Tag methods 3** Tag methods
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -30,11 +30,10 @@ typedef enum {
30 IM_LT, 30 IM_LT,
31 IM_CONCAT, 31 IM_CONCAT,
32 IM_GC, 32 IM_GC,
33 IM_FUNCTION 33 IM_FUNCTION,
34 IM_N /* number of elements in the enum */
34} IMS; 35} IMS;
35 36
36#define IM_N 15
37
38 37
39struct IM { 38struct IM {
40 TObject int_method[IM_N]; 39 TObject int_method[IM_N];
diff --git a/lua.c b/lua.c
index 098aa7cf..e55596cc 100644
--- a/lua.c
+++ b/lua.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lua.c,v 1.32 2000/01/19 16:50:14 roberto Exp roberto $ 2** $Id: lua.c,v 1.33 2000/02/21 18:30: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*/
@@ -87,16 +87,10 @@ static void print_version (void) {
87 87
88 88
89static void assign (char *arg) { 89static void assign (char *arg) {
90 char buffer[500]; 90 char *eq = strchr(arg, '=');
91 if (strlen(arg) >= sizeof(buffer)) 91 *eq = '\0'; /* spilt `arg' in two strings (name & value) */
92 fprintf(stderr, "lua: shell argument too long"); 92 lua_pushstring(eq+1);
93 else { 93 lua_setglobal(arg);
94 char *eq = strchr(arg, '=');
95 lua_pushstring(eq+1);
96 strncpy(buffer, arg, eq-arg);
97 buffer[eq-arg] = 0;
98 lua_setglobal(buffer);
99 }
100} 94}
101 95
102 96
@@ -139,7 +133,7 @@ static void manual_input (int prompt) {
139 if (prompt) { 133 if (prompt) {
140 const char *s = lua_getstring(lua_getglobal("_PROMPT")); 134 const char *s = lua_getstring(lua_getglobal("_PROMPT"));
141 if (!s) s = PROMPT; 135 if (!s) s = PROMPT;
142 printf("%s", s); 136 fputs(s, stdout);
143 } 137 }
144 for(;;) { 138 for(;;) {
145 int c = getchar(); 139 int c = getchar();
@@ -153,7 +147,7 @@ static void manual_input (int prompt) {
153 else break; 147 else break;
154 } 148 }
155 else if (i >= BUFSIZ-1) { 149 else if (i >= BUFSIZ-1) {
156 fprintf(stderr, "lua: argument line too long\n"); 150 fprintf(stderr, "lua: input line too long\n");
157 break; 151 break;
158 } 152 }
159 else buffer[i++] = (char)c; 153 else buffer[i++] = (char)c;
@@ -217,9 +211,9 @@ int main (int argc, char *argv[]) {
217 print_message(); 211 print_message();
218 exit(1); 212 exit(1);
219 } 213 }
220 getargs(argc-i, argv+i); /* collect following arguments */ 214 getargs(argc-i, argv+i); /* collect remaining arguments */
221 file_input(argv, i); 215 file_input(argv, i);
222 i = argc; /* stop running arguments */ 216 i = argc; /* stop scanning arguments */
223 break; 217 break;
224 default: 218 default:
225 print_message(); 219 print_message();
diff --git a/lundump.c b/lundump.c
index 01da4afb..7aa0a93d 100644
--- a/lundump.c
+++ b/lundump.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lundump.c,v 1.16 1999/12/02 19:11:51 roberto Exp roberto $ 2** $Id: lundump.c,v 1.26 2000/02/17 19:17:44 lhf Exp lhf $
3** load bytecodes from files 3** load bytecodes from files
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -50,22 +50,13 @@ static unsigned long LoadLong (lua_State* L, ZIO* Z)
50 return (hi<<16)|lo; 50 return (hi<<16)|lo;
51} 51}
52 52
53static real LoadNumber (lua_State* L, ZIO* Z, int native) 53static real LoadNumber (lua_State* L, ZIO* Z)
54{ 54{
55 if (native) 55 char b[256];
56 { 56 int size=ezgetc(L,Z);
57 real x; 57 LoadBlock(L,b,size,Z);
58 LoadBlock(L,&x,sizeof(x),Z); 58 b[size]=0;
59 return x; 59 return luaU_str2d(L,b,zname(Z));
60 }
61 else
62 {
63 char b[256];
64 int size=ezgetc(L,Z);
65 LoadBlock(L,b,size,Z);
66 b[size]=0;
67 return luaU_str2d(L,b,zname(Z));
68 }
69} 60}
70 61
71static int LoadInt (lua_State* L, ZIO* Z, const char* message) 62static int LoadInt (lua_State* L, ZIO* Z, const char* message)
@@ -76,19 +67,15 @@ static int LoadInt (lua_State* L, ZIO* Z, const char* message)
76 return i; 67 return i;
77} 68}
78 69
79#define PAD 5 /* two word operands plus opcode */ 70static void LoadCode (lua_State* L, TProtoFunc* tf, ZIO* Z)
80
81static Byte* LoadCode (lua_State* L, ZIO* Z)
82{ 71{
83 int size=LoadInt(L,Z,"code too long (%lu bytes) in %.255s"); 72 int size=LoadInt(L,Z,"code too long (%lu bytes) in %.255s");
84 Byte* b=luaM_malloc(L,size+PAD); 73 tf->code=luaM_newvector(L,size,Instruction);
85 LoadBlock(L,b,size,Z); 74 LoadBlock(L,tf->code,size*sizeof(tf->code[0]),Z);
86 if (b[size-1]!=ENDCODE) luaL_verror(L,"bad code in %.255s",zname(Z)); 75 if (tf->code[size-1]!=ENDCODE) luaL_verror(L,"bad code in %.255s",zname(Z));
87 memset(b+size,ENDCODE,PAD); /* pad code for safety */
88 return b;
89} 76}
90 77
91static TaggedString* LoadTString (lua_State* L, ZIO* Z) 78static TaggedString* LoadString (lua_State* L, ZIO* Z)
92{ 79{
93 long size=LoadLong(L,Z); 80 long size=LoadLong(L,Z);
94 if (size==0) 81 if (size==0)
@@ -97,7 +84,7 @@ static TaggedString* LoadTString (lua_State* L, ZIO* Z)
97 { 84 {
98 char* s=luaL_openspace(L,size); 85 char* s=luaL_openspace(L,size);
99 LoadBlock(L,s,size,Z); 86 LoadBlock(L,s,size,Z);
100 return luaS_newlstr(L,s,size-1); 87 return luaS_newlstr(L,s,size-1); /* remove trailing '\0' */
101 } 88 }
102} 89}
103 90
@@ -109,7 +96,7 @@ static void LoadLocals (lua_State* L, TProtoFunc* tf, ZIO* Z)
109 for (i=0; i<n; i++) 96 for (i=0; i<n; i++)
110 { 97 {
111 tf->locvars[i].line=LoadInt(L,Z,"too many lines (%lu) in %.255s"); 98 tf->locvars[i].line=LoadInt(L,Z,"too many lines (%lu) in %.255s");
112 tf->locvars[i].varname=LoadTString(L,Z); 99 tf->locvars[i].varname=LoadString(L,Z);
113 } 100 }
114 tf->locvars[i].line=-1; /* flag end of vector */ 101 tf->locvars[i].line=-1; /* flag end of vector */
115 tf->locvars[i].varname=NULL; 102 tf->locvars[i].varname=NULL;
@@ -119,31 +106,27 @@ static TProtoFunc* LoadFunction (lua_State* L, ZIO* Z, int native);
119 106
120static void LoadConstants (lua_State* L, TProtoFunc* tf, ZIO* Z, int native) 107static void LoadConstants (lua_State* L, TProtoFunc* tf, ZIO* Z, int native)
121{ 108{
122 int i,n=LoadInt(L,Z,"too many constants (%lu) in %.255s"); 109 int i,n;
123 tf->nconsts=n; 110 tf->nkstr=n=LoadInt(L,Z,"too many strings (%lu) in %.255s");
124 if (n==0) return; 111 if (n>0)
125 tf->consts=luaM_newvector(L,n,TObject);
126 for (i=0; i<n; i++)
127 { 112 {
128 TObject* o=tf->consts+i; 113 tf->kstr=luaM_newvector(L,n,TaggedString*);
129 ttype(o)=-ezgetc(L,Z); /* ttype(o) is negative - ORDER LUA_T */ 114 for (i=0; i<n; i++) tf->kstr[i]=LoadString(L,Z);
130 switch (ttype(o)) 115 }
131 { 116 tf->nknum=n=LoadInt(L,Z,"too many numbers (%lu) in %.255s");
132 case LUA_T_NUMBER: 117 if (n>0)
133 nvalue(o)=LoadNumber(L,Z,native); 118 {
134 break; 119 tf->knum=luaM_newvector(L,n,real);
135 case LUA_T_STRING: 120 if (native)
136 tsvalue(o)=LoadTString(L,Z); 121 LoadBlock(L,tf->knum,n*sizeof(tf->knum[0]),Z);
137 break; 122 else
138 case LUA_T_LPROTO: 123 for (i=0; i<n; i++) tf->knum[i]=LoadNumber(L,Z);
139 tfvalue(o)=LoadFunction(L,Z,native); 124 }
140 break; 125 tf->nkproto=n=LoadInt(L,Z,"too many functions (%lu) in %.255s");
141 case LUA_T_NIL: 126 if (n>0)
142 break; 127 {
143 default: /* cannot happen */ 128 tf->kproto=luaM_newvector(L,n,TProtoFunc*);
144 luaU_badconstant(L,"load",i,o,tf); 129 for (i=0; i<n; i++) tf->kproto[i]=LoadFunction(L,Z,native);
145 break;
146 }
147 } 130 }
148} 131}
149 132
@@ -151,9 +134,12 @@ static TProtoFunc* LoadFunction (lua_State* L, ZIO* Z, int native)
151{ 134{
152 TProtoFunc* tf=luaF_newproto(L); 135 TProtoFunc* tf=luaF_newproto(L);
153 tf->lineDefined=LoadInt(L,Z,"lineDefined too large (%lu) in %.255s"); 136 tf->lineDefined=LoadInt(L,Z,"lineDefined too large (%lu) in %.255s");
154 tf->source=LoadTString(L,Z); 137 tf->source=LoadString(L,Z);
155 if (tf->source==NULL) tf->source=luaS_new(L,zname(Z)); 138 if (tf->source==NULL) tf->source=luaS_new(L,zname(Z));
156 tf->code=LoadCode(L,Z); 139 tf->numparams=LoadInt(L,Z,"numparams too large (%lu) in %.255s");
140 tf->is_vararg=LoadInt(L,Z,"is_vararg too large (%lu) in %.255s");
141 tf->maxstacksize=LoadInt(L,Z,"maxstacksize too large (%lu) in %.255s");
142 LoadCode(L,tf,Z);
157 LoadLocals(L,tf,Z); 143 LoadLocals(L,tf,Z);
158 LoadConstants(L,tf,Z,native); 144 LoadConstants(L,tf,Z,native);
159 return tf; 145 return tf;
@@ -167,6 +153,8 @@ static void LoadSignature (lua_State* L, ZIO* Z)
167 if (*s!=0) luaL_verror(L,"bad signature in %.255s",zname(Z)); 153 if (*s!=0) luaL_verror(L,"bad signature in %.255s",zname(Z));
168} 154}
169 155
156#define V(v) v/16,v%16
157
170static int LoadHeader (lua_State* L, ZIO* Z) 158static int LoadHeader (lua_State* L, ZIO* Z)
171{ 159{
172 int version,sizeofR,native; 160 int version,sizeofR,native;
@@ -174,12 +162,12 @@ static int LoadHeader (lua_State* L, ZIO* Z)
174 version=ezgetc(L,Z); 162 version=ezgetc(L,Z);
175 if (version>VERSION) 163 if (version>VERSION)
176 luaL_verror(L, 164 luaL_verror(L,
177 "%.255s too new: version=0x%02x; expected at most 0x%02x", 165 "%.255s too new: its version is %d.%d; expected at most %d.%d",
178 zname(Z),version,VERSION); 166 zname(Z),V(version),V(VERSION));
179 if (version<VERSION0) /* check last major change */ 167 if (version<VERSION0) /* check last major change */
180 luaL_verror(L, 168 luaL_verror(L,
181 "%.255s too old: version=0x%02x; expected at least 0x%02x", 169 "%.255s too old: its version is %d.%d; expected at least %d.%d",
182 zname(Z),version,VERSION0); 170 zname(Z),V(version),V(VERSION));
183 sizeofR=ezgetc(L,Z); 171 sizeofR=ezgetc(L,Z);
184 native=(sizeofR!=0); 172 native=(sizeofR!=0);
185 if (native) /* test number representation */ 173 if (native) /* test number representation */
@@ -189,9 +177,9 @@ static int LoadHeader (lua_State* L, ZIO* Z)
189 zname(Z),sizeofR,(int)sizeof(real)); 177 zname(Z),sizeofR,(int)sizeof(real));
190 else 178 else
191 { 179 {
192 real tf=TEST_NUMBER; 180 real f=0,tf=TEST_NUMBER;
193 real f=LoadNumber(L,Z,native); 181 LoadBlock(L,&f,sizeof(f),Z);
194 if ((long)f!=(long)tf) 182 if ((long)f!=(long)tf) /* disregard errors in last bit of fraction */
195 luaL_verror(L,"unknown number format in %.255s: " 183 luaL_verror(L,"unknown number format in %.255s: "
196 "read " NUMBER_FMT "; expected " NUMBER_FMT, 184 "read " NUMBER_FMT "; expected " NUMBER_FMT,
197 zname(Z),f,tf); 185 zname(Z),f,tf);
@@ -220,16 +208,6 @@ TProtoFunc* luaU_undump1 (lua_State* L, ZIO* Z)
220} 208}
221 209
222/* 210/*
223* handle constants that cannot happen
224*/
225void luaU_badconstant (lua_State* L, const char* s, int i, const TObject* o, const TProtoFunc* tf)
226{
227 int t=ttype(o);
228 const char* name= (t>0 || t<LUA_T_LINE) ? "?" : luaO_typenames[-t];
229 luaL_verror(L,"cannot %.255s constant #%d: type=%d [%s]" IN,s,i,t,name,INLOC);
230}
231
232/*
233* convert number from text 211* convert number from text
234*/ 212*/
235double luaU_str2d (lua_State* L, const char* b, const char* where) 213double luaU_str2d (lua_State* L, const char* b, const char* where)
diff --git a/lundump.h b/lundump.h
index d4f6f628..4c582ad5 100644
--- a/lundump.h
+++ b/lundump.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lundump.h,v 1.17 1999/12/02 18:51:09 lhf Exp $ 2** $Id: lundump.h,v 1.18 2000/01/28 17:51:09 lhf Exp $
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,6 +27,7 @@ double luaU_str2d (lua_State* L, const char* b, const char* where);
27#define SIGNATURE "Lua" /* ...followed by this signature */ 27#define SIGNATURE "Lua" /* ...followed by this signature */
28 28
29/* formats for error messages */ 29/* formats for error messages */
30#define xSOURCE "<%d:%.255s>"
30#define SOURCE "<%.255s:%d>" 31#define SOURCE "<%.255s:%d>"
31#define IN " in %p " SOURCE 32#define IN " in %p " SOURCE
32#define INLOC tf,tf->source->str,tf->lineDefined 33#define INLOC tf,tf->source->str,tf->lineDefined
diff --git a/lvm.c b/lvm.c
index f88f0cd1..60a886c8 100644
--- a/lvm.c
+++ b/lvm.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lvm.c,v 1.88 2000/02/22 13:31:30 roberto Exp roberto $ 2** $Id: lvm.c,v 1.89 2000/02/22 18:12:46 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*/
@@ -30,8 +30,6 @@
30#endif 30#endif
31 31
32 32
33#define highbyte(L, x) ((x)<<8)
34
35 33
36/* 34/*
37** Extra stack size to run a function: 35** Extra stack size to run a function:
@@ -106,7 +104,7 @@ void luaV_closure (lua_State *L, int nelems) {
106void luaV_gettable (lua_State *L, StkId top) { 104void luaV_gettable (lua_State *L, StkId top) {
107 TObject *table = top-2; 105 TObject *table = top-2;
108 const TObject *im; 106 const TObject *im;
109 if (ttype(table) != LUA_T_ARRAY) { /* not a table, get gettable method */ 107 if (ttype(table) != LUA_T_ARRAY) { /* not a table, get gettable TM */
110 im = luaT_getimbyObj(L, table, IM_GETTABLE); 108 im = luaT_getimbyObj(L, table, IM_GETTABLE);
111 if (ttype(im) == LUA_T_NIL) { 109 if (ttype(im) == LUA_T_NIL) {
112 L->top = top; 110 L->top = top;
@@ -116,7 +114,7 @@ void luaV_gettable (lua_State *L, StkId top) {
116 else { /* object is a table... */ 114 else { /* object is a table... */
117 int tg = table->value.a->htag; 115 int tg = table->value.a->htag;
118 im = luaT_getim(L, tg, IM_GETTABLE); 116 im = luaT_getim(L, tg, IM_GETTABLE);
119 if (ttype(im) == LUA_T_NIL) { /* and does not have a `gettable' method */ 117 if (ttype(im) == LUA_T_NIL) { /* and does not have a `gettable' TM */
120 const TObject *h = luaH_get(L, avalue(table), table+1); 118 const TObject *h = luaH_get(L, avalue(table), table+1);
121 if (ttype(h) == LUA_T_NIL && 119 if (ttype(h) == LUA_T_NIL &&
122 (ttype(im=luaT_getim(L, tg, IM_INDEX)) != LUA_T_NIL)) { 120 (ttype(im=luaT_getim(L, tg, IM_INDEX)) != LUA_T_NIL)) {
@@ -128,9 +126,9 @@ void luaV_gettable (lua_State *L, StkId top) {
128 *table = *h; /* `push' result into table position */ 126 *table = *h; /* `push' result into table position */
129 return; 127 return;
130 } 128 }
131 /* else it has a `gettable' method, go through to next command */ 129 /* else it has a `gettable' TM, go through to next command */
132 } 130 }
133 /* object is not a table, or it has a `gettable' method */ 131 /* object is not a table, or it has a `gettable' TM */
134 L->top = top; 132 L->top = top;
135 luaD_callTM(L, im, 2, 1); 133 luaD_callTM(L, im, 2, 1);
136} 134}
@@ -261,7 +259,7 @@ int luaV_lessthan (lua_State *L, TObject *l, TObject *r) {
261 else if (ttype(l) == LUA_T_STRING && ttype(r) == LUA_T_STRING) 259 else if (ttype(l) == LUA_T_STRING && ttype(r) == LUA_T_STRING)
262 return (luaV_strcomp(tsvalue(l), tsvalue(r)) < 0); 260 return (luaV_strcomp(tsvalue(l), tsvalue(r)) < 0);
263 else { 261 else {
264 /* update top and put arguments in correct order to call Tag Method */ 262 /* update top and put arguments in correct order to call TM */
265 if (l<r) /* are arguments in correct order? */ 263 if (l<r) /* are arguments in correct order? */
266 L->top = r+1; /* yes; 2nd is on top */ 264 L->top = r+1; /* yes; 2nd is on top */
267 else { /* no; exchange them */ 265 else { /* no; exchange them */
@@ -562,7 +560,7 @@ StkId luaV_execute (lua_State *L, const Closure *cl, const TProtoFunc *tf,
562 call_arith(L, top+1, IM_UNM); 560 call_arith(L, top+1, IM_UNM);
563 } 561 }
564 else 562 else
565 nvalue(top-1) = - nvalue(top-1); 563 nvalue(top-1) = -nvalue(top-1);
566 break; 564 break;
567 565
568 case NOTOP: 566 case NOTOP:
diff --git a/lvm.h b/lvm.h
index 14b83bb7..391d90ab 100644
--- a/lvm.h
+++ b/lvm.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lvm.h,v 1.15 2000/01/24 20:14:07 roberto Exp roberto $ 2** $Id: lvm.h,v 1.16 2000/02/22 18:12:46 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*/
@@ -13,8 +13,8 @@
13#include "ltm.h" 13#include "ltm.h"
14 14
15 15
16#define tonumber(o) ((ttype(o) != LUA_T_NUMBER) && (luaV_tonumber(o) != 0)) 16#define tonumber(o) ((ttype(o) != LUA_T_NUMBER) && (luaV_tonumber(o) != 0))
17#define tostring(L, o) ((ttype(o) != LUA_T_STRING) && (luaV_tostring(L, o) != 0)) 17#define tostring(L,o) ((ttype(o) != LUA_T_STRING) && (luaV_tostring(L, o) != 0))
18 18
19 19
20void luaV_pack (lua_State *L, StkId firstel, int nvararg, TObject *tab); 20void luaV_pack (lua_State *L, StkId firstel, int nvararg, TObject *tab);
diff --git a/lzio.c b/lzio.c
index 48269ca7..7a05dba4 100644
--- a/lzio.c
+++ b/lzio.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lzio.c,v 1.9 1999/11/09 17:59:35 roberto Exp roberto $ 2** $Id: lzio.c,v 1.10 2000/02/08 16:39:42 roberto Exp roberto $
3** a generic input stream interface 3** a generic input stream interface
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -24,7 +24,7 @@ static int zmfilbuf (ZIO* z) {
24ZIO* zmopen (ZIO* z, const char* b, int size, const char *name) { 24ZIO* zmopen (ZIO* z, const char* b, int size, const char *name) {
25 if (b==NULL) return NULL; 25 if (b==NULL) return NULL;
26 z->n = size; 26 z->n = size;
27 z->p = (unsigned const char *)b; 27 z->p = (const unsigned char *)b;
28 z->filbuf = zmfilbuf; 28 z->filbuf = zmfilbuf;
29 z->u = NULL; 29 z->u = NULL;
30 z->name = name; 30 z->name = name;
@@ -69,7 +69,7 @@ int zread (ZIO *z, void *b, int n) {
69 if (z->n == 0) { 69 if (z->n == 0) {
70 if (z->filbuf(z) == EOZ) 70 if (z->filbuf(z) == EOZ)
71 return n; /* return number of missing bytes */ 71 return n; /* return number of missing bytes */
72 zungetc(z); /* put result from 'filbuf' in the buffer */ 72 zungetc(z); /* put result from `filbuf' in the buffer */
73 } 73 }
74 m = (n <= z->n) ? n : z->n; /* min. between n and z->n */ 74 m = (n <= z->n) ? n : z->n; /* min. between n and z->n */
75 memcpy(b, z->p, m); 75 memcpy(b, z->p, m);