Browse Source

many details (most by lhf).

Roberto Ierusalimschy 25 năm trước cách đây
mục cha
commit
3c9d999424
32 tập tin đã thay đổi với 280 bổ sung293 xóa
  1. 20 19
      lapi.c
  2. 2 2
      lapi.h
  3. 6 2
      lbuffer.c
  4. 32 21
      lbuiltin.c
  5. 25 26
      lbuiltin.h
  6. 2 2
      lcode.c
  7. 6 2
      ldblib.c
  8. 2 2
      ldebug.c
  9. 5 5
      ldo.c
  10. 2 2
      lfunc.c
  11. 5 8
      liolib.c
  12. 9 9
      llex.c
  13. 6 5
      llex.h
  14. 9 8
      lmem.c
  15. 2 2
      lobject.c
  16. 15 20
      lobject.h
  17. 9 6
      lopcodes.h
  18. 5 5
      lparser.c
  19. 6 6
      lparser.h
  20. 5 4
      lref.c
  21. 2 2
      lstring.c
  22. 3 3
      lstring.h
  23. 23 23
      lstrlib.c
  24. 2 2
      ltable.c
  25. 2 2
      ltm.c
  26. 3 4
      ltm.h
  27. 9 15
      lua.c
  28. 48 70
      lundump.c
  29. 2 1
      lundump.h
  30. 7 9
      lvm.c
  31. 3 3
      lvm.h
  32. 3 3
      lzio.c

+ 20 - 19
lapi.c

@@ -1,5 +1,5 @@
 /*
-** $Id: lapi.c,v 1.71 2000/02/08 16:34:31 roberto Exp roberto $
+** $Id: lapi.c,v 1.72 2000/02/22 17:54:16 roberto Exp roberto $
 ** Lua API
 ** See Copyright Notice in lua.h
 */
@@ -41,9 +41,10 @@ const TObject *luaA_protovalue (const TObject *o) {
 }
 
 
-void luaA_checkCparams (lua_State *L, int nParams) {
-  if (nParams > L->top-L->Cstack.base)
-    lua_error(L, "API error - wrong number of arguments in C2lua stack");
+void luaA_checkCargs (lua_State *L, int nargs) {
+  if (nargs > L->top-L->Cstack.base)
+    luaL_verror(L, "Lua API error - "
+                   "expected at least %d arguments in C2lua stack", nargs);
 }
 
 
@@ -70,7 +71,7 @@ static void top2LC (lua_State *L, int n) {
 
 
 lua_Object lua_pop (lua_State *L) {
-  luaA_checkCparams(L, 1);
+  luaA_checkCargs(L, 1);
   return luaA_putObjectOnTop(L);
 }
 
@@ -103,10 +104,10 @@ lua_Object lua_gettagmethod (lua_State *L, int tag, const char *event) {
 
 lua_Object lua_settagmethod (lua_State *L, int tag, const char *event) {
   TObject *method;
-  luaA_checkCparams(L, 1);
+  luaA_checkCargs(L, 1);
   method = L->top-1;
   if ((ttype(method) != LUA_T_NIL) && (*lua_type(L, method) != 'f'))
-    lua_error(L, "API error - tag method must be a function or nil");
+    lua_error(L, "Lua API error - tag method must be a function or nil");
   luaT_settagmethod(L, tag, event, method);
   return luaA_putObjectOnTop(L);
 }
@@ -114,7 +115,7 @@ lua_Object lua_settagmethod (lua_State *L, int tag, const char *event) {
 
 lua_Object lua_seterrormethod (lua_State *L) {
   lua_Object temp;
-  luaA_checkCparams(L, 1);
+  luaA_checkCargs(L, 1);
   temp = lua_getglobal(L, "_ERRORMESSAGE");
   lua_setglobal(L, "_ERRORMESSAGE");
   return temp;
@@ -122,7 +123,7 @@ lua_Object lua_seterrormethod (lua_State *L) {
 
 
 lua_Object lua_gettable (lua_State *L) {
-  luaA_checkCparams(L, 2);
+  luaA_checkCargs(L, 2);
   luaV_gettable(L, L->top--);
   return luaA_putObjectOnTop(L);
 }
@@ -130,7 +131,7 @@ lua_Object lua_gettable (lua_State *L) {
 
 lua_Object lua_rawgettable (lua_State *L) {
   lua_Object res;
-  luaA_checkCparams(L, 2);
+  luaA_checkCargs(L, 2);
   if (ttype(L->top-2) != LUA_T_ARRAY)
     lua_error(L, "indexed expression not a table in rawgettable");
   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) {
 
 void lua_settable (lua_State *L) {
   StkId top;
-  luaA_checkCparams(L, 3);
+  luaA_checkCargs(L, 3);
   top = L->top;
   luaV_settable(L, top-3, top);
   L->top = top-3;  /* pop table, index, and value */
@@ -149,7 +150,7 @@ void lua_settable (lua_State *L) {
 
 
 void lua_rawsettable (lua_State *L) {
-  luaA_checkCparams(L, 3);
+  luaA_checkCargs(L, 3);
   luaV_rawsettable(L, L->top-3);
 }
 
@@ -176,14 +177,14 @@ lua_Object lua_rawgetglobal (lua_State *L, const char *name) {
 
 
 void lua_setglobal (lua_State *L, const char *name) {
-  luaA_checkCparams(L, 1);
+  luaA_checkCargs(L, 1);
   luaV_setglobal(L, luaS_assertglobalbyname(L, name), L->top--);
 }
 
 
 void lua_rawsetglobal (lua_State *L, const char *name) {
   GlobalVar *gv = luaS_assertglobalbyname(L, name);
-  luaA_checkCparams(L, 1);
+  luaA_checkCargs(L, 1);
   gv->value = *(--L->top);
 }
 
@@ -296,8 +297,8 @@ void lua_pushstring (lua_State *L, const char *s) {
 
 void lua_pushcclosure (lua_State *L, lua_CFunction fn, int n) {
   if (fn == NULL)
-    lua_error(L, "API error - attempt to push a NULL Cfunction");
-  luaA_checkCparams(L, n);
+    lua_error(L, "Lua API error - attempt to push a NULL Cfunction");
+  luaA_checkCargs(L, n);
   ttype(L->top) = LUA_T_CPROTO;
   fvalue(L->top) = fn;
   incr_top;
@@ -321,7 +322,7 @@ void luaA_pushobject (lua_State *L, const TObject *o) {
 
 void lua_pushobject (lua_State *L, lua_Object o) {
   if (o == LUA_NOOBJECT)
-    lua_error(L, "API error - attempt to push a NOOBJECT");
+    lua_error(L, "Lua API error - attempt to push a NOOBJECT");
   *L->top = *o;
   incr_top;
 }
@@ -339,7 +340,7 @@ int lua_tag (lua_State *L, lua_Object o) {
 
 
 void lua_settag (lua_State *L, int tag) {
-  luaA_checkCparams(L, 1);
+  luaA_checkCargs(L, 1);
   luaT_realtag(L, tag);
   switch (ttype(L->top-1)) {
     case LUA_T_ARRAY:
@@ -406,7 +407,7 @@ int luaA_next (lua_State *L, const Hash *t, int i) {
 
 int lua_next (lua_State *L, lua_Object t, int i) {
   if (ttype(t) != LUA_T_ARRAY)
-    lua_error(L, "API error - object is not a table in `lua_next'"); 
+    lua_error(L, "Lua API error - object is not a table in `lua_next'"); 
   i = luaA_next(L, avalue(t), i);
   top2LC(L, (i==0) ? 0 : 2);
   return i;

+ 2 - 2
lapi.h

@@ -1,5 +1,5 @@
 /*
-** $Id: lapi.h,v 1.12 1999/12/23 18:19:57 roberto Exp roberto $
+** $Id: lapi.h,v 1.13 2000/01/19 12:00:45 roberto Exp roberto $
 ** Auxiliary functions from Lua API
 ** See Copyright Notice in lua.h
 */
@@ -11,7 +11,7 @@
 #include "lobject.h"
 
 
-void luaA_checkCparams (lua_State *L, int nParams);
+void luaA_checkCargs (lua_State *L, int nargs);
 const TObject *luaA_protovalue (const TObject *o);
 void luaA_pushobject (lua_State *L, const TObject *o);
 GlobalVar *luaA_nextvar (lua_State *L, TaggedString *g);

+ 6 - 2
lbuffer.c

@@ -1,5 +1,5 @@
 /*
-** $Id: lbuffer.c,v 1.10 1999/11/10 15:40:46 roberto Exp roberto $
+** $Id: lbuffer.c,v 1.11 1999/11/22 13:12:07 roberto Exp roberto $
 ** Auxiliary functions for building Lua libraries
 ** See Copyright Notice in lua.h
 */
@@ -19,10 +19,14 @@
 -------------------------------------------------------*/
 
 
+/*
+** amount of extra space (pre)allocated when buffer is reallocated
+*/
 #define EXTRABUFF	32
 
 
-#define openspace(L, size)  if (L->Mbuffnext+(size) > L->Mbuffsize) Openspace(L, size)
+#define openspace(L, size)  if (L->Mbuffnext+(size) > L->Mbuffsize) \
+                              Openspace(L, size)
 
 static void Openspace (lua_State *L, int size) {
   L->Mbuffsize = (L->Mbuffnext+size+EXTRABUFF)*2;

+ 32 - 21
lbuiltin.c

@@ -1,10 +1,19 @@
 /*
-** $Id: lbuiltin.c,v 1.92 2000/01/19 16:50:30 roberto Exp roberto $
+** $Id: lbuiltin.c,v 1.93 2000/02/22 18:12:46 roberto Exp roberto $
 ** Built-in functions
 ** See Copyright Notice in lua.h
 */
 
 
+/*
+** =========================================================================
+** All built-in functions are public (i.e. not static) and are named luaB_f,
+** where f is the function name in Lua. So, if you do not need all these
+** functions, you may register manually only the ones that you need.
+** =========================================================================
+*/
+
+
 #include <ctype.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -91,7 +100,7 @@ static Hash *gettable (lua_State *L, int arg) {
 
 
 /*
-** If your system does not support "stderr", redefine this function, or
+** If your system does not support `stderr', redefine this function, or
 ** redefine _ERRORMESSAGE so that it won't need _ALERT.
 */
 void luaB__ALERT (lua_State *L) {
@@ -116,9 +125,9 @@ void luaB__ERRORMESSAGE (lua_State *L) {
 
 
 /*
-** If your system does not support "stdout", you can just remove this function.
-** If you need, you can define your own "print" function, following this
-** model but changing "fputs" to put the strings at a proper place
+** If your system does not support `stdout', you can just remove this function.
+** If you need, you can define your own `print' function, following this
+** model but changing `fputs' to put the strings at a proper place
 ** (a console window or a log file, for instance).
 */
 #ifndef MAXPRINT
@@ -174,17 +183,17 @@ void luaB_error (lua_State *L) {
 }
 
 void luaB_setglobal (lua_State *L) {
-  const char *n = luaL_check_string(L, 1);
+  const char *name = luaL_check_string(L, 1);
   lua_Object value = luaL_nonnullarg(L, 2);
   lua_pushobject(L, value);
-  lua_setglobal(L, n);
+  lua_setglobal(L, name);
 }
 
 void luaB_rawsetglobal (lua_State *L) {
-  const char *n = luaL_check_string(L, 1);
+  const char *name = luaL_check_string(L, 1);
   lua_Object value = luaL_nonnullarg(L, 2);
   lua_pushobject(L, value);
-  lua_rawsetglobal(L, n);
+  lua_rawsetglobal(L, name);
 }
 
 void luaB_getglobal (lua_State *L) {
@@ -236,7 +245,7 @@ void luaB_settagmethod (lua_State *L) {
                  "function or nil expected");
 #ifndef LUA_COMPAT_GC
   if (strcmp(event, "gc") == 0 && tag != LUA_T_NIL)
-    lua_error(L, "cannot set this tag method from Lua");
+    lua_error(L, "cannot set this `gc' tag method from Lua");
 #endif
   lua_pushobject(L, nf);
   lua_pushobject(L, lua_settagmethod(L, tag, event));
@@ -325,7 +334,7 @@ void luaB_call (lua_State *L) {
       return;  /* return nil to signal the error */
     }
     else
-      lua_error(L, NULL);
+      lua_error(L, NULL);  /* propagate error without additional messages */
   }
   else {  /* no errors */
     if (strchr(options, 'p')) {  /* pack results? */
@@ -340,14 +349,14 @@ void luaB_call (lua_State *L) {
 
 void luaB_nextvar (lua_State *L) {
   lua_Object o = luaL_nonnullarg(L, 1);
-  TaggedString *g;
+  TaggedString *name;
   if (ttype(o) == LUA_T_NIL)
-    g = NULL;
+    name = NULL;
   else {
     luaL_arg_check(L, ttype(o) == LUA_T_STRING, 1, "variable name expected");
-    g = tsvalue(o);
+    name = tsvalue(o);
   }
-  if (!luaA_nextvar(L, g))
+  if (!luaA_nextvar(L, name))
     lua_pushnil(L);
 }
 
@@ -355,7 +364,7 @@ void luaB_nextvar (lua_State *L) {
 void luaB_next (lua_State *L) {
   const Hash *a = gettable(L, 1);
   lua_Object k = luaL_nonnullarg(L, 2);
-  int i;  /* will get first element after `i' */
+  int i;  /* `luaA_next' gets first element after `i' */
   if (ttype(k) == LUA_T_NIL)
     i = 0;  /* get first */
   else {
@@ -390,7 +399,8 @@ void luaB_tostring (lua_State *L) {
       sprintf(buff, "function: %p", o->value.f);
       break;
     case LUA_T_USERDATA:
-      sprintf(buff, "userdata: %p", o->value.ts->u.d.value);
+      sprintf(buff, "userdata: %p(%d)", o->value.ts->u.d.value,
+                                        o->value.ts->u.d.tag);
       break;
     case LUA_T_NIL:
       lua_pushstring(L, "nil");
@@ -435,7 +445,7 @@ void luaB_foreachi (lua_State *L) {
     luaD_call(L, L->top-3, 1);
     if (ttype(L->top-1) != LUA_T_NIL)
       return;
-    L->top--;
+    L->top--;  /* remove nil result */
   }
 }
 
@@ -499,7 +509,7 @@ void luaB_tinsert (lua_State *L) {
     pos = n+1;
   }
   luaV_setn(L, a, n+1);  /* a.n = n+1 */
-  for ( ;n>=pos; n--)
+  for (; n>=pos; n--)
     luaH_move(L, a, n, n+1);  /* a[n+1] = a[n] */
   luaH_setint(L, a, pos, v);  /* a[pos] = v */
 }
@@ -521,6 +531,7 @@ void luaB_tremove (lua_State *L) {
 /*
 ** {======================================================
 ** Quicksort
+** (based on `Algorithms in MODULA-3', Robert Sedgewick; Addison-Wesley, 1993.)
 */
 
 static void swap (lua_State *L, Hash *a, int i, int j) {
@@ -602,7 +613,7 @@ void luaB_sort (lua_State *L) {
   lua_Object func = lua_getparam(L, 2);
   luaL_arg_check(L, func == LUA_NOOBJECT || lua_isfunction(L, func), 2,
                  "function expected");
-  luaD_checkstack(L, 4);  /* for Pivot, f, a, b (sort_comp) */
+  luaD_checkstack(L, 4);  /* for pivot, f, a, b (sort_comp) */
   auxsort(L, a, 1, n, func);
   lua_pushobject(L, t);
 }
@@ -640,7 +651,7 @@ static const struct luaL_reg builtin_funcs[] = {
   {"tonumber", luaB_tonumber},
   {"tostring", luaB_tostring},
   {"type", luaB_type},
-  /* "Extra" functions */
+/* "Extra" functions */
   {"assert", luaB_assert},
   {"foreach", luaB_foreach},
   {"foreachi", luaB_foreachi},

+ 25 - 26
lbuiltin.h

@@ -1,5 +1,5 @@
 /*
-** $Id: lbuiltin.h,v 1.4 1999/12/27 17:33:22 roberto Exp roberto $
+** $Id: lbuiltin.h,v 1.5 1999/12/28 19:23:41 roberto Exp roberto $
 ** Built-in functions
 ** See Copyright Notice in lua.h
 */
@@ -11,39 +11,38 @@
 
 void luaB__ALERT (lua_State *L);
 void luaB__ERRORMESSAGE (lua_State *L);
-void luaB_print (lua_State *L);
-void luaB_tonumber (lua_State *L);
+void luaB_assert (lua_State *L);
+void luaB_call (lua_State *L);
+void luaB_collectgarbage (lua_State *L);
+void luaB_copytagmethods (lua_State *L);
+void luaB_dofile (lua_State *L);
+void luaB_dostring (lua_State *L);
 void luaB_error (lua_State *L);
-void luaB_setglobal (lua_State *L);
-void luaB_rawsetglobal (lua_State *L);
+void luaB_foreach (lua_State *L);
+void luaB_foreachi (lua_State *L);
+void luaB_foreachvar (lua_State *L);
 void luaB_getglobal (lua_State *L);
-void luaB_rawgetglobal (lua_State *L);
-void luaB_tag (lua_State *L);
-void luaB_settag (lua_State *L);
+void luaB_getn (lua_State *L);
+void luaB_gettagmethod (lua_State *L);
 void luaB_newtag (lua_State *L);
-void luaB_copytagmethods (lua_State *L);
+void luaB_next (lua_State *L);
+void luaB_nextvar (lua_State *L);
+void luaB_print (lua_State *L);
+void luaB_rawgetglobal (lua_State *L);
 void luaB_rawgettable (lua_State *L);
+void luaB_rawsetglobal (lua_State *L);
 void luaB_rawsettable (lua_State *L);
-void luaB_settagmethod (lua_State *L);
-void luaB_gettagmethod (lua_State *L);
 void luaB_seterrormethod (lua_State *L);
-void luaB_collectgarbage (lua_State *L);
-void luaB_type (lua_State *L);
-void luaB_dostring (lua_State *L);
-void luaB_dofile (lua_State *L);
-void luaB_call (lua_State *L);
-void luaB_nextvar (lua_State *L);
-void luaB_next (lua_State *L);
-void luaB_tostring (lua_State *L);
-void luaB_assert (lua_State *L);
-void luaB_foreachi (lua_State *L);
-void luaB_foreach (lua_State *L);
-void luaB_foreachvar (lua_State *L);
-void luaB_getn (lua_State *L);
+void luaB_setglobal (lua_State *L);
+void luaB_settag (lua_State *L);
+void luaB_settagmethod (lua_State *L);
+void luaB_sort (lua_State *L);
+void luaB_tag (lua_State *L);
 void luaB_tinsert (lua_State *L);
+void luaB_tonumber (lua_State *L);
+void luaB_tostring (lua_State *L);
 void luaB_tremove (lua_State *L);
-void luaB_sort (lua_State *L);
-
+void luaB_type (lua_State *L);
 
 void luaB_predefine (lua_State *L);
 

+ 2 - 2
lcode.c

@@ -1,5 +1,5 @@
 /*
-** $Id: lcode.c,v 1.1 2000/02/22 13:30:11 roberto Exp roberto $
+** $Id: lcode.c,v 1.2 2000/03/03 12:33:59 roberto Exp roberto $
 ** Code generator for Lua
 ** See Copyright Notice in lua.h
 */
@@ -152,7 +152,7 @@ int luaK_kstr (LexState *ls, int c) {
 #endif
 
 static int real_constant (LexState *ls, real r) {
-  /* check whether `r' has appeared within the last LIM entries */
+  /* check whether `r' has appeared within the last LOOKBACKNUMS entries */
   TProtoFunc *f = ls->fs->f;
   int c = f->nknum;
   int lim = c < LOOKBACKNUMS ? 0 : c-LOOKBACKNUMS;

+ 6 - 2
ldblib.c

@@ -1,5 +1,5 @@
 /*
-** $Id: ldblib.c,v 1.9 1999/12/21 18:04:41 roberto Exp roberto $
+** $Id: ldblib.c,v 1.10 2000/01/19 12:00:45 roberto Exp roberto $
 ** Interface from Lua to its debug API
 ** See Copyright Notice in lua.h
 */
@@ -50,7 +50,7 @@ static void getstack (lua_State *L) {
     lua_Object res = lua_createtable(L);
     if (!lua_getinfo(L, options, &ar))
       luaL_argerror(L, 2, "invalid option");
-    for ( ;*options; options++) {
+    for (; *options; options++) {
       switch (*options) {
         case 'S':
           settabss(L, res, "source", ar.source);
@@ -103,6 +103,10 @@ static void setlocal (lua_State *L) {
 }
 
 
+/*
+** because of these variables, this module is not reentrant, and should
+** not be used in multiple states
+*/
 
 static int linehook = LUA_NOREF;  /* Lua reference to line hook function */
 static int callhook = LUA_NOREF;  /* Lua reference to call hook function */

+ 2 - 2
ldebug.c

@@ -1,5 +1,5 @@
 /*
-** $Id: ldebug.c,v 1.8 2000/02/11 16:52:54 roberto Exp roberto $
+** $Id: ldebug.c,v 1.9 2000/02/17 18:30:36 roberto Exp roberto $
 ** Debug Interface
 ** See Copyright Notice in lua.h
 */
@@ -187,7 +187,7 @@ static void lua_getobjname (lua_State *L, StkId f, lua_Dbgactreg *ar) {
 int lua_getinfo (lua_State *L, const char *what, lua_Dbgactreg *ar) {
   StkId func = ar->_func;
   LUA_ASSERT(L, is_T_MARK(ttype(func)), "invalid activation record");
-  for ( ;*what; what++) {
+  for (; *what; what++) {
     switch (*what) {
       case 'S':
         lua_funcinfo(ar);

+ 5 - 5
ldo.c

@@ -1,5 +1,5 @@
 /*
-** $Id: ldo.c,v 1.66 2000/01/19 12:00:45 roberto Exp roberto $
+** $Id: ldo.c,v 1.67 2000/02/08 16:34:31 roberto Exp roberto $
 ** Stack and Call structure of Lua
 ** See Copyright Notice in lua.h
 */
@@ -52,7 +52,7 @@ void luaD_checkstack (lua_State *L, int n) {
     if (L->stack_last-L->stack > (L->stacksize-1)) {
       /* overflow while handling overflow: do what?? */
       L->top -= EXTRA_STACK;
-      lua_error(L, "BAD STACK OVERFLOW! DATA CORRUPTED!!");
+      lua_error(L, "BAD STACK OVERFLOW! DATA CORRUPTED!");
     }
     else {
       lua_Dbgactreg dummy;
@@ -62,7 +62,7 @@ void luaD_checkstack (lua_State *L, int n) {
         lua_error(L, "Lua2C - C2Lua overflow");
       }
       else
-        lua_error(L, "stack size overflow");
+        lua_error(L, "stack overflow; possible recursion loop");
     }
   }
 }
@@ -254,7 +254,7 @@ void lua_error (lua_State *L, const char *s) {
   if (L->errorJmp)
     longjmp(L->errorJmp->b, 1);
   else {
-    message(L, "unable to recover. exiting.\n");
+    message(L, "unable to recover; exiting\n");
     exit(1);
   }
 }
@@ -301,7 +301,7 @@ static int protectedparser (lua_State *L, ZIO *z, int bin) {
   TProtoFunc *volatile tf;
   struct lua_longjmp *volatile oldErr = L->errorJmp;
   L->errorJmp = &myErrorJmp;
-  L->top = base;   /* erase C2Lua */
+  L->top = base;   /* clear C2Lua */
   if (setjmp(myErrorJmp.b) == 0) {
     tf = bin ? luaU_undump1(L, z) : luaY_parser(L, z);
     status = 0;

+ 2 - 2
lfunc.c

@@ -1,5 +1,5 @@
 /*
-** $Id: lfunc.c,v 1.17 2000/01/25 13:57:18 roberto Exp roberto $
+** $Id: lfunc.c,v 1.18 2000/01/28 16:53:00 roberto Exp roberto $
 ** Auxiliary functions to manipulate prototypes and closures
 ** See Copyright Notice in lua.h
 */
@@ -14,7 +14,7 @@
 #include "lstate.h"
 
 #define gcsizeproto(L, p)	numblocks(L, 0, sizeof(TProtoFunc))
-#define gcsizeclosure(L, c) numblocks(L, c->nelems, sizeof(Closure))
+#define gcsizeclosure(L, c)	numblocks(L, c->nelems, sizeof(Closure))
 
 
 

+ 5 - 8
liolib.c

@@ -1,5 +1,5 @@
 /*
-** $Id: liolib.c,v 1.56 2000/01/19 12:00:45 roberto Exp roberto $
+** $Id: liolib.c,v 1.57 2000/02/08 16:34:31 roberto Exp roberto $
 ** Standard I/O (and system) library
 ** See Copyright Notice in lua.h
 */
@@ -97,7 +97,7 @@ static FILE *gethandle (lua_State *L, lua_Object f) {
 static FILE *getfilebyname (lua_State *L, const char *name) {
   FILE *handle = gethandle(L, lua_rawgetglobal(L, name));
   if (!handle)
-    luaL_verror(L, "global variable `%.50s' is not a file handle", name);
+    luaL_verror(L, "`%.50s' is not a file handle", name);
   return handle;
 }
 
@@ -286,7 +286,7 @@ static int read_pattern (lua_State *L, FILE *f, const char *p) {
 
 #else
 
-#define read_pattern(L, f,p)   (lua_error(L, "read patterns are deprecated"), 0)
+#define read_pattern(L, f, p) (lua_error(L, "read patterns are deprecated"), 0)
 
 #endif
 
@@ -525,9 +525,6 @@ static void io_debug (lua_State *L) {
 #define MAXMESSAGE (MESSAGESIZE*10)
 
 
-#define MAXSRC		60
-
-
 static void errorfb (lua_State *L) {
   char buff[MAXMESSAGE];
   int level = 1;  /* skip level 0 (it's this function) */
@@ -535,10 +532,10 @@ static void errorfb (lua_State *L) {
   lua_Object alertfunc = lua_rawgetglobal(L, "_ALERT");
   sprintf(buff, "error: %.200s\n", lua_getstring(L, lua_getparam(L, 1)));
   while (lua_getstack(L, level++, &ar)) {
-    char buffchunk[MAXSRC];
+    char buffchunk[60];
     lua_getinfo(L, "Snl", &ar);
     luaL_chunkid(buffchunk, ar.source, sizeof(buffchunk));
-    if (level == 2) strcat(buff, "Active Stack:\n");
+    if (level == 2) strcat(buff, "Stack traceback:\n");
     strcat(buff, "  ");
     if (strlen(buff) > MAXMESSAGE-MESSAGESIZE) {
       strcat(buff, "...\n");

+ 9 - 9
llex.c

@@ -1,5 +1,5 @@
 /*
-** $Id: llex.c,v 1.50 2000/01/26 18:51:49 roberto Exp roberto $
+** $Id: llex.c,v 1.51 2000/02/08 16:34:31 roberto Exp roberto $
 ** Lexical Analyzer
 ** See Copyright Notice in lua.h
 */
@@ -23,7 +23,7 @@
 
 
 
-#define next(LS) (LS->current = zgetc(LS->lex_z))
+#define next(LS) (LS->current = zgetc(LS->z))
 
 
 #define save(L, c)	luaL_addchar(L, c)
@@ -37,7 +37,7 @@ static const char *const token2string [] = {"and", "do", "else", "elseif", "end"
 
 
 void luaX_init (lua_State *L) {
-  unsigned int i;
+  int i;
   for (i=0; i<NUM_RESERVED; i++) {
     TaggedString *ts = luaS_new(L, token2string[i]);
     ts->marked = (unsigned char)(RESERVEDMARK+i);  /* reserved word */
@@ -49,7 +49,7 @@ void luaX_init (lua_State *L) {
 
 void luaX_syntaxerror (LexState *ls, const char *s, const char *token) {
   char buff[MAXSRC];
-  luaL_chunkid(buff, zname(ls->lex_z), sizeof(buff));
+  luaL_chunkid(buff, zname(ls->z), sizeof(buff));
   luaL_verror(ls->L, "%.100s;\n  last token read: `%.50s' at line %d in %.80s",
               s, token, ls->linenumber, buff);
 }
@@ -86,10 +86,10 @@ static void luaX_invalidchar (LexState *ls, int c) {
 
 static void firstline (LexState *LS)
 {
-  int c = zgetc(LS->lex_z);
+  int c = zgetc(LS->z);
   if (c == '#')
-    while ((c=zgetc(LS->lex_z)) != '\n' && c != EOZ) /* skip first line */;
-  zungetc(LS->lex_z);
+    while ((c=zgetc(LS->z)) != '\n' && c != EOZ) /* skip first line */;
+  zungetc(LS->z);
 }
 
 
@@ -100,7 +100,7 @@ void luaX_setinput (lua_State *L, LexState *LS, ZIO *z) {
   LS->iflevel = 0;
   LS->ifstate[0].skip = 0;
   LS->ifstate[0].elsepart = 1;  /* to avoid a free $else */
-  LS->lex_z = z;
+  LS->z = z;
   LS->fs = NULL;
   firstline(LS);
   luaL_resetbuffer(L);
@@ -322,7 +322,7 @@ int luaX_lex (LexState *LS) {
   for (;;) {
     switch (LS->current) {
 
-      case ' ': case '\t': case '\r':  /* CR: to avoid problems with DOS */
+      case ' ': case '\t': case '\r':  /* `\r' to avoid problems with DOS */
         next(LS);
         continue;
 

+ 6 - 5
llex.h

@@ -1,5 +1,5 @@
 /*
-** $Id: llex.h,v 1.17 2000/01/25 18:44:21 roberto Exp roberto $
+** $Id: llex.h,v 1.18 2000/02/08 16:34:31 roberto Exp roberto $
 ** Lexical Analyzer
 ** See Copyright Notice in lua.h
 */
@@ -11,7 +11,7 @@
 #include "lzio.h"
 
 
-#define FIRST_RESERVED	260
+#define FIRST_RESERVED	257
 
 /* maximum length of a reserved word (+1 for final 0) */
 #define TOKEN_LEN	15
@@ -30,7 +30,8 @@ enum RESERVED {
   NAME, CONC, DOTS, EQ, GE, LE, NE, NUMBER, STRING, EOS
 };
 
-#define NUM_RESERVED	(WHILE-FIRST_RESERVED+1)  /* number of reserved words */
+/* number of reserved words */
+#define NUM_RESERVED	((int)(WHILE-FIRST_RESERVED+1))
 
 
 #ifndef MAX_IFS
@@ -49,13 +50,13 @@ struct ifState {
 typedef struct LexState {
   int current;  /* look ahead character */
   int token;  /* look ahead token */
-  struct FuncState *fs;  /* `FuncState' is private for the parser */
+  struct FuncState *fs;  /* `FuncState' is private to the parser */
   struct lua_State *L;
   union {
     real r;
     TaggedString *ts;
   } seminfo;  /* semantics information */
-  struct zio *lex_z;  /* input stream */
+  struct zio *z;  /* input stream */
   int linenumber;  /* input line counter */
   int iflevel;  /* level of nested $if's (for lexical analysis) */
   struct ifState ifstate[MAX_IFS];

+ 9 - 8
lmem.c

@@ -1,5 +1,5 @@
 /*
-** $Id: lmem.c,v 1.24 2000/01/13 16:30:47 roberto Exp roberto $
+** $Id: lmem.c,v 1.25 2000/02/08 16:34:31 roberto Exp roberto $
 ** Interface to Memory Manager
 ** See Copyright Notice in lua.h
 */
@@ -43,7 +43,9 @@
 #define free(b)		debug_realloc(b, 0)
 
 
-#define HEADER		(sizeof(double))  /* maximum alignment */
+/* ensures maximum alignment for HEADER */
+#define HEADER	(sizeof(double)>sizeof(long) ? sizeof(double) : sizeof(long))
+
 #define MARKSIZE	16
 #define MARK		0x55  /* 01010101 (a nice pattern) */
 
@@ -77,21 +79,21 @@ static void freeblock (void *block) {
 
 
 static void *debug_realloc (void *block, size_t size) {
-  size_t realsize = HEADER+size+MARKSIZE;
   if (size == 0) {
     freeblock(block);
     return NULL;
   }
   else {
+    size_t realsize = HEADER+size+MARKSIZE;
     char *newblock = (char *)(malloc)(realsize);  /* alloc a new block */
     int i;
+    if (newblock == NULL) return NULL;
     if (block) {
       size_t oldsize = *blocksize(block);
       if (oldsize > size) oldsize = size;
       memcpy(newblock+HEADER, block, oldsize);
       freeblock(block);  /* erase (and check) old copy */
     }
-    if (newblock == NULL) return NULL;
     memdebug_total += size;
     memdebug_numblocks++;
     *(unsigned long *)newblock = size;
@@ -123,14 +125,13 @@ void *luaM_growaux (lua_State *L, void *block, unsigned long nelems,
 ** generic allocation routine.
 */
 void *luaM_realloc (lua_State *L, void *block, unsigned long size) {
-  size_t s = (size_t)size;
-  if (s != size)
-    lua_error(L, "memory allocation error: block too big");
   if (size == 0) {
     free(block);  /* block may be NULL; that is OK for free */
     return NULL;
   }
-  block = realloc(block, s);
+  else if ((size_t)size != size)
+    lua_error(L, "memory allocation error: block too big");
+  block = realloc(block, size);
   if (block == NULL)
     lua_error(L, memEM);
   return block;

+ 2 - 2
lobject.c

@@ -1,5 +1,5 @@
 /*
-** $Id: lobject.c,v 1.30 2000/01/25 18:44:21 roberto Exp roberto $
+** $Id: lobject.c,v 1.31 2000/02/17 18:30:36 roberto Exp roberto $
 ** Some generic functions over Lua objects
 ** See Copyright Notice in lua.h
 */
@@ -16,7 +16,7 @@
 const char *const luaO_typenames[] = { /* ORDER LUA_T */
     "userdata", "number", "string", "table", "function", "function", "nil",
     "function", "function", "function", "function", "function", "function",
-    "line", "global", "local", "field", NULL
+    "line", NULL
 };
 
 

+ 15 - 20
lobject.h

@@ -1,5 +1,5 @@
 /*
-** $Id: lobject.h,v 1.48 2000/02/17 18:30:36 roberto Exp roberto $
+** $Id: lobject.h,v 1.49 2000/02/21 18:33:26 roberto Exp roberto $
 ** Type definitions for Lua objects
 ** See Copyright Notice in lua.h
 */
@@ -14,15 +14,13 @@
 
 
 #ifdef DEBUG
-#ifdef NDEBUG
 #undef NDEBUG
-#endif
 #include <assert.h>
 #define LUA_INTERNALERROR(L,s)	assert(0)
 #define LUA_ASSERT(L,c,s)	assert(c)
 #else
 #define LUA_INTERNALERROR(L,s)	/* empty */
-#define LUA_ASSERT(L,c,s)		/* empty */
+#define LUA_ASSERT(L,c,s)	/* empty */
 #endif
 
 
@@ -51,7 +49,7 @@ typedef unsigned long Instruction;
 
 /* conversion of pointer to int (for hashing only) */
 /* (the shift removes bits that are usually 0 because of alignment) */
-#define IntPoint(L, p)	(((unsigned int)(p)) >> 3)
+#define IntPoint(L, p)	(((unsigned long)(p)) >> 3)
 
 
 /*
@@ -68,21 +66,21 @@ typedef unsigned long Instruction;
 ** grep "ORDER LUA_T"
 */
 typedef enum {
-  LUA_T_USERDATA =  0,  /* default tag for userdata */
-  LUA_T_NUMBER   = -1,  /* fixed tag for numbers */
-  LUA_T_STRING   = -2,  /* fixed tag for strings */
-  LUA_T_ARRAY    = -3,  /* default tag for tables (or arrays) */
-  LUA_T_LPROTO   = -4,  /* fixed tag for Lua functions */
-  LUA_T_CPROTO   = -5,  /* fixed tag for C functions */
-  LUA_T_NIL      = -6,  /* last "pre-defined" tag */
+  LUA_T_USERDATA  =  0, /* default tag for userdata */
+  LUA_T_NUMBER    = -1, /* fixed tag for numbers */
+  LUA_T_STRING    = -2, /* fixed tag for strings */
+  LUA_T_ARRAY     = -3, /* default tag for tables (or arrays) */
+  LUA_T_LPROTO    = -4, /* fixed tag for Lua functions */
+  LUA_T_CPROTO    = -5, /* fixed tag for C functions */
+  LUA_T_NIL       = -6, /* last "pre-defined" tag */
 
   LUA_T_LCLOSURE  = -7, /* Lua closure */
   LUA_T_CCLOSURE  = -8, /* C closure */
 
   LUA_T_LCLMARK   = -9 ,/* mark for Lua closures */
   LUA_T_CCLMARK   = -10,/* mark for C closures */
-  LUA_T_LMARK    = -11, /* mark for Lua prototypes */
-  LUA_T_CMARK    = -12, /* mark for C prototypes */
+  LUA_T_LMARK     = -11,/* mark for Lua prototypes */
+  LUA_T_CMARK     = -12,/* mark for C prototypes */
 
   LUA_T_LINE     = -13
 } lua_Type;
@@ -93,7 +91,7 @@ typedef enum {
 #define LAST_REGULAR_TAG  LUA_T_CCLOSURE  /* after that, are all marks */
 
 /*
-** chech whether `t' is a mark; ttypes are negative numbers, so the
+** check whether `t' is a mark; ttypes are negative numbers, so the
 ** comparisons look reversed.  (ORDER LUA_T)
 */
 #define is_T_MARK(t)	(LUA_T_CMARK <= (t) && (t) <= LUA_T_LCLMARK)
@@ -221,6 +219,7 @@ typedef struct Hash {
 
 
 extern const char *const luaO_typenames[];
+extern const TObject luaO_nilobject;
 
 #define luaO_typename(o)        luaO_typenames[-ttype(o)]
 
@@ -228,11 +227,7 @@ extern const char *const luaO_typenames[];
 
 unsigned long luaO_power2 (unsigned long n);
 
-extern const TObject luaO_nilobject;
-
-
-#define luaO_equalObj(t1,t2)	((ttype(t1) != ttype(t2)) ? 0 \
-                                      : luaO_equalval(t1,t2))
+#define luaO_equalObj(t1,t2)  (ttype(t1) == ttype(t2) && luaO_equalval(t1,t2))
 int luaO_equalval (const TObject *t1, const TObject *t2);
 int luaO_redimension (lua_State *L, int oldsize);
 int luaO_str2d (const char *s, real *result);

+ 9 - 6
lopcodes.h

@@ -1,5 +1,5 @@
 /*
-** $Id: lopcodes.h,v 1.41 2000/02/22 13:30:11 roberto Exp roberto $
+** $Id: lopcodes.h,v 1.42 2000/03/02 12:32:53 roberto Exp roberto $
 ** Opcodes for Lua virtual machine
 ** See Copyright Notice in lua.h
 */
@@ -21,9 +21,11 @@
           2nd unsigned argument in the middle 8 bits       (`B')
 
   The signed argument is represented in excess 2^23; that is, the real value
-  is 2^23 minus the usigned value.
+  is the usigned value minus 2^23.
 ===========================================================================*/
 
+#define EXCESS_S	(1<<23)		/* == 2^23 */
+
 /*
 ** the following macros help to manipulate instructions
 */
@@ -35,13 +37,13 @@
 
 #define GET_OPCODE(i)	((OpCode)((i)&0xFF))
 #define GETARG_U(i)	((int)((i)>>8))
-#define GETARG_S(i)	((int)((i)>>8)-(1<<23))
+#define GETARG_S(i)	((int)((i)>>8)-EXCESS_S)
 #define GETARG_A(i)	((int)((i)>>16))
 #define GETARG_B(i)	((int)(((i)>>8) & 0xFF))
 
 #define SET_OPCODE(i,o)	(((i)&0xFFFFFF00u) | (Instruction)(o))
 #define SETARG_U(i,u)	(((i)&0x000000FFu) | ((Instruction)(u)<<8))
-#define SETARG_S(i,s)	(((i)&0x000000FFu) | ((Instruction)((s)+(1<<23))<<8))
+#define SETARG_S(i,s)	(((i)&0x000000FFu) | ((Instruction)((s)+EXCESS_S)<<8))
 #define SETARG_A(i,a)	(((i)&0x0000FFFFu) | ((Instruction)(a)<<16))
 #define SETARG_B(i,b)	(((i)&0xFFFF00FFu) | ((Instruction)(b)<<8))
 
@@ -55,8 +57,9 @@
 */
 
 typedef enum {
-/* name          parm    before          after           side effect
------------------------------------------------------------------------------*/
+/*----------------------------------------------------------------------
+name		args	stack before	stack after	side effects
+------------------------------------------------------------------------*/
 ENDCODE,/*	-	-		(return)			*/
 RETCODE,/*	U	-		(return)			*/
 

+ 5 - 5
lparser.c

@@ -1,5 +1,5 @@
 /*
-** $Id: lparser.c,v 1.60 2000/02/22 13:30:11 roberto Exp roberto $
+** $Id: lparser.c,v 1.61 2000/03/03 12:33:59 roberto Exp roberto $
 ** LL(1) Parser and code generator for Lua
 ** See Copyright Notice in lua.h
 */
@@ -434,7 +434,7 @@ static int funcparams (LexState *ls, int slf) {
       break;
 
     case STRING:  /* funcparams -> STRING */
-      code_string(ls, ls->seminfo.ts);  /* must use 'seminfo' before `next' */
+      code_string(ls, ls->seminfo.ts);  /* must use `seminfo' before `next' */
       next(ls);
       break;
 
@@ -660,7 +660,7 @@ static void simpleexp (LexState *ls, expdesc *v) {
     }
 
     case STRING:  /* simpleexp -> STRING */
-      /* must use 'seminfo' before `next' */
+      /* must use `seminfo' before `next' */
       v->info = code_string(ls, ls->seminfo.ts);
       next(ls);
       break;
@@ -930,7 +930,7 @@ static void namestat (LexState *ls) {
   check_debugline(ls);
   var_or_func(ls, &v);
   if (v.k == VEXP) {  /* stat -> func */
-    if (!luaK_iscall(ls, v.info))  /* is just an upper value? */
+    if (!luaK_iscall(ls, v.info))  /* is just an upvalue? */
       luaK_error(ls, "syntax error");
     luaK_setcallreturns(ls, v.info, 0);  /* call statement uses no results */
   }
@@ -1006,7 +1006,7 @@ static int stat (LexState *ls) {
       return 1;
 
     case RETURN: case ';': case ELSE: case ELSEIF:
-    case END: case UNTIL: case EOS:  /* 'stat' follow */
+    case END: case UNTIL: case EOS:  /* `stat' follow */
       return 0;
 
     default:

+ 6 - 6
lparser.h

@@ -1,5 +1,5 @@
 /*
-** $Id: lparser.h,v 1.6 2000/02/22 13:30:11 roberto Exp roberto $
+** $Id: lparser.h,v 1.7 2000/03/03 12:33:59 roberto Exp roberto $
 ** LL(1) Parser and code generator for Lua
 ** See Copyright Notice in lua.h
 */
@@ -14,31 +14,31 @@
 
 /* maximum number of local variables */
 #ifndef MAXLOCALS
-#define MAXLOCALS 200  /* arbitrary limit (<=MAXARG_B) */
+#define MAXLOCALS 200		/* arbitrary limit (<=MAXARG_B) */
 #endif
 
 
 /* maximum number of upvalues */
 #ifndef MAXUPVALUES
-#define MAXUPVALUES 32  /* arbitrary limit (<=MAXARG_B) */
+#define MAXUPVALUES 32		/* arbitrary limit (<=MAXARG_B) */
 #endif
 
 
 /* maximum number of variables in the left side of an assignment */
 #ifndef MAXVARSLH
-#define MAXVARSLH	100  /* arbitrary limit (<=MAXARG_B) */
+#define MAXVARSLH 100		/* arbitrary limit (<=MAXARG_B) */
 #endif
 
 
 /* maximum number of parameters in a function */
 #ifndef MAXPARAMS
-#define MAXPARAMS	100  /* arbitrary limit (<=MAXLOCALS) */
+#define MAXPARAMS 100		/* arbitrary limit (<=MAXLOCALS) */
 #endif
 
 
 /* maximum stack size in a function */
 #ifndef MAXSTACK
-#define MAXSTACK	256  /* arbitrary limit (<=MAXARG_A) */
+#define MAXSTACK 256		/* arbitrary limit (<=MAXARG_A) */
 #endif
 
 

+ 5 - 4
lref.c

@@ -1,5 +1,5 @@
 /*
-** $Id: lref.c,v 1.6 1999/12/27 17:33:22 roberto Exp roberto $
+** $Id: lref.c,v 1.7 2000/02/08 16:34:31 roberto Exp roberto $
 ** reference mechanism
 ** See Copyright Notice in lua.h
 */
@@ -16,7 +16,7 @@
 
 int lua_ref (lua_State *L,  int lock) {
   int ref;
-  luaA_checkCparams(L, 1);
+  luaA_checkCargs(L, 1);
   if (ttype(L->top-1) == LUA_T_NIL)
     ref = LUA_REFNIL;
   else {
@@ -39,7 +39,8 @@ int lua_ref (lua_State *L,  int lock) {
 void lua_unref (lua_State *L, int ref) {
   if (ref >= 0) {
     if (ref >= L->refSize || L->refArray[ref].st >= 0)
-      lua_error(L, "API error - invalid parameter for function `lua_unref'");
+      lua_error(L, "Lua API error - "
+                   "invalid argument for function `lua_unref'");
     L->refArray[ref].st = L->refFree;
     L->refFree = ref;
   }
@@ -67,7 +68,7 @@ void lua_beginblock (lua_State *L) {
 
 void lua_endblock (lua_State *L) {
   if (L->numCblocks <= 0)
-    lua_error(L, "API error - no block to end");
+    lua_error(L, "Lua API error - no block to end");
   --L->numCblocks;
   L->Cstack = L->Cblocks[L->numCblocks];
   L->top = L->Cstack.base;

+ 2 - 2
lstring.c

@@ -1,5 +1,5 @@
 /*
-** $Id: lstring.c,v 1.30 1999/11/26 18:59:20 roberto Exp roberto $
+** $Id: lstring.c,v 1.31 1999/12/14 18:42:57 roberto Exp roberto $
 ** String table (keeps all strings handled by Lua)
 ** See Copyright Notice in lua.h
 */
@@ -18,7 +18,7 @@
 
 
 #define gcsizestring(L, l)	numblocks(L, 0, sizeof(TaggedString)+l)
-#define gcsizeudata	gcsizestring(L, 0)
+#define gcsizeudata		gcsizestring(L, 0)
 
 
 

+ 3 - 3
lstring.h

@@ -1,5 +1,5 @@
 /*
-** $Id: lstring.h,v 1.14 1999/11/26 18:59:20 roberto Exp roberto $
+** $Id: lstring.h,v 1.15 1999/12/14 18:42:57 roberto Exp roberto $
 ** String table (keep all strings handled by Lua)
 ** See Copyright Notice in lua.h
 */
@@ -12,8 +12,8 @@
 #include "lstate.h"
 
 
-#define NUM_HASHSTR     31  /* a prime not in array `dimensions' */
-#define NUM_HASHUDATA   31  /* idem */
+#define NUM_HASHSTR     31
+#define NUM_HASHUDATA   31
 #define NUM_HASHS (NUM_HASHSTR+NUM_HASHUDATA)
 
 

+ 23 - 23
lstrlib.c

@@ -1,5 +1,5 @@
 /*
-** $Id: lstrlib.c,v 1.39 1999/12/27 17:33:22 roberto Exp roberto $
+** $Id: lstrlib.c,v 1.40 2000/02/08 16:34:31 roberto Exp roberto $
 ** Standard library for string operations and pattern-matching
 ** See Copyright Notice in lua.h
 */
@@ -116,8 +116,8 @@ static void str_char (lua_State *L) {
 ** =======================================================
 */
 
-#ifndef MAX_CAPT
-#define MAX_CAPT 32  /* arbitrary limit */
+#ifndef MAX_CAPTURES
+#define MAX_CAPTURES 32  /* arbitrary limit */
 #endif
 
 
@@ -127,12 +127,12 @@ struct Capture {
   struct {
     const char *init;
     int len;  /* -1 signals unfinished capture */
-  } capture[MAX_CAPT];
+  } capture[MAX_CAPTURES];
 };
 
 
-#define ESC	'%'
-#define SPECIALS  "^$*+?.([%-"
+#define ESC		'%'
+#define SPECIALS	"^$*+?.([%-"
 
 
 static void push_captures (lua_State *L, struct Capture *cap) {
@@ -145,7 +145,7 @@ static void push_captures (lua_State *L, struct Capture *cap) {
 }
 
 
-static int check_cap (lua_State *L, int l, struct Capture *cap) {
+static int check_capture (lua_State *L, int l, struct Capture *cap) {
   l -= '1';
   if (!(0 <= l && l < cap->level && cap->capture[l].len != -1))
     lua_error(L, "invalid capture index");
@@ -165,12 +165,12 @@ static int capture_to_close (lua_State *L, struct Capture *cap) {
 const char *luaI_classend (lua_State *L, const char *p) {
   switch (*p++) {
     case ESC:
-      if (*p == '\0') lua_error(L, "incorrect pattern (ends with `%')");
+      if (*p == '\0') lua_error(L, "malformed pattern (ends with `%')");
       return p+1;
     case '[':
       if (*p == '^') p++;
       do {  /* look for a ']' */
-        if (*p == '\0') lua_error(L, "incorrect pattern (missing `]')");
+        if (*p == '\0') lua_error(L, "malformed pattern (missing `]')");
         if (*(p++) == ESC && *p != '\0') p++;  /* skip escapes (e.g. '%]') */
       } while (*p != ']');
       return p+1;
@@ -180,7 +180,7 @@ const char *luaI_classend (lua_State *L, const char *p) {
 }
 
 
-static int matchclass (int c, int cl) {
+static int match_class (int c, int cl) {
   int res;
   switch (tolower(cl)) {
     case 'a' : res = isalpha(c); break;
@@ -209,7 +209,7 @@ static int matchbracketclass (int c, const char *p, const char *endclass) {
   while (++p < endclass) {
     if (*p == ESC) {
       p++;
-      if (matchclass(c, (unsigned char)*p))
+      if (match_class(c, (unsigned char)*p))
         return sig;
     }
     else if ((*(p+1) == '-') && (p+2 < endclass)) {
@@ -217,7 +217,7 @@ static int matchbracketclass (int c, const char *p, const char *endclass) {
       if ((int)(unsigned char)*(p-2) <= c && c <= (int)(unsigned char)*p)
         return sig;
     }
-    else if ((unsigned char)*p == c) return sig;
+    else if ((int)(unsigned char)*p == c) return sig;
   }
   return !sig;
 }
@@ -229,7 +229,7 @@ int luaI_singlematch (int c, const char *p, const char *ep) {
     case '.':  /* matches any char */
       return 1;
     case ESC:
-      return matchclass(c, (unsigned char)*(p+1));
+      return match_class(c, (unsigned char)*(p+1));
     case '[':
       return matchbracketclass(c, p, ep-1);
     default:
@@ -289,11 +289,11 @@ static const char *min_expand (lua_State *L, const char *s, const char *p, const
 }
 
 
-static const char *start_capt (lua_State *L, const char *s, const char *p,
-                               struct Capture *cap) {
+static const char *start_capture (lua_State *L, const char *s, const char *p,
+                                  struct Capture *cap) {
   const char *res;
   int level = cap->level;
-  if (level >= MAX_CAPT) lua_error(L, "too many captures");
+  if (level >= MAX_CAPTURES) lua_error(L, "too many captures");
   cap->capture[level].init = s;
   cap->capture[level].len = -1;
   cap->level = level+1;
@@ -303,8 +303,8 @@ static const char *start_capt (lua_State *L, const char *s, const char *p,
 }
 
 
-static const char *end_capt (lua_State *L, const char *s, const char *p,
-                             struct Capture *cap) {
+static const char *end_capture (lua_State *L, const char *s, const char *p,
+                                struct Capture *cap) {
   int l = capture_to_close(L, cap);
   const char *res;
   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,
 
 static const char *match_capture (lua_State *L, const char *s, int level,
                                   struct Capture *cap) {
-  int l = check_cap(L, level, cap);
+  int l = check_capture(L, level, cap);
   int len = cap->capture[l].len;
   if (cap->src_end-s >= len &&
       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
   init: /* using goto's to optimize tail recursion */
   switch (*p) {
     case '(':  /* start capture */
-      return start_capt(L, s, p, cap);
+      return start_capture(L, s, p, cap);
     case ')':  /* end capture */
-      return end_capt(L, s, p, cap);
+      return end_capture(L, s, p, cap);
     case ESC:  /* may be %[0-9] or %b */
       if (isdigit((unsigned char)(*(p+1)))) {  /* capture? */
         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) {
         if (!isdigit((unsigned char)news[i]))
           luaL_addchar(L, news[i]);
         else {
-          int level = check_cap(L, news[i], cap);
+          int level = check_capture(L, news[i], cap);
           addnchar(L, cap->capture[level].init, cap->capture[level].len);
         }
       }
@@ -576,7 +576,7 @@ static void str_format (lua_State *L) {
           long l;
           const char *s = luaL_check_lstr(L, arg, &l);
           if (cap.capture[1].len == 0 && l >= 100) {
-            /* no precision and string is too big to be formatted;
+            /* no precision and string is too long to be formatted;
                keep original string */
             addnchar(L, s, l);
             continue;  /* skip the "addsize" at the end */

+ 2 - 2
ltable.c

@@ -1,5 +1,5 @@
 /*
-** $Id: ltable.c,v 1.33 1999/12/23 18:19:57 roberto Exp roberto $
+** $Id: ltable.c,v 1.34 2000/02/08 16:34:31 roberto Exp roberto $
 ** Lua tables (hash)
 ** See Copyright Notice in lua.h
 */
@@ -32,7 +32,7 @@
 
 
 
-#define TagDefault LUA_T_ARRAY;
+#define TagDefault LUA_T_ARRAY
 
 
 

+ 2 - 2
ltm.c

@@ -1,5 +1,5 @@
 /*
-** $Id: ltm.c,v 1.31 2000/01/19 12:00:45 roberto Exp roberto $
+** $Id: ltm.c,v 1.32 2000/02/22 18:12:46 roberto Exp roberto $
 ** Tag methods
 ** See Copyright Notice in lua.h
 */
@@ -147,7 +147,7 @@ void luaT_settagmethod (lua_State *L, int t, const char *event, TObject *func) {
   e = luaI_checkevent(L, event, luaT_eventname);
   checktag(L, t);
   if (!luaT_validevent(t, e))
-    luaL_verror(L, "cannot change tag method `%.20s' for type `%.20s'%.20s",
+    luaL_verror(L, "cannot change `%.20s' tag method for type `%.20s'%.20s",
                 luaT_eventname[e], luaO_typenames[-t],
                 (t == LUA_T_ARRAY || t == LUA_T_USERDATA) ? " with default tag"
                                                           : "");

+ 3 - 4
ltm.h

@@ -1,5 +1,5 @@
 /*
-** $Id: ltm.h,v 1.8 1999/11/22 13:12:07 roberto Exp roberto $
+** $Id: ltm.h,v 1.9 2000/02/22 18:12:46 roberto Exp roberto $
 ** Tag methods
 ** See Copyright Notice in lua.h
 */
@@ -30,11 +30,10 @@ typedef enum {
   IM_LT,
   IM_CONCAT,
   IM_GC,
-  IM_FUNCTION
+  IM_FUNCTION,
+  IM_N		/* number of elements in the enum */
 } IMS;
 
-#define IM_N 15
-
 
 struct IM {
   TObject int_method[IM_N];

+ 9 - 15
lua.c

@@ -1,5 +1,5 @@
 /*
-** $Id: lua.c,v 1.32 2000/01/19 16:50:14 roberto Exp roberto $
+** $Id: lua.c,v 1.33 2000/02/21 18:30:42 roberto Exp roberto $
 ** Lua stand-alone interpreter
 ** See Copyright Notice in lua.h
 */
@@ -87,16 +87,10 @@ static void print_version (void) {
 
 
 static void assign (char *arg) {
-  char buffer[500];
-  if (strlen(arg) >= sizeof(buffer))
-    fprintf(stderr, "lua: shell argument too long");
-  else {
-    char *eq = strchr(arg, '=');
-    lua_pushstring(eq+1);
-    strncpy(buffer, arg, eq-arg);
-    buffer[eq-arg] = 0;
-    lua_setglobal(buffer);
-  }
+  char *eq = strchr(arg, '=');
+  *eq = '\0';  /* spilt `arg' in two strings (name & value) */
+  lua_pushstring(eq+1);
+  lua_setglobal(arg);
 }
 
 
@@ -139,7 +133,7 @@ static void manual_input (int prompt) {
     if (prompt) {
       const char *s = lua_getstring(lua_getglobal("_PROMPT"));
       if (!s) s = PROMPT;
-      printf("%s", s);
+      fputs(s, stdout);
     }
     for(;;) {
       int c = getchar();
@@ -153,7 +147,7 @@ static void manual_input (int prompt) {
         else break;
       }
       else if (i >= BUFSIZ-1) {
-        fprintf(stderr, "lua: argument line too long\n");
+        fprintf(stderr, "lua: input line too long\n");
         break;
       }
       else buffer[i++] = (char)c;
@@ -217,9 +211,9 @@ int main (int argc, char *argv[]) {
             print_message();
             exit(1);
           }
-          getargs(argc-i, argv+i);  /* collect following arguments */
+          getargs(argc-i, argv+i);  /* collect remaining arguments */
           file_input(argv, i);
-          i = argc;  /* stop running arguments */
+          i = argc;  /* stop scanning arguments */
           break;
         default:
           print_message();

+ 48 - 70
lundump.c

@@ -1,5 +1,5 @@
 /*
-** $Id: lundump.c,v 1.16 1999/12/02 19:11:51 roberto Exp roberto $
+** $Id: lundump.c,v 1.26 2000/02/17 19:17:44 lhf Exp lhf $
 ** load bytecodes from files
 ** See Copyright Notice in lua.h
 */
@@ -50,22 +50,13 @@ static unsigned long LoadLong (lua_State* L, ZIO* Z)
  return (hi<<16)|lo;
 }
 
-static real LoadNumber (lua_State* L, ZIO* Z, int native)
+static real LoadNumber (lua_State* L, ZIO* Z)
 {
- if (native)
- {
-  real x;
-  LoadBlock(L,&x,sizeof(x),Z);
-  return x;
- }
- else
- {
-  char b[256];
-  int size=ezgetc(L,Z);
-  LoadBlock(L,b,size,Z);
-  b[size]=0;
-  return luaU_str2d(L,b,zname(Z));
- }
+ char b[256];
+ int size=ezgetc(L,Z);
+ LoadBlock(L,b,size,Z);
+ b[size]=0;
+ return luaU_str2d(L,b,zname(Z));
 }
 
 static 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)
  return i;
 }
 
-#define PAD	5			/* two word operands plus opcode */
-
-static Byte* LoadCode (lua_State* L, ZIO* Z)
+static void LoadCode (lua_State* L, TProtoFunc* tf, ZIO* Z)
 {
  int size=LoadInt(L,Z,"code too long (%lu bytes) in %.255s");
- Byte* b=luaM_malloc(L,size+PAD);
- LoadBlock(L,b,size,Z);
- if (b[size-1]!=ENDCODE) luaL_verror(L,"bad code in %.255s",zname(Z));
- memset(b+size,ENDCODE,PAD);		/* pad code for safety */
- return b;
+ tf->code=luaM_newvector(L,size,Instruction);
+ LoadBlock(L,tf->code,size*sizeof(tf->code[0]),Z);
+ if (tf->code[size-1]!=ENDCODE) luaL_verror(L,"bad code in %.255s",zname(Z));
 }
 
-static TaggedString* LoadTString (lua_State* L, ZIO* Z)
+static TaggedString* LoadString (lua_State* L, ZIO* Z)
 {
  long size=LoadLong(L,Z);
  if (size==0)
@@ -97,7 +84,7 @@ static TaggedString* LoadTString (lua_State* L, ZIO* Z)
  {
   char* s=luaL_openspace(L,size);
   LoadBlock(L,s,size,Z);
-  return luaS_newlstr(L,s,size-1);
+  return luaS_newlstr(L,s,size-1);	/* remove trailing '\0' */
  }
 }
 
@@ -109,7 +96,7 @@ static void LoadLocals (lua_State* L, TProtoFunc* tf, ZIO* Z)
  for (i=0; i<n; i++)
  {
   tf->locvars[i].line=LoadInt(L,Z,"too many lines (%lu) in %.255s");
-  tf->locvars[i].varname=LoadTString(L,Z);
+  tf->locvars[i].varname=LoadString(L,Z);
  }
  tf->locvars[i].line=-1;		/* flag end of vector */
  tf->locvars[i].varname=NULL;
@@ -119,31 +106,27 @@ static TProtoFunc* LoadFunction (lua_State* L, ZIO* Z, int native);
 
 static void LoadConstants (lua_State* L, TProtoFunc* tf, ZIO* Z, int native)
 {
- int i,n=LoadInt(L,Z,"too many constants (%lu) in %.255s");
- tf->nconsts=n;
- if (n==0) return;
- tf->consts=luaM_newvector(L,n,TObject);
- for (i=0; i<n; i++)
+ int i,n;
+ tf->nkstr=n=LoadInt(L,Z,"too many strings (%lu) in %.255s");
+ if (n>0)
  {
-  TObject* o=tf->consts+i;
-  ttype(o)=-ezgetc(L,Z);		/* ttype(o) is negative - ORDER LUA_T */
-  switch (ttype(o))
-  {
-   case LUA_T_NUMBER:
-	nvalue(o)=LoadNumber(L,Z,native);
-	break;
-   case LUA_T_STRING:
-	tsvalue(o)=LoadTString(L,Z);
-	break;
-   case LUA_T_LPROTO:
-	tfvalue(o)=LoadFunction(L,Z,native);
-	break;
-   case LUA_T_NIL:
-	break;
-   default:				/* cannot happen */
-	luaU_badconstant(L,"load",i,o,tf);
-	break;
-  }
+  tf->kstr=luaM_newvector(L,n,TaggedString*);
+  for (i=0; i<n; i++) tf->kstr[i]=LoadString(L,Z);
+ }
+ tf->nknum=n=LoadInt(L,Z,"too many numbers (%lu) in %.255s");
+ if (n>0)
+ {
+  tf->knum=luaM_newvector(L,n,real);
+  if (native)
+   LoadBlock(L,tf->knum,n*sizeof(tf->knum[0]),Z);
+  else
+   for (i=0; i<n; i++) tf->knum[i]=LoadNumber(L,Z);
+ }
+ tf->nkproto=n=LoadInt(L,Z,"too many functions (%lu) in %.255s");
+ if (n>0)
+ {
+  tf->kproto=luaM_newvector(L,n,TProtoFunc*);
+  for (i=0; i<n; i++) tf->kproto[i]=LoadFunction(L,Z,native);
  }
 }
 
@@ -151,9 +134,12 @@ static TProtoFunc* LoadFunction (lua_State* L, ZIO* Z, int native)
 {
  TProtoFunc* tf=luaF_newproto(L);
  tf->lineDefined=LoadInt(L,Z,"lineDefined too large (%lu) in %.255s");
- tf->source=LoadTString(L,Z);
+ tf->source=LoadString(L,Z);
  if (tf->source==NULL) tf->source=luaS_new(L,zname(Z));
- tf->code=LoadCode(L,Z);
+ tf->numparams=LoadInt(L,Z,"numparams too large (%lu) in %.255s");
+ tf->is_vararg=LoadInt(L,Z,"is_vararg too large (%lu) in %.255s");
+ tf->maxstacksize=LoadInt(L,Z,"maxstacksize too large (%lu) in %.255s");
+ LoadCode(L,tf,Z);
  LoadLocals(L,tf,Z);
  LoadConstants(L,tf,Z,native);
  return tf;
@@ -167,6 +153,8 @@ static void LoadSignature (lua_State* L, ZIO* Z)
  if (*s!=0) luaL_verror(L,"bad signature in %.255s",zname(Z));
 }
 
+#define V(v)	v/16,v%16
+
 static int LoadHeader (lua_State* L, ZIO* Z)
 {
  int version,sizeofR,native;
@@ -174,12 +162,12 @@ static int LoadHeader (lua_State* L, ZIO* Z)
  version=ezgetc(L,Z);
  if (version>VERSION)
   luaL_verror(L,
-	"%.255s too new: version=0x%02x; expected at most 0x%02x",
-	zname(Z),version,VERSION);
+	"%.255s too new: its version is %d.%d; expected at most %d.%d",
+	zname(Z),V(version),V(VERSION));
  if (version<VERSION0)			/* check last major change */
   luaL_verror(L,
-	"%.255s too old: version=0x%02x; expected at least 0x%02x",
-	zname(Z),version,VERSION0);
+	"%.255s too old: its version is %d.%d; expected at least %d.%d",
+	zname(Z),V(version),V(VERSION));
  sizeofR=ezgetc(L,Z);
  native=(sizeofR!=0);
  if (native)				/* test number representation */
@@ -189,9 +177,9 @@ static int LoadHeader (lua_State* L, ZIO* Z)
 	 zname(Z),sizeofR,(int)sizeof(real));
   else
   {
-   real tf=TEST_NUMBER;
-   real f=LoadNumber(L,Z,native);
-   if ((long)f!=(long)tf)
+   real f=0,tf=TEST_NUMBER;
+   LoadBlock(L,&f,sizeof(f),Z);
+   if ((long)f!=(long)tf)		/* disregard errors in last bit of fraction */
     luaL_verror(L,"unknown number format in %.255s: "
 	  "read " NUMBER_FMT "; expected " NUMBER_FMT,
 	  zname(Z),f,tf);
@@ -219,16 +207,6 @@ TProtoFunc* luaU_undump1 (lua_State* L, ZIO* Z)
  return NULL;
 }
 
-/*
-* handle constants that cannot happen
-*/
-void luaU_badconstant (lua_State* L, const char* s, int i, const TObject* o, const TProtoFunc* tf)
-{
- int t=ttype(o);
- const char* name= (t>0 || t<LUA_T_LINE) ? "?" : luaO_typenames[-t];
- luaL_verror(L,"cannot %.255s constant #%d: type=%d [%s]" IN,s,i,t,name,INLOC);
-}
-
 /*
 * convert number from text
 */

+ 2 - 1
lundump.h

@@ -1,5 +1,5 @@
 /*
-** $Id: lundump.h,v 1.17 1999/12/02 18:51:09 lhf Exp $
+** $Id: lundump.h,v 1.18 2000/01/28 17:51:09 lhf Exp $
 ** load pre-compiled Lua chunks
 ** See Copyright Notice in lua.h
 */
@@ -27,6 +27,7 @@ double luaU_str2d (lua_State* L, const char* b, const char* where);
 #define	SIGNATURE	"Lua"		/* ...followed by this signature */
 
 /* formats for error messages */
+#define xSOURCE		"<%d:%.255s>"
 #define SOURCE		"<%.255s:%d>"
 #define IN		" in %p " SOURCE
 #define INLOC		tf,tf->source->str,tf->lineDefined

+ 7 - 9
lvm.c

@@ -1,5 +1,5 @@
 /*
-** $Id: lvm.c,v 1.88 2000/02/22 13:31:30 roberto Exp roberto $
+** $Id: lvm.c,v 1.89 2000/02/22 18:12:46 roberto Exp roberto $
 ** Lua virtual machine
 ** See Copyright Notice in lua.h
 */
@@ -30,8 +30,6 @@
 #endif
 
 
-#define highbyte(L, x)	((x)<<8)
-
 
 /*
 ** Extra stack size to run a function:
@@ -106,7 +104,7 @@ void luaV_closure (lua_State *L, int nelems) {
 void luaV_gettable (lua_State *L, StkId top) {
   TObject *table = top-2;
   const TObject *im;
-  if (ttype(table) != LUA_T_ARRAY) {  /* not a table, get gettable method */
+  if (ttype(table) != LUA_T_ARRAY) {  /* not a table, get gettable TM */
     im = luaT_getimbyObj(L, table, IM_GETTABLE);
     if (ttype(im) == LUA_T_NIL) {
       L->top = top;
@@ -116,7 +114,7 @@ void luaV_gettable (lua_State *L, StkId top) {
   else {  /* object is a table... */
     int tg = table->value.a->htag;
     im = luaT_getim(L, tg, IM_GETTABLE);
-    if (ttype(im) == LUA_T_NIL) {  /* and does not have a `gettable' method */
+    if (ttype(im) == LUA_T_NIL) {  /* and does not have a `gettable' TM */
       const TObject *h = luaH_get(L, avalue(table), table+1);
       if (ttype(h) == LUA_T_NIL &&
           (ttype(im=luaT_getim(L, tg, IM_INDEX)) != LUA_T_NIL)) {
@@ -128,9 +126,9 @@ void luaV_gettable (lua_State *L, StkId top) {
         *table = *h;  /* `push' result into table position */
       return;
     }
-    /* else it has a `gettable' method, go through to next command */
+    /* else it has a `gettable' TM, go through to next command */
   }
-  /* object is not a table, or it has a `gettable' method */
+  /* object is not a table, or it has a `gettable' TM */
   L->top = top;
   luaD_callTM(L, im, 2, 1);
 }
@@ -261,7 +259,7 @@ int luaV_lessthan (lua_State *L, TObject *l, TObject *r) {
   else if (ttype(l) == LUA_T_STRING && ttype(r) == LUA_T_STRING)
     return (luaV_strcomp(tsvalue(l), tsvalue(r)) < 0);
   else {
-    /* update top and put arguments in correct order to call Tag Method */
+    /* update top and put arguments in correct order to call TM */
     if (l<r)  /* are arguments in correct order? */
       L->top = r+1;  /* yes; 2nd is on top */
     else {  /* no; exchange them */
@@ -562,7 +560,7 @@ StkId luaV_execute (lua_State *L, const Closure *cl, const TProtoFunc *tf,
           call_arith(L, top+1, IM_UNM);
         }
         else
-          nvalue(top-1) = - nvalue(top-1);
+          nvalue(top-1) = -nvalue(top-1);
         break;
 
       case NOTOP:

+ 3 - 3
lvm.h

@@ -1,5 +1,5 @@
 /*
-** $Id: lvm.h,v 1.15 2000/01/24 20:14:07 roberto Exp roberto $
+** $Id: lvm.h,v 1.16 2000/02/22 18:12:46 roberto Exp roberto $
 ** Lua virtual machine
 ** See Copyright Notice in lua.h
 */
@@ -13,8 +13,8 @@
 #include "ltm.h"
 
 
-#define tonumber(o) ((ttype(o) != LUA_T_NUMBER) && (luaV_tonumber(o) != 0))
-#define tostring(L, o) ((ttype(o) != LUA_T_STRING) && (luaV_tostring(L, o) != 0))
+#define tonumber(o)   ((ttype(o) != LUA_T_NUMBER) && (luaV_tonumber(o) != 0))
+#define tostring(L,o) ((ttype(o) != LUA_T_STRING) && (luaV_tostring(L, o) != 0))
 
 
 void luaV_pack (lua_State *L, StkId firstel, int nvararg, TObject *tab);

+ 3 - 3
lzio.c

@@ -1,5 +1,5 @@
 /*
-** $Id: lzio.c,v 1.9 1999/11/09 17:59:35 roberto Exp roberto $
+** $Id: lzio.c,v 1.10 2000/02/08 16:39:42 roberto Exp roberto $
 ** a generic input stream interface
 ** See Copyright Notice in lua.h
 */
@@ -24,7 +24,7 @@ static int zmfilbuf (ZIO* z) {
 ZIO* zmopen (ZIO* z, const char* b, int size, const char *name) {
   if (b==NULL) return NULL;
   z->n = size;
-  z->p = (unsigned const char *)b;
+  z->p = (const unsigned char *)b;
   z->filbuf = zmfilbuf;
   z->u = NULL;
   z->name = name;
@@ -69,7 +69,7 @@ int zread (ZIO *z, void *b, int n) {
     if (z->n == 0) {
       if (z->filbuf(z) == EOZ)
         return n;  /* return number of missing bytes */
-      zungetc(z);  /* put result from 'filbuf' in the buffer */
+      zungetc(z);  /* put result from `filbuf' in the buffer */
     }
     m = (n <= z->n) ? n : z->n;  /* min. between n and z->n */
     memcpy(b, z->p, m);