Browse Source

better error messages;
better names for some API functions.

Roberto Ierusalimschy 28 years ago
parent
commit
42fa305649
10 changed files with 107 additions and 100 deletions
  1. 18 15
      fallback.c
  2. 4 4
      fallback.h
  3. 23 24
      inout.c
  4. 6 6
      iolib.c
  5. 3 3
      lua.c
  6. 16 14
      lua.h
  7. 2 2
      mathlib.c
  8. 21 20
      opcode.c
  9. 3 1
      opcode.h
  10. 11 11
      strlib.c

+ 18 - 15
fallback.c

@@ -3,7 +3,7 @@
 ** TecCGraf - PUC-Rio
 */
  
-char *rcs_fallback="$Id: fallback.c,v 1.38 1997/04/02 23:04:12 roberto Exp roberto $";
+char *rcs_fallback="$Id: fallback.c,v 2.1 1997/04/03 18:24:23 roberto Exp roberto $";
 
 #include <stdio.h>
 #include <string.h>
@@ -115,7 +115,7 @@ static int luaI_checkevent (char *name, char *list[])
 {
   int e = findstring(name, list);
   if (e < 0)
-    luaL_verror("invalid event name `%s'", name);
+    luaL_verror("`%s' is not a valid event name", name);
   return e;
 }
 
@@ -180,17 +180,19 @@ int lua_newtag (void)
 static void checktag (int tag)
 {
   if (!(last_tag <= tag && tag <= 0))
-    lua_error("invalid tag");
+    luaL_verror("%d is not a valid tag", tag);
 }
 
-int luaI_userdatatag (int tag)
+void luaI_realtag (int tag)
 {
-  return (tag >= 0 || (last_tag <= tag && tag < LUA_T_NIL));
+  if (!(last_tag <= tag && tag < LUA_T_NIL))
+    luaL_verror("tag %d is not result of `newtag'", tag);
 }
 
 
 void luaI_settag (int tag, TObject *o)
 {
+  luaI_realtag(tag);
   switch (ttype(o)) {
     case LUA_T_ARRAY:
       o->value.a->htag = tag;
@@ -199,7 +201,7 @@ void luaI_settag (int tag, TObject *o)
       o->value.ts->tag = tag;
       break;
     default:
-      lua_error("settag: cannot change tag of given object");
+      luaL_verror("cannot change tag of a %s", luaI_typenames[-ttype(o)]);
   }
 }
 
@@ -223,25 +225,26 @@ TObject *luaI_getim (int tag, IMS event)
 }
 
 
-void luaI_getintmethod (void)
+void luaI_gettagmethod (void)
 {
-  int t = (int)luaL_check_number(1, "getintmethod");
-  int e = luaI_checkevent(luaL_check_string(2, "getintmethod"), luaI_eventname);
+  int t = (int)luaL_check_number(1, "gettagmethod");
+  int e = luaI_checkevent(luaL_check_string(2, "gettagmethod"), luaI_eventname);
   checktag(t);
   if (validevent(t, e))
     luaI_pushobject(&luaI_IMtable[-t].int_method[e]);
 }
 
 
-void luaI_setintmethod (void)
+void luaI_settagmethod (void)
 {
-  int t = (int)luaL_check_number(1, "setintmethod");
-  int e = luaI_checkevent(luaL_check_string(2, "setintmethod"), luaI_eventname);
+  int t = (int)luaL_check_number(1, "settagmethod");
+  int e = luaI_checkevent(luaL_check_string(2, "settagmethod"), luaI_eventname);
   lua_Object func = lua_getparam(3);
   checktag(t);
   if (!validevent(t, e))
-    lua_error("cannot change this internal method");
-  luaL_arg_check(lua_isnil(func) || lua_isfunction(func), "setintmethod",
+    luaL_verror("cannot change internal method `%s' for tag %d",
+                luaI_eventname[e], t);
+  luaL_arg_check(lua_isnil(func) || lua_isfunction(func), "settagmethod",
                  3, "function expected");
   luaI_pushobject(&luaI_IMtable[-t].int_method[e]);
   luaI_IMtable[-t].int_method[e] = *luaI_Address(func);
@@ -352,7 +355,7 @@ void luaI_setfallback (void)
     replace = typeFB;
   }
   else {
-    lua_error("invalid fallback name");
+    luaL_verror("`%s' is not a valid fallback name", name);
     replace = NULL;  /* to avoid warnings */
   }
   if (oldfunc.ttype != LUA_T_NIL)

+ 4 - 4
fallback.h

@@ -1,5 +1,5 @@
 /*
-** $Id: fallback.h,v 1.20 1997/04/02 22:52:42 roberto Exp roberto $
+** $Id: fallback.h,v 1.21 1997/04/02 23:04:12 roberto Exp roberto $
 */
  
 #ifndef fallback_h
@@ -46,13 +46,13 @@ void luaI_invalidaterefs (void);
 char *luaI_travfallbacks (int (*fn)(TObject *));
 
 void luaI_settag (int tag, TObject *o);
-int luaI_userdatatag (int tag);
+void luaI_realtag (int tag);
 TObject *luaI_getim (int tag, IMS event);
 #define luaI_getimbyObj(o,e)  (luaI_getim(luaI_tag(o),(e)))
 TObject *luaI_geterrorim (void);
 int luaI_tag (TObject *o);
-void luaI_setintmethod (void);
-void luaI_getintmethod (void);
+void luaI_settagmethod (void);
+void luaI_gettagmethod (void);
 void luaI_seterrormethod (void);
 void luaI_initfallbacks (void);
 

+ 23 - 24
inout.c

@@ -5,7 +5,7 @@
 ** Also provides some predefined lua functions.
 */
 
-char *rcs_inout="$Id: inout.c,v 2.53 1997/04/02 22:53:35 roberto Exp roberto $";
+char *rcs_inout="$Id: inout.c,v 2.54 1997/04/02 23:04:12 roberto Exp roberto $";
 
 #include <stdio.h>
 #include <string.h>
@@ -28,7 +28,7 @@ Word lua_linenumber;
 char *lua_parsedfile;
 
 
-static char *typenames[] = { /* ORDER LUA_T */
+char *luaI_typenames[] = { /* ORDER LUA_T */
   "userdata", "line", "cmark", "mark", "function",
   "function", "table", "string", "number", "nil",
   NULL
@@ -95,8 +95,7 @@ void lua_openstring (char *s)
   char buff[SIZE_PREF+25];
   lua_setinput(stringinput);
   st = s;
-  strcpy(buff, "(dostring) >> ");
-  strncat(buff, s, SIZE_PREF);
+  sprintf(buff, "(dostring) >> %.20s", s);
   if (strlen(s) > SIZE_PREF) strcat(buff, "...");
   lua_parsedfile = luaI_createfixedstring(buff)->str;
 }
@@ -148,7 +147,7 @@ static char *tostring (lua_Object obj)
       return lua_getstring(obj);
     case LUA_T_ARRAY: case LUA_T_FUNCTION:
     case LUA_T_CFUNCTION: case LUA_T_NIL:
-      return typenames[-ttype(o)];
+      return luaI_typenames[-ttype(o)];
     case LUA_T_USERDATA: {
       char *buff = luaI_buffer(100);
       int size = o->value.ts->size;
@@ -181,7 +180,7 @@ static void luaI_type (void)
 {
   lua_Object o = lua_getparam(1);
   luaL_arg_check(o != LUA_NOOBJECT, "type", 1, "no argument");
-  lua_pushstring(typenames[-ttype(luaI_Address(o))]);
+  lua_pushstring(luaI_typenames[-ttype(luaI_Address(o))]);
   lua_pushnumber(lua_tag(o));
 }
 
@@ -219,12 +218,12 @@ static void luaI_setglobal (void)
   lua_pushobject(value);  /* return given value */
 }
 
-static void luaI_basicsetglobal (void)
+static void luaI_rawsetglobal (void)
 {
   lua_Object value = lua_getparam(2);
-  luaL_arg_check(value != LUA_NOOBJECT, "basicsetglobal", 2, NULL);
+  luaL_arg_check(value != LUA_NOOBJECT, "rawsetglobal", 2, NULL);
   lua_pushobject(value);
-  lua_basicsetglobal(luaL_check_string(1, "basicsetglobal"));
+  lua_rawsetglobal(luaL_check_string(1, "rawsetglobal"));
   lua_pushobject(value);  /* return given value */
 }
 
@@ -233,9 +232,9 @@ static void luaI_getglobal (void)
   lua_pushobject(lua_getglobal(luaL_check_string(1, "getglobal")));
 }
 
-static void luaI_basicgetglobal (void)
+static void luaI_rawgetglobal (void)
 {
-  lua_pushobject(lua_basicgetglobal(luaL_check_string(1, "basicgetglobal")));
+  lua_pushobject(lua_rawgetglobal(luaL_check_string(1, "rawgetglobal")));
 }
 
 static void luatag (void)
@@ -291,28 +290,28 @@ static void luaIl_newtag (void)
   lua_pushnumber(lua_newtag());
 }
 
-static void basicindex (void)
+static void rawgettable (void)
 {
   lua_Object t = lua_getparam(1);
   lua_Object i = lua_getparam(2);
-  luaL_arg_check(t != LUA_NOOBJECT, "basicindex", 1, NULL);
-  luaL_arg_check(i != LUA_NOOBJECT, "basicindex", 2, NULL);
+  luaL_arg_check(t != LUA_NOOBJECT, "rawgettable", 1, NULL);
+  luaL_arg_check(i != LUA_NOOBJECT, "rawgettable", 2, NULL);
   lua_pushobject(t);
   lua_pushobject(i);
-  lua_pushobject(lua_basicindex());
+  lua_pushobject(lua_rawgettable());
 }
 
-static void basicstoreindex (void)
+static void rawsettable (void)
 {
   lua_Object t = lua_getparam(1);
   lua_Object i = lua_getparam(2);
   lua_Object v = lua_getparam(3);
   luaL_arg_check(t != LUA_NOOBJECT && i != LUA_NOOBJECT && v != LUA_NOOBJECT,
-            "basicindex", 0, NULL);
+            "rawsettable", 0, NULL);
   lua_pushobject(t);
   lua_pushobject(i);
   lua_pushobject(v);
-  lua_basicstoreindex();
+  lua_rawsettable();
 }
 
 
@@ -325,10 +324,6 @@ static struct {
   lua_CFunction func;
 } int_funcs[] = {
   {"assert", luaI_assert},
-  {"basicgetglobal", luaI_basicgetglobal},
-  {"basicindex", basicindex},
-  {"basicsetglobal", luaI_basicsetglobal},
-  {"basicstoreindex", basicstoreindex},
   {"call", luaI_call},
   {"dofile", lua_internaldofile},
   {"dostring", lua_internaldostring},
@@ -338,11 +333,15 @@ static struct {
   {"next", lua_next},
   {"nextvar", luaI_nextvar},
   {"print", luaI_print},
+  {"rawgetglobal", luaI_rawgetglobal},
+  {"rawgettable", rawgettable},
+  {"rawsetglobal", luaI_rawsetglobal},
+  {"rawsettable", rawsettable},
   {"seterrormethod", luaI_seterrormethod},
   {"setfallback", luaI_setfallback},
   {"setglobal", luaI_setglobal},
-  {"setintmethod", luaI_setintmethod},
-  {"getintmethod", luaI_getintmethod},
+  {"settagmethod", luaI_settagmethod},
+  {"gettagmethod", luaI_gettagmethod},
   {"settag", luaIl_settag},
   {"tonumber", lua_obj2number},
   {"tostring", luaI_tostring},

+ 6 - 6
iolib.c

@@ -33,7 +33,7 @@ static void pushresult (int i)
 #ifndef NOSTRERROR
     lua_pushstring(strerror(errno));
 #else
-    lua_pushstring("system unable to define the error");
+    lua_pushstring("O.S. unable to define the error");
 #endif
   }
 }
@@ -124,7 +124,7 @@ static void io_read (void)
     }
     else if (*p == '}') {
       if (inskip == 0)
-        lua_error("unbalanced `{...}' in read pattern");
+        lua_error("unbalanced braces in read pattern");
       inskip--;
       p++;
     }
@@ -248,7 +248,7 @@ static void lua_printstack (FILE *f)
         fprintf(f, "function %s", name);
         break;
       case 'f':
-        fprintf(f, "`%s' fallback", name);
+        fprintf(f, "`%s' iternal method", name);
         break;
       default: {
         char *filename;
@@ -289,7 +289,7 @@ static void getbyte (void)
   else {
     i--;
     if (0 <= i && i < lua_getbindatasize(ud))
-      lua_pushnumber(*(((char *)lua_getbinarydata(ud))+i));
+      lua_pushnumber(*(((char *)lua_getbindata(ud))+i));
     else
       lua_pushnil();
   }
@@ -307,7 +307,7 @@ static void createuserdata (void)
     lua_beginblock();
     lua_pushobject(t);
     lua_pushnumber(i+1);
-    o = lua_basicindex();
+    o = lua_rawgettable();
     if (lua_isnil(o)) {
       lua_endblock();
       break;
@@ -317,7 +317,7 @@ static void createuserdata (void)
     luaI_addchar(lua_getnumber(o));
     lua_endblock();
   }
-  lua_pushbinarydata(luaI_addchar(0), i, tag);
+  lua_pushbindata(luaI_addchar(0), i, tag);
 }
 
 

+ 3 - 3
lua.c

@@ -3,7 +3,7 @@
 ** Linguagem para Usuarios de Aplicacao
 */
 
-char *rcs_lua="$Id: lua.c,v 1.13 1996/07/06 20:20:35 roberto Exp roberto $";
+char *rcs_lua="$Id: lua.c,v 1.14 1996/09/24 17:30:28 roberto Exp roberto $";
 
 #include <stdio.h>
 #include <string.h>
@@ -59,8 +59,8 @@ int main (int argc, char *argv[])
       result = lua_dofile (argv[i]);
       if (result) {
         if (result == 2) {
-          fprintf(stderr, "lua: cannot execute file `%s' - ", argv[i]);
-          perror(NULL);
+          fprintf(stderr, "lua: cannot execute file ");
+          perror(argv[i]);
         }
         return 1;
       }

+ 16 - 14
lua.h

@@ -2,7 +2,7 @@
 ** LUA - An Extensible Extension Language
 ** TeCGraf: Grupo de Tecnologia em Computacao Grafica, PUC-Rio, Brazil
 ** e-mail: [email protected]
-** $Id: lua.h,v 3.42 1997/04/02 23:04:12 roberto Exp roberto $
+** $Id: lua.h,v 4.1 1997/04/03 18:26:08 roberto Exp roberto $
 */
 
 
@@ -19,9 +19,8 @@
 typedef void (*lua_CFunction) (void);
 typedef unsigned int lua_Object;
 
-lua_Object     lua_setfallback		(char *event, lua_CFunction fallback);
-void           lua_setintmethod	(int tag, char *event, lua_CFunction method);
-void           lua_getintmethod	(int tag, char *event);  /* out: method */
+void           lua_settagmethod	(int tag, char *event, lua_CFunction method);
+void           lua_gettagmethod	(int tag, char *event);  /* out: method */
 void           lua_seterrormethod (lua_CFunction method);
 
 int            lua_newtag		(void);
@@ -53,26 +52,26 @@ int            lua_isfunction           (lua_Object object);
 float          lua_getnumber 		(lua_Object object);
 char          *lua_getstring 		(lua_Object object);
 lua_CFunction  lua_getcfunction 	(lua_Object object);
-void          *lua_getbinarydata	(lua_Object object);
+void          *lua_getbindata		(lua_Object object);
 int            lua_getbindatasize	(lua_Object object);
 
 void 	       lua_pushnil 		(void);
 void           lua_pushnumber 		(float n);
 void           lua_pushstring 		(char *s);
 void           lua_pushcfunction	(lua_CFunction fn);
-void           lua_pushbinarydata	(void *buff, int size, int tag);
+void           lua_pushbindata		(void *buff, int size, int tag);
 void           lua_pushusertag     	(void *u, int tag);
 void           lua_pushobject       	(lua_Object object);
 
 lua_Object     lua_getglobal 		(char *name);
-lua_Object     lua_basicgetglobal	(char *name);
+lua_Object     lua_rawgetglobal		(char *name);
 void           lua_setglobal		(char *name); /* In: value */
-void           lua_basicsetglobal	(char *name); /* In: value */
+void           lua_rawsetglobal		(char *name); /* In: value */
 
-void           lua_storesubscript	(void); /* In: table, index, value */
-void           lua_basicstoreindex	(void); /* In: table, index, value */
-lua_Object     lua_getsubscript		(void); /* In: table, index */
-lua_Object     lua_basicindex		(void); /* In: table, index */
+void           lua_settable	(void); /* In: table, index, value */
+void           lua_rawsettable	(void); /* In: table, index, value */
+lua_Object     lua_gettable 		(void); /* In: table, index */
+lua_Object     lua_rawgettable		(void); /* In: table, index */
 
 int            lua_tag			(lua_Object object);
 
@@ -98,6 +97,8 @@ lua_Object     lua_createtable		(void);
 /* =============================================================== */
 /* for compatibility with old versions. Avoid using these macros/functions */
 
+lua_Object     lua_setfallback		(char *event, lua_CFunction fallback);
+
 #define lua_storeglobal(n)	lua_setglobal(n)
 #define lua_type(o)		(lua_tag(o))
 
@@ -111,9 +112,10 @@ void	*lua_getuserdata	(lua_Object object);
 
 #define lua_pushliteral(o)  lua_pushstring(o)
 
-#define lua_getindexed(o,n) (lua_pushobject(o), lua_pushnumber(n), lua_getsubscript())
-#define lua_getfield(o,f)   (lua_pushobject(o), lua_pushliteral(f), lua_getsubscript())
+#define lua_getindexed(o,n) (lua_pushobject(o), lua_pushnumber(n), lua_gettable())
+#define lua_getfield(o,f)   (lua_pushobject(o), lua_pushliteral(f), lua_gettable())
 
 #define lua_copystring(o) (strdup(lua_getstring(o)))
 
+#define lua_getsubscript  lua_gettable
 #endif

+ 2 - 2
mathlib.c

@@ -3,7 +3,7 @@
 ** Mathematics library to LUA
 */
 
-char *rcs_mathlib="$Id: mathlib.c,v 1.20 1997/03/18 15:30:50 roberto Exp roberto $";
+char *rcs_mathlib="$Id: mathlib.c,v 1.21 1997/03/21 18:37:28 roberto Exp roberto $";
 
 #include <stdlib.h>
 #include <math.h>
@@ -210,6 +210,6 @@ static struct luaL_reg mathlib[] = {
 void mathlib_open (void)
 {
   luaL_openlib(mathlib, (sizeof(mathlib)/sizeof(mathlib[0])));
-  lua_setintmethod(0, "pow", math_pow);
+  lua_settagmethod(0, "pow", math_pow);
 }
 

+ 21 - 20
opcode.c

@@ -3,7 +3,7 @@
 ** TecCGraf - PUC-Rio
 */
 
-char *rcs_opcode="$Id: opcode.c,v 3.93 1997/04/02 23:04:12 roberto Exp roberto $";
+char *rcs_opcode="$Id: opcode.c,v 4.1 1997/04/03 18:27:06 roberto Exp roberto $";
 
 #include <setjmp.h>
 #include <stdio.h>
@@ -19,6 +19,7 @@ char *rcs_opcode="$Id: opcode.c,v 3.93 1997/04/02 23:04:12 roberto Exp roberto $
 #include "lua.h"
 #include "fallback.h"
 #include "undump.h"
+#include "auxlib.h"
 
 #define tonumber(o) ((ttype(o) != LUA_T_NUMBER) && (lua_tonumber(o) != 0))
 #define tostring(o) ((ttype(o) != LUA_T_STRING) && (lua_tostring(o) != 0))
@@ -340,11 +341,11 @@ static void pushsubscript (void)
 }
 
 
-lua_Object lua_basicindex (void)
+lua_Object lua_rawgettable (void)
 {
   adjustC(2);
   if (ttype(top-2) != LUA_T_ARRAY)
-    lua_error("indexed expression not a table in basic indexing");
+    lua_error("indexed expression not a table in raw gettable");
   else {
     TObject *h = lua_hashget(avalue(top-2), top-1);
     --top;
@@ -360,7 +361,7 @@ lua_Object lua_basicindex (void)
 
 /*
 ** Function to store indexed based on values at the top
-** mode = 0: basic store (without internal methods)
+** mode = 0: raw store (without internal methods)
 ** mode = 1: normal store (with internal methods)
 ** mode = 2: "deep stack" store (with internal methods)
 */
@@ -656,14 +657,14 @@ lua_Object lua_setfallback (char *name, lua_CFunction fallback)
   return (Ref(top-1));
 }
 
-void lua_getintmethod (int tag, char *event)
+void lua_gettagmethod (int tag, char *event)
 {
   lua_pushnumber(tag);
   lua_pushstring(event);
-  do_unprotectedrun(luaI_getintmethod, 2, 1);
+  do_unprotectedrun(luaI_gettagmethod, 2, 1);
 }
 
-void lua_setintmethod (int tag, char *event, lua_CFunction method)
+void lua_settagmethod (int tag, char *event, lua_CFunction method)
 {
   lua_pushnumber(tag);
   lua_pushstring(event);
@@ -671,7 +672,7 @@ void lua_setintmethod (int tag, char *event, lua_CFunction method)
     lua_pushcfunction (method);
   else
     lua_pushnil();
-  do_unprotectedrun(luaI_setintmethod, 3, 1);
+  do_unprotectedrun(luaI_settagmethod, 3, 1);
 }
 
 void lua_seterrormethod (lua_CFunction method)
@@ -685,7 +686,7 @@ void lua_seterrormethod (lua_CFunction method)
 ** API: receives on the stack the table and the index.
 ** returns the value.
 */
-lua_Object lua_getsubscript (void)
+lua_Object lua_gettable (void)
 {
   adjustC(2);
   pushsubscript();
@@ -729,13 +730,13 @@ void lua_settag (int tag)
 /* 
 ** API: receives on the stack the table, the index, and the new value.
 */
-void lua_storesubscript (void)
+void lua_settable (void)
 {
   adjustC(3);
   storesubscript(top-3, 1);
 }
 
-void lua_basicstoreindex (void)
+void lua_rawsettable (void)
 {
   adjustC(3);
   storesubscript(top-3, 0);
@@ -825,7 +826,7 @@ char *lua_getstring (lua_Object object)
  else return (svalue(Address(object)));
 }
 
-void *lua_getbinarydata (lua_Object object)
+void *lua_getbindata (lua_Object object)
 {
   if (object == LUA_NOOBJECT || ttype(Address(object)) != LUA_T_USERDATA)
     return NULL;
@@ -834,7 +835,7 @@ void *lua_getbinarydata (lua_Object object)
 
 void *lua_getuserdata (lua_Object object)
 {
-  void *add = lua_getbinarydata(object);
+  void *add = lua_getbindata(object);
   if (add == NULL) return NULL;
   else return *(void **)add;
 }
@@ -875,7 +876,7 @@ void lua_pushref (int ref)
 {
   TObject *o = luaI_getref(ref);
   if (o == NULL)
-    lua_error("access to invalid (possibly garbage collected) reference");
+    lua_error("access to invalid reference (possibly garbage collected)");
   luaI_pushobject(o);
 }
 
@@ -900,7 +901,7 @@ lua_Object lua_getglobal (char *name)
 }
 
 
-lua_Object lua_basicgetglobal (char *name)
+lua_Object lua_rawgetglobal (char *name)
 {
   adjustC(0);
   *top = lua_table[luaI_findsymbolbyname(name)].object;
@@ -938,7 +939,7 @@ void lua_setglobal (char *name)
   setglobal(luaI_findsymbolbyname(name));
 }
 
-void lua_basicsetglobal (char *name)
+void lua_rawsetglobal (char *name)
 {
  Word n = luaI_findsymbolbyname(name);
  adjustC(1);
@@ -989,13 +990,13 @@ void lua_pushcfunction (lua_CFunction fn)
  incr_top;
 }
 
-void lua_pushbinarydata (void *buff, int size, int tag)
+void lua_pushbindata (void *buff, int size, int tag)
 {
   if (buff == NULL)
     ttype(top) = LUA_T_NIL;
   else {
-    if (!luaI_userdatatag(tag))
-      lua_error("invalid tag for userdata");
+    if (tag < 0)
+      luaI_realtag(tag);
     tsvalue(top) = luaI_createuserdata(buff, size, tag);
     ttype(top) = LUA_T_USERDATA;
   }
@@ -1007,7 +1008,7 @@ void lua_pushbinarydata (void *buff, int size, int tag)
 */
 void lua_pushusertag (void *u, int tag)
 {
-  lua_pushbinarydata(&u, sizeof(void *), tag);
+  lua_pushbindata(&u, sizeof(void *), tag);
 }
 
 /*

+ 3 - 1
opcode.h

@@ -1,6 +1,6 @@
 /*
 ** TeCGraf - PUC-Rio
-** $Id: opcode.h,v 3.30 1997/03/20 19:20:43 roberto Exp roberto $
+** $Id: opcode.h,v 3.31 1997/03/31 14:02:58 roberto Exp roberto $
 */
 
 #ifndef opcode_h
@@ -35,6 +35,8 @@ typedef enum
 #define NUM_TYPES 10
 
 
+extern char *luaI_typenames[];
+
 typedef enum {
 /* name          parm    before          after           side effect
 -----------------------------------------------------------------------------*/

+ 11 - 11
strlib.c

@@ -3,7 +3,7 @@
 ** String library to LUA
 */
 
-char *rcs_strlib="$Id: strlib.c,v 1.37 1997/03/18 15:30:50 roberto Exp roberto $";
+char *rcs_strlib="$Id: strlib.c,v 1.38 1997/03/26 22:23:15 roberto Exp roberto $";
 
 #include <string.h>
 #include <stdio.h>
@@ -84,7 +84,7 @@ static void str_tok (void)
     lua_pushobject(t);
     lua_pushnumber(i++);
     lua_pushstring(s1);
-    lua_storesubscript();
+    lua_settable();
     s1 = NULL;  /* prepare for next strtok */
   }
   lua_pushobject(t);
@@ -121,10 +121,10 @@ static void str_sub (void)
 */
 static void str_lower (void)
 {
-  char *s = luaL_check_string(1, "strlower");
+  char *s;
   luaI_emptybuff();
-  while (*s)
-    luaI_addchar(tolower((unsigned char)*s++));
+  for (s = luaL_check_string(1, "strlower"); *s; s++)
+    luaI_addchar(tolower((unsigned char)*s));
   lua_pushstring(luaI_addchar(0));
 }
 
@@ -133,10 +133,10 @@ static void str_lower (void)
 */
 static void str_upper (void)
 {
-  char *s = luaL_check_string(1, "strupper");
+  char *s;
   luaI_emptybuff();
-  while (*s)
-    luaI_addchar(toupper((unsigned char)*s++));
+  for (s = luaL_check_string(1, "strupper"); *s; s++)
+    luaI_addchar(toupper((unsigned char)*s));
   lua_pushstring(luaI_addchar(0));
 }
 
@@ -177,11 +177,11 @@ char *luaL_item_end (char *p)
   switch (*p++) {
     case '\0': return p-1;
     case ESC:
-      if (*p == 0) lua_error("incorrect pattern");
+      if (*p == 0) luaL_verror("incorrect pattern (ends with `%c')", ESC);
       return p+1;
     case '[': {
       char *end = bracket_end(p);
-      if (end == NULL) lua_error("incorrect pattern");
+      if (end == NULL) lua_error("incorrect pattern (missing `]')");
       return end+1;
     }
     default:
@@ -492,7 +492,7 @@ static void str_format (void)
       char *initf = strfrmt-1;  /* -1 to include % */
       strfrmt = match(strfrmt, "[-+ #]*(%d*)%.?(%d*)", 0);
       if (capture[0].len > 3 || capture[1].len > 3)  /* < 1000? */
-        lua_error("invalid format (width/precision too long)");
+        lua_error("invalid format (width or precision too long)");
       strncpy(form, initf, strfrmt-initf+1); /* +1 to include convertion */
       form[strfrmt-initf+1] = 0;
       buff = openspace(1000);  /* to store the formated value */