Browse Source

"const" !!!

Roberto Ierusalimschy 26 years ago
parent
commit
c787dccd9b
40 changed files with 442 additions and 516 deletions
  1. 58 97
      lapi.c
  2. 3 3
      lapi.h
  3. 16 25
      lauxlib.c
  4. 10 10
      lauxlib.h
  5. 22 22
      lbuiltin.c
  6. 10 10
      ldblib.c
  7. 12 14
      ldo.c
  8. 3 3
      ldo.h
  9. 8 14
      lfunc.c
  10. 2 2
      lfunc.h
  11. 18 34
      lgc.c
  12. 3 3
      lgc.h
  13. 24 24
      liolib.c
  14. 8 8
      llex.c
  15. 3 3
      llex.h
  16. 2 2
      lmathlib.c
  17. 14 16
      lmem.c
  18. 2 2
      lmem.h
  19. 8 10
      lobject.c
  20. 5 5
      lobject.h
  21. 13 12
      lparser.c
  22. 3 3
      lparser.h
  23. 3 5
      lstate.c
  24. 10 10
      lstring.c
  25. 6 6
      lstring.h
  26. 47 44
      lstrlib.c
  27. 7 7
      ltable.c
  28. 6 6
      ltable.h
  29. 12 10
      ltm.c
  30. 6 6
      ltm.h
  31. 2 2
      lua.c
  32. 19 16
      lua.h
  33. 6 5
      luadebug.h
  34. 3 3
      lualib.h
  35. 6 6
      lundump.c
  36. 3 3
      lundump.h
  37. 18 21
      lvm.c
  38. 3 3
      lvm.h
  39. 28 31
      lzio.c
  40. 10 10
      lzio.h

+ 58 - 97
lapi.c

@@ -1,5 +1,5 @@
 /*
-** $Id: lapi.c,v 1.46 1999/06/17 17:04:03 roberto Exp roberto $
+** $Id: lapi.c,v 1.47 1999/06/22 20:37:23 roberto Exp roberto $
 ** Lua API
 ** See Copyright Notice in lua.h
 */
@@ -24,8 +24,8 @@
 #include "lvm.h"
 
 
-char lua_ident[] = "$Lua: " LUA_VERSION " " LUA_COPYRIGHT " $\n"
-                   "$Authors:  " LUA_AUTHORS " $";
+const char lua_ident[] = "$Lua: " LUA_VERSION " " LUA_COPYRIGHT " $\n"
+                               "$Authors:  " LUA_AUTHORS " $";
 
 
 
@@ -34,8 +34,7 @@ TObject *luaA_Address (lua_Object o) {
 }
 
 
-static lua_Type normalized_type (TObject *o)
-{
+static lua_Type normalized_type (const TObject *o) {
   int t = ttype(o);
   switch (t) {
     case LUA_T_PMARK:
@@ -50,21 +49,18 @@ static lua_Type normalized_type (TObject *o)
 }
 
 
-static void set_normalized (TObject *d, TObject *s)
-{
+static void set_normalized (TObject *d, const TObject *s) {
   d->value = s->value;
   d->ttype = normalized_type(s);
 }
 
 
-static TObject *luaA_protovalue (TObject *o)
-{
+static const TObject *luaA_protovalue (const TObject *o) {
   return (normalized_type(o) == LUA_T_CLOSURE) ?  protovalue(o) : o;
 }
 
 
-void luaA_packresults (void)
-{
+void luaA_packresults (void) {
   luaV_pack(L->Cstack.lua2C, L->Cstack.num, L->stack.top);
   incr_top;
 }
@@ -76,14 +72,13 @@ int luaA_passresults (void) {
 }
 
 
-static void checkCparams (int nParams)
-{
+static void checkCparams (int nParams) {
   if (L->stack.top-L->stack.stack < L->Cstack.base+nParams)
     lua_error("API error - wrong number of arguments in C2lua stack");
 }
 
 
-static lua_Object put_luaObject (TObject *o) {
+static lua_Object put_luaObject (const TObject *o) {
   luaD_openstack((L->stack.top-L->stack.stack)-L->Cstack.base);
   L->stack.stack[L->Cstack.base++] = *o;
   return L->Cstack.base;  /* this is +1 real position (see Ref) */
@@ -115,8 +110,7 @@ lua_Object lua_pop (void) {
 ** Get a parameter, returning the object handle or LUA_NOOBJECT on error.
 ** 'number' must be 1 to get the first parameter.
 */
-lua_Object lua_lua2C (int number)
-{
+lua_Object lua_lua2C (int number) {
   if (number <= 0 || number > L->Cstack.num) return LUA_NOOBJECT;
   /* Ref(L->stack.stack+(L->Cstack.lua2C+number-1)) ==
      L->stack.stack+(L->Cstack.lua2C+number-1)-L->stack.stack+1 == */
@@ -124,8 +118,7 @@ lua_Object lua_lua2C (int number)
 }
 
 
-int lua_callfunction (lua_Object function)
-{
+int lua_callfunction (lua_Object function) {
   if (function == LUA_NOOBJECT)
     return 1;
   else {
@@ -136,14 +129,12 @@ int lua_callfunction (lua_Object function)
 }
 
 
-lua_Object lua_gettagmethod (int tag, char *event)
-{
+lua_Object lua_gettagmethod (int tag, const char *event) {
   return put_luaObject(luaT_gettagmethod(tag, event));
 }
 
 
-lua_Object lua_settagmethod (int tag, char *event)
-{
+lua_Object lua_settagmethod (int tag, const char *event) {
   checkCparams(1);
   luaT_settagmethod(tag, event, L->stack.top-1);
   return put_luaObjectonTop();
@@ -159,8 +150,7 @@ lua_Object lua_seterrormethod (void) {
 }
 
 
-lua_Object lua_gettable (void)
-{
+lua_Object lua_gettable (void) {
   checkCparams(2);
   luaV_gettable();
   return put_luaObjectonTop();
@@ -190,8 +180,7 @@ void lua_rawsettable (void) {
 }
 
 
-lua_Object lua_createtable (void)
-{
+lua_Object lua_createtable (void) {
   TObject o;
   luaC_checkGC();
   avalue(&o) = luaH_new(0);
@@ -200,31 +189,27 @@ lua_Object lua_createtable (void)
 }
 
 
-lua_Object lua_getglobal (char *name)
-{
+lua_Object lua_getglobal (const char *name) {
   luaD_checkstack(2);  /* may need that to call T.M. */
   luaV_getglobal(luaS_new(name));
   return put_luaObjectonTop();
 }
 
 
-lua_Object lua_rawgetglobal (char *name)
-{
+lua_Object lua_rawgetglobal (const char *name) {
   TaggedString *ts = luaS_new(name);
   return put_luaObject(&ts->u.s.globalval);
 }
 
 
-void lua_setglobal (char *name)
-{
+void lua_setglobal (const char *name) {
   checkCparams(1);
   luaD_checkstack(2);  /* may need that to call T.M. */
   luaV_setglobal(luaS_new(name));
 }
 
 
-void lua_rawsetglobal (char *name)
-{
+void lua_rawsetglobal (const char *name) {
   TaggedString *ts = luaS_new(name);
   checkCparams(1);
   luaS_rawsetglobal(ts, --L->stack.top);
@@ -232,113 +217,96 @@ void lua_rawsetglobal (char *name)
 
 
 
-int lua_isnil (lua_Object o)
-{
+int lua_isnil (lua_Object o) {
   return (o!= LUA_NOOBJECT) && (ttype(Address(o)) == LUA_T_NIL);
 }
 
-int lua_istable (lua_Object o)
-{
+int lua_istable (lua_Object o) {
   return (o!= LUA_NOOBJECT) && (ttype(Address(o)) == LUA_T_ARRAY);
 }
 
-int lua_isuserdata (lua_Object o)
-{
+int lua_isuserdata (lua_Object o) {
   return (o!= LUA_NOOBJECT) && (ttype(Address(o)) == LUA_T_USERDATA);
 }
 
-int lua_iscfunction (lua_Object o)
-{
+int lua_iscfunction (lua_Object o) {
   return (lua_tag(o) == LUA_T_CPROTO);
 }
 
-int lua_isnumber (lua_Object o)
-{
+int lua_isnumber (lua_Object o) {
   return (o!= LUA_NOOBJECT) && (tonumber(Address(o)) == 0);
 }
 
-int lua_isstring (lua_Object o)
-{
+int lua_isstring (lua_Object o) {
   int t = lua_tag(o);
   return (t == LUA_T_STRING) || (t == LUA_T_NUMBER);
 }
 
-int lua_isfunction (lua_Object o)
-{
+int lua_isfunction (lua_Object o) {
   int t = lua_tag(o);
   return (t == LUA_T_PROTO) || (t == LUA_T_CPROTO);
 }
 
 
-double lua_getnumber (lua_Object object)
-{
+double lua_getnumber (lua_Object object) {
  if (object == LUA_NOOBJECT) return 0.0;
  if (tonumber(Address(object))) return 0.0;
  else return (nvalue(Address(object)));
 }
 
-char *lua_getstring (lua_Object object)
-{
+const char *lua_getstring (lua_Object object) {
   luaC_checkGC();  /* "tostring" may create a new string */
   if (object == LUA_NOOBJECT || tostring(Address(object)))
     return NULL;
   else return (svalue(Address(object)));
 }
 
-long lua_strlen (lua_Object object)
-{
+long lua_strlen (lua_Object object) {
   luaC_checkGC();  /* "tostring" may create a new string */
   if (object == LUA_NOOBJECT || tostring(Address(object)))
     return 0L;
   else return (tsvalue(Address(object))->u.s.len);
 }
 
-void *lua_getuserdata (lua_Object object)
-{
+void *lua_getuserdata (lua_Object object) {
   if (object == LUA_NOOBJECT || ttype(Address(object)) != LUA_T_USERDATA)
     return NULL;
   else return tsvalue(Address(object))->u.d.v;
 }
 
-lua_CFunction lua_getcfunction (lua_Object object)
-{
+lua_CFunction lua_getcfunction (lua_Object object) {
   if (!lua_iscfunction(object))
     return NULL;
   else return fvalue(luaA_protovalue(Address(object)));
 }
 
 
-void lua_pushnil (void)
-{
+void lua_pushnil (void) {
   ttype(L->stack.top) = LUA_T_NIL;
   incr_top;
 }
 
-void lua_pushnumber (double n)
-{
+void lua_pushnumber (double n) {
   ttype(L->stack.top) = LUA_T_NUMBER;
   nvalue(L->stack.top) = n;
   incr_top;
 }
 
-void lua_pushlstring (char *s, long len)
-{
+void lua_pushlstring (const char *s, long len) {
   tsvalue(L->stack.top) = luaS_newlstr(s, len);
   ttype(L->stack.top) = LUA_T_STRING;
   incr_top;
   luaC_checkGC();
 }
 
-void lua_pushstring (char *s)
-{
+void lua_pushstring (const char *s) {
   if (s == NULL)
     lua_pushnil();
   else
     lua_pushlstring(s, strlen(s));
 }
 
-void lua_pushcclosure (lua_CFunction fn, int n)
-{
+void lua_pushcclosure (lua_CFunction fn, int n) {
   if (fn == NULL)
     lua_error("API error - attempt to push a NULL Cfunction");
   checkCparams(n);
@@ -349,8 +317,7 @@ void lua_pushcclosure (lua_CFunction fn, int n)
   luaC_checkGC();
 }
 
-void lua_pushusertag (void *u, int tag)
-{
+void lua_pushusertag (void *u, int tag) {
   if (tag < 0 && tag != LUA_ANYTAG)
     luaT_realtag(tag);  /* error if tag is not valid */
   tsvalue(L->stack.top) = luaS_createudata(u, tag);
@@ -359,8 +326,7 @@ void lua_pushusertag (void *u, int tag)
   luaC_checkGC();
 }
 
-void luaA_pushobject (TObject *o)
-{
+void luaA_pushobject (const TObject *o) {
   *L->stack.top = *o;
   incr_top;
 }
@@ -373,12 +339,11 @@ void lua_pushobject (lua_Object o) {
 }
 
 
-int lua_tag (lua_Object lo)
-{
+int lua_tag (lua_Object lo) {
   if (lo == LUA_NOOBJECT)
      return LUA_T_NIL;
   else {
-    TObject *o = Address(lo);
+    const TObject *o = Address(lo);
     int t;
     switch (t = ttype(o)) {
       case LUA_T_USERDATA:
@@ -402,8 +367,7 @@ int lua_tag (lua_Object lo)
 }
 
 
-void lua_settag (int tag)
-{
+void lua_settag (int tag) {
   checkCparams(1);
   luaT_realtag(tag);
   switch (ttype(L->stack.top-1)) {
@@ -440,7 +404,7 @@ TaggedString *luaA_nextvar (TaggedString *g) {
 }
 
 
-char *lua_nextvar (char *varname) {
+const char *lua_nextvar (const char *varname) {
   TaggedString *g = (varname == NULL) ? NULL : luaS_new(varname);
   g = luaA_nextvar(g);
   if (g) {
@@ -454,7 +418,7 @@ char *lua_nextvar (char *varname) {
 }
 
 
-int luaA_next (Hash *t, int i) {
+int luaA_next (const Hash *t, int i) {
   int tsize = nhash(t);
   for (; i<tsize; i++) {
     Node *n = node(t, i);
@@ -469,7 +433,7 @@ int luaA_next (Hash *t, int i) {
 
 
 int lua_next (lua_Object o, int i) {
-  TObject *t = Address(o);
+  const TObject *t = Address(o);
   if (ttype(t) != LUA_T_ARRAY)
     lua_error("API error - object is not a table in `lua_next'"); 
   i = luaA_next(avalue(t), i);
@@ -519,8 +483,7 @@ int lua_setdebug (int debug) {
 */
 
 
-lua_Function lua_stackedfunction (int level)
-{
+lua_Function lua_stackedfunction (int level) {
   StkId i;
   for (i = (L->stack.top-1)-L->stack.stack; i>=0; i--) {
     int t = L->stack.stack[i].ttype;
@@ -533,20 +496,20 @@ lua_Function lua_stackedfunction (int level)
 
 
 int lua_nups (lua_Function func) {
-  TObject *o = luaA_Address(func);
+  const TObject *o = luaA_Address(func);
   return (!o || normalized_type(o) != LUA_T_CLOSURE) ? 0 : o->value.cl->nelems;
 }
 
 
-int lua_currentline (lua_Function func)
-{
-  TObject *f = Address(func);
+int lua_currentline (lua_Function func) {
+  const TObject *f = Address(func);
   return (f+1 < L->stack.top && (f+1)->ttype == LUA_T_LINE) ?
              (f+1)->value.i : -1;
 }
 
 
-lua_Object lua_getlocal (lua_Function func, int local_number, char **name) {
+lua_Object lua_getlocal (lua_Function func, int local_number,
+                         const char **name) {
   /* check whether func is a Lua function */
   if (lua_tag(func) != LUA_T_PROTO)
     return LUA_NOOBJECT;
@@ -565,15 +528,14 @@ lua_Object lua_getlocal (lua_Function func, int local_number, char **name) {
 }
 
 
-int lua_setlocal (lua_Function func, int local_number)
-{
+int lua_setlocal (lua_Function func, int local_number) {
   /* check whether func is a Lua function */
   if (lua_tag(func) != LUA_T_PROTO)
     return 0;
   else {
     TObject *f = Address(func);
     TProtoFunc *fp = luaA_protovalue(f)->value.tf;
-    char *name = luaF_getlocalname(fp, local_number, lua_currentline(func));
+    const char *name = luaF_getlocalname(fp, local_number, lua_currentline(func));
     checkCparams(1);
     --L->stack.top;
     if (name) {
@@ -588,11 +550,11 @@ int lua_setlocal (lua_Function func, int local_number)
 }
 
 
-void lua_funcinfo (lua_Object func, char **source, int *linedefined) {
+void lua_funcinfo (lua_Object func, const char **source, int *linedefined) {
   if (!lua_isfunction(func))
     lua_error("API error - `funcinfo' called with a non-function value");
   else {
-    TObject *f = luaA_protovalue(Address(func));
+    const TObject *f = luaA_protovalue(Address(func));
     if (normalized_type(f) == LUA_T_PROTO) {
       *source = tfvalue(f)->source->str;
       *linedefined = tfvalue(f)->lineDefined;
@@ -605,14 +567,13 @@ void lua_funcinfo (lua_Object func, char **source, int *linedefined) {
 }
 
 
-static int checkfunc (TObject *o)
-{
+static int checkfunc (TObject *o) {
   return luaO_equalObj(o, L->stack.top);
 }
 
 
-char *lua_getobjname (lua_Object o, char **name)
-{ /* try to find a name for given function */
+const char *lua_getobjname (lua_Object o, const char **name) {
+  /* try to find a name for given function */
   set_normalized(L->stack.top, Address(o)); /* to be accessed by "checkfunc" */
   if ((*name = luaS_travsymbol(checkfunc)) != NULL)
     return "global";
@@ -662,7 +623,7 @@ int lua_ref (int lock) {
 
 
 lua_Object lua_getref (int ref) {
-  TObject *o = luaC_getref(ref);
+  const TObject *o = luaC_getref(ref);
   return (o ? put_luaObject(o) : LUA_NOOBJECT);
 }
 

+ 3 - 3
lapi.h

@@ -1,5 +1,5 @@
 /*
-** $Id: lapi.h,v 1.3 1999/02/22 19:13:12 roberto Exp roberto $
+** $Id: lapi.h,v 1.4 1999/02/23 14:57:28 roberto Exp roberto $
 ** Auxiliary functions from Lua API
 ** See Copyright Notice in lua.h
 */
@@ -13,10 +13,10 @@
 
 
 TObject *luaA_Address (lua_Object o);
-void luaA_pushobject (TObject *o);
+void luaA_pushobject (const TObject *o);
 void luaA_packresults (void);
 int luaA_passresults (void);
 TaggedString *luaA_nextvar (TaggedString *g);
-int luaA_next (Hash *t, int i);
+int luaA_next (const Hash *t, int i);
 
 #endif

+ 16 - 25
lauxlib.c

@@ -1,5 +1,5 @@
 /*
-** $Id: lauxlib.c,v 1.16 1999/03/10 14:19:41 roberto Exp roberto $
+** $Id: lauxlib.c,v 1.17 1999/03/11 18:59:19 roberto Exp roberto $
 ** Auxiliary functions for building Lua libraries
 ** See Copyright Notice in lua.h
 */
@@ -20,7 +20,7 @@
 
 
 
-int luaL_findstring (char *name, char *list[]) {
+int luaL_findstring (const char *name, const char *const list[]) {
   int i;
   for (i=0; list[i]; i++)
     if (strcmp(list[i], name) == 0)
@@ -28,9 +28,9 @@ int luaL_findstring (char *name, char *list[]) {
   return -1;  /* name not found */
 }
 
-void luaL_argerror (int numarg, char *extramsg) {
+void luaL_argerror (int numarg, const char *extramsg) {
   lua_Function f = lua_stackedfunction(0);
-  char *funcname;
+  const char *funcname;
   lua_getobjname(f, &funcname);
   numarg -= lua_nups(f);
   if (funcname == NULL)
@@ -42,58 +42,50 @@ void luaL_argerror (int numarg, char *extramsg) {
                     numarg, funcname, extramsg);
 }
 
-char *luaL_check_lstr (int numArg, long *len)
-{
+const char *luaL_check_lstr (int numArg, long *len) {
   lua_Object o = lua_getparam(numArg);
   luaL_arg_check(lua_isstring(o), numArg, "string expected");
   if (len) *len = lua_strlen(o);
   return lua_getstring(o);
 }
 
-char *luaL_opt_lstr (int numArg, char *def, long *len)
-{
+const char *luaL_opt_lstr (int numArg, const char *def, long *len) {
   return (lua_getparam(numArg) == LUA_NOOBJECT) ? def :
                               luaL_check_lstr(numArg, len);
 }
 
-double luaL_check_number (int numArg)
-{
+double luaL_check_number (int numArg) {
   lua_Object o = lua_getparam(numArg);
   luaL_arg_check(lua_isnumber(o), numArg, "number expected");
   return lua_getnumber(o);
 }
 
 
-double luaL_opt_number (int numArg, double def)
-{
+double luaL_opt_number (int numArg, double def) {
   return (lua_getparam(numArg) == LUA_NOOBJECT) ? def :
                               luaL_check_number(numArg);
 }  
 
 
-lua_Object luaL_tablearg (int arg)
-{
+lua_Object luaL_tablearg (int arg) {
   lua_Object o = lua_getparam(arg);
   luaL_arg_check(lua_istable(o), arg, "table expected");
   return o;
 }
 
-lua_Object luaL_functionarg (int arg)
-{
+lua_Object luaL_functionarg (int arg) {
   lua_Object o = lua_getparam(arg);
   luaL_arg_check(lua_isfunction(o), arg, "function expected");
   return o;
 }
 
-lua_Object luaL_nonnullarg (int numArg)
-{
+lua_Object luaL_nonnullarg (int numArg) {
   lua_Object o = lua_getparam(numArg);
   luaL_arg_check(o != LUA_NOOBJECT, numArg, "value expected");
   return o;
 }
 
-void luaL_openlib (struct luaL_reg *l, int n)
-{
+void luaL_openlib (const struct luaL_reg *l, int n) {
   int i;
   lua_open();  /* make sure lua is already open */
   for (i=0; i<n; i++)
@@ -101,8 +93,7 @@ void luaL_openlib (struct luaL_reg *l, int n)
 }
 
 
-void luaL_verror (char *fmt, ...)
-{
+void luaL_verror (const char *fmt, ...) {
   char buff[500];
   va_list argp;
   va_start(argp, fmt);
@@ -112,14 +103,14 @@ void luaL_verror (char *fmt, ...)
 }
 
 
-void luaL_chunkid (char *out, char *source, int len) {
+void luaL_chunkid (char *out, const char *source, int len) {
   len -= 13;  /* 13 = strlen("string ''...\0") */
   if (*source == '@')
     sprintf(out, "file `%.*s'", len, source+1);
   else if (*source == '(')
     strcpy(out, "(C code)");
   else {
-    char *b = strchr(source , '\n');  /* stop string at first new line */
+    const char *b = strchr(source , '\n');  /* stop string at first new line */
     int lim = (b && (b-source)<len) ? b-source : len;
     sprintf(out, "string `%.*s'", lim, source);
     strcpy(out+lim+(13-5), "...'");  /* 5 = strlen("...'\0") */
@@ -127,7 +118,7 @@ void luaL_chunkid (char *out, char *source, int len) {
 }
 
 
-void luaL_filesource (char *out, char *filename, int len) {
+void luaL_filesource (char *out, const char *filename, int len) {
   if (filename == NULL) filename = "(stdin)";
   sprintf(out, "@%.*s", len-2, filename);  /* -2 for '@' and '\0' */
 }

+ 10 - 10
lauxlib.h

@@ -1,5 +1,5 @@
 /*
-** $Id: lauxlib.h,v 1.11 1999/03/04 21:17:26 roberto Exp roberto $
+** $Id: lauxlib.h,v 1.12 1999/03/10 14:19:41 roberto Exp roberto $
 ** Auxiliary functions for building Lua libraries
 ** See Copyright Notice in lua.h
 */
@@ -13,7 +13,7 @@
 
 
 struct luaL_reg {
-  char *name;
+  const char *name;
   lua_CFunction func;
 };
 
@@ -21,12 +21,12 @@ struct luaL_reg {
 #define luaL_arg_check(cond,numarg,extramsg) if (!(cond)) \
                                                luaL_argerror(numarg,extramsg)
 
-void luaL_openlib (struct luaL_reg *l, int n);
-void luaL_argerror (int numarg, char *extramsg);
+void luaL_openlib (const struct luaL_reg *l, int n);
+void luaL_argerror (int numarg, const char *extramsg);
 #define luaL_check_string(n)  (luaL_check_lstr((n), NULL))
-char *luaL_check_lstr (int numArg, long *len);
+const char *luaL_check_lstr (int numArg, long *len);
 #define luaL_opt_string(n, d) (luaL_opt_lstr((n), (d), NULL))
-char *luaL_opt_lstr (int numArg, char *def, long *len);
+const char *luaL_opt_lstr (int numArg, const char *def, long *len);
 double luaL_check_number (int numArg);
 #define luaL_check_int(n)	((int)luaL_check_number(n))
 #define luaL_check_long(n)	((long)luaL_check_number(n))
@@ -36,7 +36,7 @@ double luaL_opt_number (int numArg, double def);
 lua_Object luaL_functionarg (int arg);
 lua_Object luaL_tablearg (int arg);
 lua_Object luaL_nonnullarg (int numArg);
-void luaL_verror (char *fmt, ...);
+void luaL_verror (const char *fmt, ...);
 char *luaL_openspace (int size);
 void luaL_resetbuffer (void);
 void luaL_addchar (int c);
@@ -45,9 +45,9 @@ void luaL_addsize (int n);
 int luaL_newbuffer (int size);
 void luaL_oldbuffer (int old);
 char *luaL_buffer (void);
-int luaL_findstring (char *name, char *list[]);
-void luaL_chunkid (char *out, char *source, int len);
-void luaL_filesource (char *out, char *filename, int len);
+int luaL_findstring (const char *name, const char *const list[]);
+void luaL_chunkid (char *out, const char *source, int len);
+void luaL_filesource (char *out, const char *filename, int len);
 
 
 #endif

+ 22 - 22
lbuiltin.c

@@ -1,5 +1,5 @@
 /*
-** $Id: lbuiltin.c,v 1.59 1999/06/17 17:04:03 roberto Exp roberto $
+** $Id: lbuiltin.c,v 1.60 1999/07/22 19:35:41 roberto Exp roberto $
 ** Built-in functions
 ** See Copyright Notice in lua.h
 */
@@ -42,7 +42,7 @@ static void pushtagstring (TaggedString *s) {
 }
 
 
-static real getsize (Hash *h) {
+static real getsize (const Hash *h) {
   real max = 0;
   int i;
   for (i = 0; i<nhash(h); i++) {
@@ -56,7 +56,7 @@ static real getsize (Hash *h) {
 }
 
 
-static real getnarg (Hash *a) {
+static real getnarg (const Hash *a) {
   TObject index;
   TObject *value;
   /* value = table.n */
@@ -146,10 +146,10 @@ static void luaB_tonumber (void) {
     else lua_pushnil();  /* not a number */
   }
   else {
-    char *s = luaL_check_string(1);
+    char *s;
     long n;
     luaL_arg_check(0 <= base && base <= 36, 2, "base out of range");
-    n = strtol(s, &s, base);
+    n = strtol(luaL_check_string(1), &s, base);
     while (isspace((unsigned char)*s)) s++;  /* skip trailing spaces */
     if (*s) lua_pushnil();  /* invalid format: return nil */
     else lua_pushnumber(n);
@@ -162,7 +162,7 @@ static void luaB_error (void) {
 }
 
 static void luaB_setglobal (void) {
-  char *n = luaL_check_string(1);
+  const char *n = luaL_check_string(1);
   lua_Object value = luaL_nonnullarg(2);
   lua_pushobject(value);
   lua_setglobal(n);
@@ -170,7 +170,7 @@ static void luaB_setglobal (void) {
 }
 
 static void luaB_rawsetglobal (void) {
-  char *n = luaL_check_string(1);
+  const char *n = luaL_check_string(1);
   lua_Object value = luaL_nonnullarg(2);
   lua_pushobject(value);
   lua_rawsetglobal(n);
@@ -250,7 +250,7 @@ static void luaB_collectgarbage (void) {
 
 static void luaB_dostring (void) {
   long l;
-  char *s = luaL_check_lstr(1, &l);
+  const char *s = luaL_check_lstr(1, &l);
   if (*s == ID_CHUNK)
     lua_error("`dostring' cannot run pre-compiled code");
   if (lua_dobuffer(s, l, luaL_opt_string(2, s)) == 0)
@@ -260,7 +260,7 @@ static void luaB_dostring (void) {
 
 
 static void luaB_dofile (void) {
-  char *fname = luaL_opt_string(1, NULL);
+  const char *fname = luaL_opt_string(1, NULL);
   if (lua_dofile(fname) == 0)
     if (luaA_passresults() == 0)
       lua_pushuserdata(NULL);  /* at least one result to signal no errors */
@@ -269,8 +269,8 @@ static void luaB_dofile (void) {
 
 static void luaB_call (void) {
   lua_Object f = luaL_nonnullarg(1);
-  Hash *arg = gethash(2);
-  char *options = luaL_opt_string(3, "");
+  const Hash *arg = gethash(2);
+  const char *options = luaL_opt_string(3, "");
   lua_Object err = lua_getparam(4);
   int narg = (int)getnarg(arg);
   int i, status;
@@ -305,7 +305,7 @@ static void luaB_call (void) {
 
 
 static void luaB_nextvar (void) {
-  TObject *o = luaA_Address(luaL_nonnullarg(1));
+  const TObject *o = luaA_Address(luaL_nonnullarg(1));
   TaggedString *g;
   if (ttype(o) == LUA_T_NIL)
     g = NULL;
@@ -319,8 +319,8 @@ static void luaB_nextvar (void) {
 
 
 static void luaB_next (void) {
-  Hash *a = gethash(1);
-  TObject *k = luaA_Address(luaL_nonnullarg(2));
+  const Hash *a = gethash(1);
+  const TObject *k = luaA_Address(luaL_nonnullarg(2));
   int i = (ttype(k) == LUA_T_NIL) ? 0 : luaH_pos(a, k)+1;
   if (luaA_next(a, i) == 0)
     lua_pushnil();
@@ -329,7 +329,7 @@ static void luaB_next (void) {
 
 static void luaB_tostring (void) {
   lua_Object obj = lua_getparam(1);
-  TObject *o = luaA_Address(obj);
+  const TObject *o = luaA_Address(obj);
   char buff[64];
   switch (ttype(o)) {
     case LUA_T_NUMBER:
@@ -391,7 +391,7 @@ static void luaB_assert (void) {
 
 
 static void luaB_foreachi (void) {
-  Hash *t = gethash(1);
+  const Hash *t = gethash(1);
   int i;
   int n = (int)getnarg(t);
   TObject f;
@@ -413,13 +413,13 @@ static void luaB_foreachi (void) {
 
 
 static void luaB_foreach (void) {
-  Hash *a = gethash(1);
+  const Hash *a = gethash(1);
   int i;
   TObject f;  /* see comment in 'foreachi' */
   f = *luaA_Address(luaL_functionarg(2));
   luaD_checkstack(3);  /* for f, ref, and val */
   for (i=0; i<a->nhash; i++) {
-    Node *nd = &(a->node[i]);
+    const Node *nd = &(a->node[i]);
     if (ttype(val(nd)) != LUA_T_NIL) {
       *(L->stack.top++) = f;
       *(L->stack.top++) = *ref(nd);
@@ -504,7 +504,7 @@ static void swap (Hash *a, int i, int j) {
   luaH_setint(a, j, &temp);
 }
 
-static int sort_comp (lua_Object f, TObject *a, TObject *b) {
+static int sort_comp (lua_Object f, const TObject *a, const TObject *b) {
   /* notice: the caller (auxsort) must check stack space */
   if (f != LUA_NOOBJECT) {
     *(L->stack.top) = *luaA_Address(f);
@@ -604,7 +604,7 @@ static void query_strings (void) {
 
 
 static void countlist (void) {
-  char *s = luaL_check_string(1);
+  const char *s = luaL_check_string(1);
   GCnode *l = (s[0]=='t') ? L->roottable.next : (s[0]=='c') ? L->rootcl.next :
               (s[0]=='p') ? L->rootproto.next : L->rootglobal.next;
   int i=0;
@@ -623,7 +623,7 @@ static void testC (void) {
   static int locks[10];
   lua_Object reg[10];
   char nome[2];
-  char *s = luaL_check_string(1);
+  const char *s = luaL_check_string(1);
   nome[1] = 0;
   for (;;) {
     switch (*s++) {
@@ -674,7 +674,7 @@ static void testC (void) {
 
 
 
-static struct luaL_reg builtin_funcs[] = {
+static const struct luaL_reg builtin_funcs[] = {
 #ifdef LUA_COMPAT2_5
   {"setfallback", luaT_setfallback},
 #endif

+ 10 - 10
ldblib.c

@@ -1,5 +1,5 @@
 /*
-** $Id: ldblib.c,v 1.4 1999/02/04 17:47:59 roberto Exp roberto $
+** $Id: ldblib.c,v 1.5 1999/03/04 21:17:26 roberto Exp roberto $
 ** Interface from Lua to its debug API
 ** See Copyright Notice in lua.h
 */
@@ -15,7 +15,7 @@
 
 
 
-static void settabss (lua_Object t, char *i, char *v) {
+static void settabss (lua_Object t, const char *i, const char *v) {
   lua_pushobject(t);
   lua_pushstring(i);
   lua_pushstring(v);
@@ -23,7 +23,7 @@ static void settabss (lua_Object t, char *i, char *v) {
 }
 
 
-static void settabsi (lua_Object t, char *i, int v) {
+static void settabsi (lua_Object t, const char *i, int v) {
   lua_pushobject(t);
   lua_pushstring(i);
   lua_pushnumber(v);
@@ -33,7 +33,7 @@ static void settabsi (lua_Object t, char *i, int v) {
 
 static lua_Object getfuncinfo (lua_Object func) {
   lua_Object result = lua_createtable();
-  char *str;
+  const char *str;
   int line;
   lua_funcinfo(func, &str, &line);
   if (line == -1)  /* C function? */
@@ -48,7 +48,7 @@ static lua_Object getfuncinfo (lua_Object func) {
     settabss(result, "source", str);
   }
   if (line != 0) {  /* is it not a "main"? */
-    char *kind = lua_getobjname(func, &str);
+    const char *kind = lua_getobjname(func, &str);
     if (*kind) {
       settabss(result, "name", str);
       settabss(result, "where", kind);
@@ -86,10 +86,10 @@ static int findlocal (lua_Object func, int arg) {
   if (lua_isnumber(v))
     return (int)lua_getnumber(v);
   else {
-    char *name = luaL_check_string(arg);
+    const char *name = luaL_check_string(arg);
     int i = 0;
     int result = -1;
-    char *vname;
+    const char *vname;
     while (lua_getlocal(func, ++i, &vname) != LUA_NOOBJECT) {
       if (strcmp(name, vname) == 0)
         result = i;  /* keep looping to get the last var with this name */
@@ -104,7 +104,7 @@ static int findlocal (lua_Object func, int arg) {
 static void getlocal (void) {
   lua_Object func = lua_stackedfunction(luaL_check_int(1));
   lua_Object val;
-  char *name;
+  const char *name;
   if (func == LUA_NOOBJECT)  /* level out of range? */
     return;  /* return nil */
   else if (lua_getparam(2) != LUA_NOOBJECT) {  /* 2nd argument? */
@@ -161,7 +161,7 @@ static void linef (int line) {
 }
 
 
-static void callf (lua_Function func, char *file, int line) {
+static void callf (lua_Function func, const char *file, int line) {
   if (func != LUA_NOOBJECT) {
     lua_pushobject(func);
     lua_pushstring(file);
@@ -201,7 +201,7 @@ static void setlinehook (void) {
 }
 
 
-static struct luaL_reg dblib[] = {
+static const struct luaL_reg dblib[] = {
   {"funcinfo", funcinfo},
   {"getlocal", getlocal},
   {"getstack", getstack},

+ 12 - 14
ldo.c

@@ -1,5 +1,5 @@
 /*
-** $Id: ldo.c,v 1.44 1999/06/17 17:04:03 roberto Exp roberto $
+** $Id: ldo.c,v 1.45 1999/06/22 20:37:23 roberto Exp roberto $
 ** Stack and Call structure of Lua
 ** See Copyright Notice in lua.h
 */
@@ -159,7 +159,7 @@ static StkId callCclosure (struct Closure *cl, lua_CFunction f, StkId base) {
 }
 
 
-void luaD_callTM (TObject *f, int nParams, int nResults) {
+void luaD_callTM (const TObject *f, int nParams, int nResults) {
   luaD_openstack(nParams);
   *(L->stack.top-nParams-1) = *f;
   luaD_calln(nParams, nResults);
@@ -199,7 +199,7 @@ void luaD_calln (int nArgs, int nResults) {
     }
     default: { /* func is not a function */
       /* Check the tag method for invalid functions */
-      TObject *im = luaT_getimbyObj(func, IM_FUNCTION);
+      const TObject *im = luaT_getimbyObj(func, IM_FUNCTION);
       if (ttype(im) == LUA_T_NIL)
         lua_error("call expression not a function");
       luaD_callTM(im, (S->top-S->stack)-(base-1), nResults);
@@ -222,8 +222,7 @@ void luaD_calln (int nArgs, int nResults) {
 /*
 ** Traverse all objects on L->stack.stack
 */
-void luaD_travstack (int (*fn)(TObject *))
-{
+void luaD_travstack (int (*fn)(TObject *)) {
   StkId i;
   for (i = (L->stack.top-1)-L->stack.stack; i>=0; i--)
     fn(L->stack.stack+i);
@@ -231,8 +230,8 @@ void luaD_travstack (int (*fn)(TObject *))
 
 
 
-static void message (char *s) {
-  TObject *em = &(luaS_new("_ERRORMESSAGE")->u.s.globalval);
+static void message (const char *s) {
+  const TObject *em = &(luaS_new("_ERRORMESSAGE")->u.s.globalval);
   if (ttype(em) == LUA_T_PROTO || ttype(em) == LUA_T_CPROTO ||
       ttype(em) == LUA_T_CLOSURE) {
     *L->stack.top = *em;
@@ -245,7 +244,7 @@ static void message (char *s) {
 /*
 ** Reports an error, and jumps up to the available recover label
 */
-void lua_error (char *s) {
+void lua_error (const char *s) {
   if (s) message(s);
   if (L->errorJmp)
     longjmp(L->errorJmp->b, 1);
@@ -335,9 +334,8 @@ static int do_main (ZIO *z, int bin) {
 }
 
 
-void luaD_gcIM (TObject *o)
-{
-  TObject *im = luaT_getimbyObj(o, IM_GC);
+void luaD_gcIM (const TObject *o) {
+  const TObject *im = luaT_getimbyObj(o, IM_GC);
   if (ttype(im) != LUA_T_NIL) {
     *L->stack.top = *o;
     incr_top;
@@ -348,7 +346,7 @@ void luaD_gcIM (TObject *o)
 
 #define	MAXFILENAME	260	/* maximum part of a file name kept */
 
-int lua_dofile (char *filename) {
+int lua_dofile (const char *filename) {
   ZIO z;
   int status;
   int c;
@@ -371,12 +369,12 @@ int lua_dofile (char *filename) {
 }
 
 
-int lua_dostring (char *str) {
+int lua_dostring (const char *str) {
   return lua_dobuffer(str, strlen(str), str);
 }
 
 
-int lua_dobuffer (char *buff, int size, char *name) {
+int lua_dobuffer (const char *buff, int size, const char *name) {
   ZIO z;
   if (!name) name = "?";
   luaZ_mopen(&z, buff, size, name);

+ 3 - 3
ldo.h

@@ -1,5 +1,5 @@
 /*
-** $Id: ldo.h,v 1.5 1998/07/12 16:14:34 roberto Exp roberto $
+** $Id: ldo.h,v 1.6 1999/06/22 20:37:23 roberto Exp roberto $
 ** Stack and Call structure of Lua
 ** See Copyright Notice in lua.h
 */
@@ -36,9 +36,9 @@ void luaD_openstack (int nelems);
 void luaD_lineHook (int line);
 void luaD_callHook (StkId base, TProtoFunc *tf, int isreturn);
 void luaD_calln (int nArgs, int nResults);
-void luaD_callTM (TObject *f, int nParams, int nResults);
+void luaD_callTM (const TObject *f, int nParams, int nResults);
 int luaD_protectedrun (void);
-void luaD_gcIM (TObject *o);
+void luaD_gcIM (const TObject *o);
 void luaD_travstack (int (*fn)(TObject *));
 void luaD_checkstack (int n);
 

+ 8 - 14
lfunc.c

@@ -1,5 +1,5 @@
 /*
-** $Id: lfunc.c,v 1.9 1998/06/19 16:14:09 roberto Exp roberto $
+** $Id: lfunc.c,v 1.10 1999/03/04 21:17:26 roberto Exp roberto $
 ** Auxiliary functions to manipulate prototypes and closures
 ** See Copyright Notice in lua.h
 */
@@ -16,8 +16,7 @@
 
 
 
-Closure *luaF_newclosure (int nelems)
-{
+Closure *luaF_newclosure (int nelems) {
   Closure *c = (Closure *)luaM_malloc(sizeof(Closure)+nelems*sizeof(TObject));
   luaO_insertlist(&(L->rootcl), (GCnode *)c);
   L->nblocks += gcsizeclosure(c);
@@ -26,8 +25,7 @@ Closure *luaF_newclosure (int nelems)
 }
 
 
-TProtoFunc *luaF_newproto (void)
-{
+TProtoFunc *luaF_newproto (void) {
   TProtoFunc *f = luaM_new(TProtoFunc);
   f->code = NULL;
   f->lineDefined = 0;
@@ -42,8 +40,7 @@ TProtoFunc *luaF_newproto (void)
 
 
 
-static void freefunc (TProtoFunc *f)
-{
+static void freefunc (TProtoFunc *f) {
   luaM_free(f->code);
   luaM_free(f->locvars);
   luaM_free(f->consts);
@@ -51,8 +48,7 @@ static void freefunc (TProtoFunc *f)
 }
 
 
-void luaF_freeproto (TProtoFunc *l)
-{
+void luaF_freeproto (TProtoFunc *l) {
   while (l) {
     TProtoFunc *next = (TProtoFunc *)l->head.next;
     L->nblocks -= gcsizeproto(l);
@@ -62,8 +58,7 @@ void luaF_freeproto (TProtoFunc *l)
 }
 
 
-void luaF_freeclosure (Closure *l)
-{
+void luaF_freeclosure (Closure *l) {
   while (l) {
     Closure *next = (Closure *)l->head.next;
     L->nblocks -= gcsizeclosure(l);
@@ -77,10 +72,9 @@ void luaF_freeclosure (Closure *l)
 ** Look for n-th local variable at line "line" in function "func".
 ** Returns NULL if not found.
 */
-char *luaF_getlocalname (TProtoFunc *func, int local_number, int line)
-{
+const char *luaF_getlocalname (TProtoFunc *func, int local_number, int line) {
   int count = 0;
-  char *varname = NULL;
+  const char *varname = NULL;
   LocVar *lv = func->locvars;
   if (lv == NULL)
     return NULL;

+ 2 - 2
lfunc.h

@@ -1,5 +1,5 @@
 /*
-** $Id: lfunc.h,v 1.4 1997/11/19 17:29:23 roberto Exp roberto $
+** $Id: lfunc.h,v 1.5 1997/12/15 16:17:20 roberto Exp roberto $
 ** Lua Function structures
 ** See Copyright Notice in lua.h
 */
@@ -17,7 +17,7 @@ Closure *luaF_newclosure (int nelems);
 void luaF_freeproto (TProtoFunc *l);
 void luaF_freeclosure (Closure *l);
 
-char *luaF_getlocalname (TProtoFunc *func, int local_number, int line);
+const char *luaF_getlocalname (TProtoFunc *func, int local_number, int line);
 
 
 #endif

+ 18 - 34
lgc.c

@@ -1,5 +1,5 @@
 /*
-** $Id: lgc.c,v 1.23 1999/03/04 21:17:26 roberto Exp roberto $
+** $Id: lgc.c,v 1.24 1999/08/11 17:00:59 roberto Exp roberto $
 ** Garbage Collector
 ** See Copyright Notice in lua.h
 */
@@ -29,7 +29,7 @@ static int markobject (TObject *o);
 */
 
 
-int luaC_ref (TObject *o, int lock) {
+int luaC_ref (const TObject *o, int lock) {
   int ref;
   if (ttype(o) == LUA_T_NIL)
     ref = LUA_REFNIL;
@@ -48,15 +48,13 @@ int luaC_ref (TObject *o, int lock) {
 }
 
 
-void lua_unref (int ref)
-{
+void lua_unref (int ref) {
   if (ref >= 0 && ref < L->refSize)
     L->refArray[ref].status = FREE;
 }
 
 
-TObject* luaC_getref (int ref)
-{
+const TObject *luaC_getref (int ref) {
   if (ref == LUA_REFNIL)
     return &luaO_nilobject;
   if (ref >= 0 && ref < L->refSize &&
@@ -67,8 +65,7 @@ TObject* luaC_getref (int ref)
 }
 
 
-static void travlock (void)
-{
+static void travlock (void) {
   int i;
   for (i=0; i<L->refSize; i++)
     if (L->refArray[i].status == LOCK)
@@ -76,8 +73,7 @@ static void travlock (void)
 }
 
 
-static int ismarked (TObject *o)
-{
+static int ismarked (const TObject *o) {
   /* valid only for locked objects */
   switch (o->ttype) {
     case LUA_T_STRING: case LUA_T_USERDATA:
@@ -99,8 +95,7 @@ static int ismarked (TObject *o)
 }
 
 
-static void invalidaterefs (void)
-{
+static void invalidaterefs (void) {
   int i;
   for (i=0; i<L->refSize; i++)
     if (L->refArray[i].status == HOLD && !ismarked(&L->refArray[i].o))
@@ -109,8 +104,7 @@ static void invalidaterefs (void)
 
 
 
-void luaC_hashcallIM (Hash *l)
-{
+void luaC_hashcallIM (Hash *l) {
   TObject t;
   ttype(&t) = LUA_T_ARRAY;
   for (; l; l=(Hash *)l->head.next) {
@@ -120,8 +114,7 @@ void luaC_hashcallIM (Hash *l)
 }
 
 
-void luaC_strcallIM (TaggedString *l)
-{
+void luaC_strcallIM (TaggedString *l) {
   TObject o;
   ttype(&o) = LUA_T_USERDATA;
   for (; l; l=(TaggedString *)l->head.next)
@@ -133,8 +126,7 @@ void luaC_strcallIM (TaggedString *l)
 
 
 
-static GCnode *listcollect (GCnode *l)
-{
+static GCnode *listcollect (GCnode *l) {
   GCnode *frees = NULL;
   while (l) {
     GCnode *next = l->next;
@@ -151,8 +143,7 @@ static GCnode *listcollect (GCnode *l)
 }
 
 
-static void strmark (TaggedString *s)
-{
+static void strmark (TaggedString *s) {
   if (!s->head.marked)
     s->head.marked = 1;
 }
@@ -169,8 +160,7 @@ static void protomark (TProtoFunc *f) {
 }
 
 
-static void closuremark (Closure *f)
-{
+static void closuremark (Closure *f) {
   if (!f->head.marked) {
     int i;
     f->head.marked = 1;
@@ -180,8 +170,7 @@ static void closuremark (Closure *f)
 }
 
 
-static void hashmark (Hash *h)
-{
+static void hashmark (Hash *h) {
   if (!h->head.marked) {
     int i;
     h->head.marked = 1;
@@ -196,8 +185,7 @@ static void hashmark (Hash *h)
 }
 
 
-static void globalmark (void)
-{
+static void globalmark (void) {
   TaggedString *g;
   for (g=(TaggedString *)L->rootglobal.next; g; g=(TaggedString *)g->head.next){
     LUA_ASSERT(g->constindex >= 0, "userdata in global list");
@@ -209,8 +197,7 @@ static void globalmark (void)
 }
 
 
-static int markobject (TObject *o)
-{
+static int markobject (TObject *o) {
   switch (ttype(o)) {
     case LUA_T_USERDATA:  case LUA_T_STRING:
       strmark(tsvalue(o));
@@ -231,8 +218,7 @@ static int markobject (TObject *o)
 
 
 
-static void markall (void)
-{
+static void markall (void) {
   luaD_travstack(markobject); /* mark stack objects */
   globalmark();  /* mark global variable values and names */
   travlock(); /* mark locked objects */
@@ -240,8 +226,7 @@ static void markall (void)
 }
 
 
-long lua_collectgarbage (long limit)
-{
+long lua_collectgarbage (long limit) {
   unsigned long recovered = L->nblocks;  /* to subtract nblocks after gc */
   Hash *freetable;
   TaggedString *freestr;
@@ -267,8 +252,7 @@ long lua_collectgarbage (long limit)
 }
 
 
-void luaC_checkGC (void)
-{
+void luaC_checkGC (void) {
   if (L->nblocks >= L->GCthreshold)
     lua_collectgarbage(0);
 }

+ 3 - 3
lgc.h

@@ -1,5 +1,5 @@
 /*
-** $Id: lgc.h,v 1.3 1997/11/19 17:29:23 roberto Exp roberto $
+** $Id: lgc.h,v 1.4 1997/12/01 20:31:25 roberto Exp roberto $
 ** Garbage Collector
 ** See Copyright Notice in lua.h
 */
@@ -12,8 +12,8 @@
 
 
 void luaC_checkGC (void);
-TObject* luaC_getref (int ref);
-int luaC_ref (TObject *o, int lock);
+const TObject *luaC_getref (int ref);
+int luaC_ref (const TObject *o, int lock);
 void luaC_hashcallIM (Hash *l);
 void luaC_strcallIM (TaggedString *l);
 

+ 24 - 24
liolib.c

@@ -1,5 +1,5 @@
 /*
-** $Id: liolib.c,v 1.42 1999/07/22 19:35:50 roberto Exp roberto $
+** $Id: liolib.c,v 1.43 1999/08/10 13:05:16 roberto Exp roberto $
 ** Standard I/O (and system) library
 ** See Copyright Notice in lua.h
 */
@@ -44,8 +44,8 @@
 
 
 #ifdef POPEN
-FILE *popen();
-int pclose();
+/* FILE *popen();
+int pclose(); */
 #define CLOSEFILE(f)    ((pclose(f) == -1) ? fclose(f) : 0)
 #else
 /* no support for popen */
@@ -88,7 +88,7 @@ static int ishandle (lua_Object f) {
 }
 
 
-static FILE *getfilebyname (char *name) {
+static FILE *getfilebyname (const char *name) {
   lua_Object f = lua_rawgetglobal(name);
   if (!ishandle(f))
       luaL_verror("global variable `%.50s' is not a file handle", name);
@@ -109,7 +109,7 @@ static FILE *getnonullfile (int arg) {
 }
 
 
-static FILE *getfileparam (char *name, int *arg) {
+static FILE *getfileparam (const char *name, int *arg) {
   FILE *f = getfile(*arg);
   if (f) {
     (*arg)++;
@@ -152,13 +152,13 @@ static void io_open (void) {
 }
 
 
-static void setfile (FILE *f, char *name, int tag) {
+static void setfile (FILE *f, const char *name, int tag) {
   lua_pushusertag(f, tag);
   lua_setglobal(name);
 }
 
 
-static void setreturn (FILE *f, char *name) {
+static void setreturn (FILE *f, const char *name) {
   if (f == NULL)
     pushresult(0);
   else {
@@ -181,7 +181,7 @@ static void io_readfrom (void) {
   else if (lua_tag(f) == gettag())  /* deprecated option */
     current = lua_getuserdata(f);
   else {
-    char *s = luaL_check_string(FIRSTARG);
+    const char *s = luaL_check_string(FIRSTARG);
     current = (*s == '|') ? popen(s+1, "r") : fopen(s, "r");
   }
   setreturn(current, FINPUT);
@@ -200,7 +200,7 @@ static void io_writeto (void) {
   else if (lua_tag(f) == gettag())  /* deprecated option */
     current = lua_getuserdata(f);
   else {
-    char *s = luaL_check_string(FIRSTARG);
+    const char *s = luaL_check_string(FIRSTARG);
     current = (*s == '|') ? popen(s+1,"w") : fopen(s, "w");
   }
   setreturn(current, FOUTPUT);
@@ -228,7 +228,7 @@ static void io_appendto (void) {
 #define NEED_OTHER (EOF-1)  /* just some flag different from EOF */
 
 
-static int read_pattern (FILE *f, char *p) {
+static int read_pattern (FILE *f, const char *p) {
   int inskip = 0;  /* {skip} level */
   int c = NEED_OTHER;
   while (*p != '\0') {
@@ -243,7 +243,7 @@ static int read_pattern (FILE *f, char *p) {
         p++;
         continue;
       default: {
-        char *ep = luaI_classend(p);  /* get what is next */
+        const char *ep = luaI_classend(p);  /* get what is next */
         int m;  /* match result */
         if (c == NEED_OTHER) c = getc(f);
         m = (c==EOF) ? 0 : luaI_singlematch(c, p, ep);
@@ -317,10 +317,10 @@ static void read_file (FILE *f) {
 
 
 static void io_read (void) {
-  static char *options[] = {"*n", "*l", "*a", ".*", "*w", NULL};
+  static const char *const options[] = {"*n", "*l", "*a", ".*", "*w", NULL};
   int arg = FIRSTARG;
   FILE *f = getfileparam(FINPUT, &arg);
-  char *p = luaL_opt_string(arg++, "*l");
+  const char *p = luaL_opt_string(arg++, "*l");
   do { /* repeat for each part */
     long l;
     int success;
@@ -355,7 +355,7 @@ static void io_write (void) {
   int arg = FIRSTARG;
   FILE *f = getfileparam(FOUTPUT, &arg);
   int status = 1;
-  char *s;
+  const char *s;
   long l;
   while ((s = luaL_opt_lstr(arg++, NULL, &l)) != NULL)
     status = status && ((long)fwrite(s, 1, l, f) == l);
@@ -364,8 +364,8 @@ static void io_write (void) {
 
 
 static void io_seek (void) {
-  static int mode[] = {SEEK_SET, SEEK_CUR, SEEK_END};
-  static char *modenames[] = {"set", "cur", "end", NULL};
+  static const int mode[] = {SEEK_SET, SEEK_CUR, SEEK_END};
+  static const char *const modenames[] = {"set", "cur", "end", NULL};
   FILE *f = getnonullfile(FIRSTARG);
   int op = luaL_findstring(luaL_opt_string(FIRSTARG+1, "cur"), modenames);
   long offset = luaL_opt_long(FIRSTARG+2, 0);
@@ -428,7 +428,7 @@ static void io_clock (void) {
 
 static void io_date (void) {
   char b[256];
-  char *s = luaL_opt_string(1, "%c");
+  const char *s = luaL_opt_string(1, "%c");
   struct tm *tm;
   time_t t;
   time(&t); tm = localtime(&t);
@@ -440,9 +440,9 @@ static void io_date (void) {
 
 
 static void setloc (void) {
-  static int cat[] = {LC_ALL, LC_COLLATE, LC_CTYPE, LC_MONETARY, LC_NUMERIC,
-                      LC_TIME};
-  static char *catnames[] = {"all", "collate", "ctype", "monetary",
+  static const int cat[] = {LC_ALL, LC_COLLATE, LC_CTYPE, LC_MONETARY,
+                      LC_NUMERIC, LC_TIME};
+  static const char *const catnames[] = {"all", "collate", "ctype", "monetary",
      "numeric", "time", NULL};
   int op = luaL_findstring(luaL_opt_string(2, "all"), catnames);
   luaL_arg_check(op != -1, 2, "invalid option");
@@ -485,9 +485,9 @@ static void errorfb (void) {
   lua_Object func;
   sprintf(buff, "lua error: %.200s\n", lua_getstring(lua_getparam(1)));
   while ((func = lua_stackedfunction(level++)) != LUA_NOOBJECT) {
-    char *name;
+    const char *name;
     int currentline;
-    char *chunkname;
+    const char *chunkname;
     char buffchunk[MAXSRC];
     int linedefined;
     lua_funcinfo(func, &chunkname, &linedefined);
@@ -531,7 +531,7 @@ static void errorfb (void) {
 
 
 
-static struct luaL_reg iolib[] = {
+static const struct luaL_reg iolib[] = {
   {"_ERRORMESSAGE", errorfb},
   {"clock",     io_clock},
   {"date",     io_date},
@@ -546,7 +546,7 @@ static struct luaL_reg iolib[] = {
 };
 
 
-static struct luaL_reg iolibtag[] = {
+static const struct luaL_reg iolibtag[] = {
   {"appendto", io_appendto},
   {"closefile",   io_close},
   {"flush",     io_flush},

+ 8 - 8
llex.c

@@ -1,5 +1,5 @@
 /*
-** $Id: llex.c,v 1.36 1999/06/17 17:04:03 roberto Exp roberto $
+** $Id: llex.c,v 1.37 1999/07/22 19:29:42 roberto Exp roberto $
 ** Lexical Analyzer
 ** See Copyright Notice in lua.h
 */
@@ -28,8 +28,8 @@
 
 
 /* ORDER RESERVED */
-static char *reserved [] = {"and", "do", "else", "elseif", "end", "function",
-    "if", "local", "nil", "not", "or", "repeat", "return", "then",
+static const char *const reserved [] = {"and", "do", "else", "elseif", "end",
+    "function", "if", "local", "nil", "not", "or", "repeat", "return", "then",
     "until", "while"};
 
 
@@ -44,7 +44,7 @@ void luaX_init (void) {
 
 #define MAXSRC          80
 
-void luaX_syntaxerror (LexState *ls, char *s, char *token) {
+void luaX_syntaxerror (LexState *ls, const char *s, const char *token) {
   char buff[MAXSRC];
   luaL_chunkid(buff, zname(ls->lex_z), sizeof(buff));
   if (token[0] == '\0')
@@ -54,7 +54,7 @@ void luaX_syntaxerror (LexState *ls, char *s, char *token) {
 }
 
 
-void luaX_error (LexState *ls, char *s) {
+void luaX_error (LexState *ls, const char *s) {
   save('\0');
   luaX_syntaxerror(ls, s, luaL_buffer());
 }
@@ -117,8 +117,8 @@ static void skipspace (LexState *LS) {
 }
 
 
-static int checkcond (LexState *LS, char *buff) {
-  static char *opts[] = {"nil", "1", NULL};
+static int checkcond (LexState *LS, const char *buff) {
+  static const char *const opts[] = {"nil", "1", NULL};
   int i = luaL_findstring(buff, opts);
   if (i >= 0) return i;
   else if (isalpha((unsigned char)buff[0]) || buff[0] == '_')
@@ -160,7 +160,7 @@ static void ifskip (LexState *LS) {
 
 
 static void inclinenumber (LexState *LS) {
-  static char *pragmas [] =
+  static const char *const pragmas [] =
     {"debug", "nodebug", "endinput", "end", "ifnot", "if", "else", NULL};
   next(LS);  /* skip '\n' */
   ++LS->linenumber;

+ 3 - 3
llex.h

@@ -1,5 +1,5 @@
 /*
-** $Id: llex.h,v 1.12 1999/06/17 17:04:03 roberto Exp roberto $
+** $Id: llex.h,v 1.13 1999/07/22 19:29:42 roberto Exp roberto $
 ** Lexical Analyzer
 ** See Copyright Notice in lua.h
 */
@@ -61,8 +61,8 @@ typedef struct LexState {
 void luaX_init (void);
 void luaX_setinput (LexState *LS, ZIO *z);
 int luaX_lex (LexState *LS);
-void luaX_syntaxerror (LexState *ls, char *s, char *token);
-void luaX_error (LexState *ls, char *s);
+void luaX_syntaxerror (LexState *ls, const char *s, const char *token);
+void luaX_error (LexState *ls, const char *s);
 void luaX_token2str (int token, char *s);
 
 

+ 2 - 2
lmathlib.c

@@ -1,5 +1,5 @@
 /*
-** $Id: lmathlib.c,v 1.16 1999/02/19 17:33:35 roberto Exp roberto $
+** $Id: lmathlib.c,v 1.17 1999/07/07 17:54:08 roberto Exp roberto $
 ** Lua standard mathematical library
 ** See Copyright Notice in lua.h
 */
@@ -164,7 +164,7 @@ static void math_randomseed (void) {
 }
 
 
-static struct luaL_reg mathlib[] = {
+static const struct luaL_reg mathlib[] = {
 {"abs",   math_abs},
 {"sin",   math_sin},
 {"cos",   math_cos},

+ 14 - 16
lmem.c

@@ -1,5 +1,5 @@
 /*
-** $Id: lmem.c,v 1.16 1999/05/20 20:43:06 roberto Exp roberto $
+** $Id: lmem.c,v 1.17 1999/05/24 17:51:05 roberto Exp roberto $
 ** Interface to Memory Manager
 ** See Copyright Notice in lua.h
 */
@@ -35,7 +35,7 @@ static unsigned long power2 (unsigned long n) {
 
 
 void *luaM_growaux (void *block, unsigned long nelems, int inc, int size,
-                       char *errormsg, unsigned long limit) {
+                       const char *errormsg, unsigned long limit) {
   unsigned long newn = nelems+inc;
   if (newn >= limit) lua_error(errormsg);
   if ((newn ^ nelems) <= nelems ||  /* still the same power of 2 limit? */
@@ -86,25 +86,23 @@ unsigned long totalmem = 0;
 
 
 static void *checkblock (void *block) {
-  if (block == NULL)
-    return NULL;
-  else {
-    unsigned long *b = blocksize(block);
-    unsigned long size = *b;
-    int i;
-    for (i=0;i<MARKSIZE;i++)
-      LUA_ASSERT(*(((char *)b)+HEADER+size+i) == MARK+i, "corrupted block");
-    numblocks--;
-    totalmem -= size;
-    return b;
-  }
+  unsigned long *b = blocksize(block);
+  unsigned long size = *b;
+  int i;
+  for (i=0;i<MARKSIZE;i++)
+    LUA_ASSERT(*(((char *)b)+HEADER+size+i) == MARK+i, "corrupted block");
+  numblocks--;
+  totalmem -= size;
+  return b;
 }
 
 
 static void freeblock (void *block) {
-  if (block)
+  if (block) {
     memset(block, -1, *blocksize(block));  /* erase block */
-  free(checkblock(block));
+    block = checkblock(block);
+    free(block);
+  }
 }
 
 

+ 2 - 2
lmem.h

@@ -1,5 +1,5 @@
 /*
-** $Id: lmem.h,v 1.7 1999/02/25 15:16:26 roberto Exp roberto $
+** $Id: lmem.h,v 1.8 1999/02/26 15:48:55 roberto Exp roberto $
 ** Interface to Memory Manager
 ** See Copyright Notice in lua.h
 */
@@ -20,7 +20,7 @@
 
 void *luaM_realloc (void *oldblock, unsigned long size);
 void *luaM_growaux (void *block, unsigned long nelems, int inc, int size,
-                       char *errormsg, unsigned long limit);
+                       const char *errormsg, unsigned long limit);
 
 #define luaM_free(b)	luaM_realloc((b), 0)
 #define luaM_malloc(t)	luaM_realloc(NULL, (t))

+ 8 - 10
lobject.c

@@ -1,5 +1,5 @@
 /*
-** $Id: lobject.c,v 1.18 1999/02/26 15:48:30 roberto Exp roberto $
+** $Id: lobject.c,v 1.19 1999/04/13 19:28:49 roberto Exp roberto $
 ** Some generic functions over Lua objects
 ** See Copyright Notice in lua.h
 */
@@ -11,25 +11,24 @@
 #include "lua.h"
 
 
-char *luaO_typenames[] = { /* ORDER LUA_T */
+const char *const luaO_typenames[] = { /* ORDER LUA_T */
     "userdata", "number", "string", "table", "function", "function",
     "nil", "function", "mark", "mark", "mark", "line", NULL
 };
 
 
-TObject luaO_nilobject = {LUA_T_NIL, {NULL}};
+const TObject luaO_nilobject = {LUA_T_NIL, {NULL}};
 
 
 
 /* hash dimensions values */
-static long dimensions[] =
+static const long dimensions[] =
  {5L, 11L, 23L, 47L, 97L, 197L, 397L, 797L, 1597L, 3203L, 6421L,
   12853L, 25717L, 51437L, 102811L, 205619L, 411233L, 822433L,
   1644817L, 3289613L, 6579211L, 13158023L, MAX_INT};
 
 
-int luaO_redimension (int oldsize)
-{
+int luaO_redimension (int oldsize) {
   int i;
   for (i=0; dimensions[i]<MAX_INT; i++) {
     if (dimensions[i] > oldsize)
@@ -40,7 +39,7 @@ int luaO_redimension (int oldsize)
 }
 
 
-int luaO_equalval (TObject *t1, TObject *t2) {
+int luaO_equalval (const TObject *t1, const TObject *t2) {
   switch (ttype(t1)) {
     case LUA_T_NIL: return 1;
     case LUA_T_NUMBER: return nvalue(t1) == nvalue(t2);
@@ -56,8 +55,7 @@ int luaO_equalval (TObject *t1, TObject *t2) {
 }
 
 
-void luaO_insertlist (GCnode *root, GCnode *node)
-{
+void luaO_insertlist (GCnode *root, GCnode *node) {
   node->next = root->next;
   root->next = node;
   node->marked = 0;
@@ -90,7 +88,7 @@ static double expten (unsigned int e) {
 }
 
 
-double luaO_str2d (char *s) {  /* LUA_NUMBER */
+double luaO_str2d (const char *s) {  /* LUA_NUMBER */
   double a = 0.0;
   int point = 0;
   while (isdigit((unsigned char)*s)) {

+ 5 - 5
lobject.h

@@ -1,5 +1,5 @@
 /*
-** $Id: lobject.h,v 1.27 1999/03/04 21:17:26 roberto Exp roberto $
+** $Id: lobject.h,v 1.28 1999/03/16 16:43:27 roberto Exp roberto $
 ** Type definitions for Lua objects
 ** See Copyright Notice in lua.h
 */
@@ -178,19 +178,19 @@ typedef struct Hash {
 } Hash;
 
 
-extern char *luaO_typenames[];
+extern const char *const luaO_typenames[];
 
 #define luaO_typename(o)        luaO_typenames[-ttype(o)]
 
 
-extern TObject luaO_nilobject;
+extern const TObject luaO_nilobject;
 
 #define luaO_equalObj(t1,t2)	((ttype(t1) != ttype(t2)) ? 0 \
                                       : luaO_equalval(t1,t2))
-int luaO_equalval (TObject *t1, TObject *t2);
+int luaO_equalval (const TObject *t1, const TObject *t2);
 int luaO_redimension (int oldsize);
 void luaO_insertlist (GCnode *root, GCnode *node);
-double luaO_str2d (char *s);
+double luaO_str2d (const char *s);
 
 #ifdef OLD_ANSI
 void luaO_memup (void *dest, void *src, int size);

+ 13 - 12
lparser.c

@@ -1,5 +1,5 @@
 /*
-** $Id: lparser.c,v 1.37 1999/06/17 17:04:03 roberto Exp roberto $
+** $Id: lparser.c,v 1.38 1999/07/22 19:29:42 roberto Exp roberto $
 ** LL(1) Parser and code generator for Lua
 ** See Copyright Notice in lua.h
 */
@@ -142,7 +142,7 @@ static void var_or_func_tail (LexState *ls, vardesc *v);
 
 
 
-static void checklimit (LexState *ls, int val, int limit, char *msg) {
+static void checklimit (LexState *ls, int val, int limit, const char *msg) {
   if (val > limit) {
     char buff[100];
     sprintf(buff, "too many %.50s (limit=%d)", msg, limit);
@@ -498,7 +498,7 @@ static void lua_pushvar (LexState *ls, vardesc *var) {
 }
 
 
-static void storevar (LexState *ls, vardesc *var) {
+static void storevar (LexState *ls, const vardesc *var) {
   switch (var->k) {
     case VLOCAL:
       code_oparg(ls, SETLOCAL, var->info, -1);
@@ -597,12 +597,13 @@ static void close_func (LexState *ls) {
 
 
 
-static int expfollow [] = {ELSE, ELSEIF, THEN, IF, WHILE, REPEAT, DO, NAME,
-   LOCAL, FUNCTION, END, UNTIL, RETURN, ')', ']', '}', ';', EOS, ',',  0};
+static const int expfollow [] = {ELSE, ELSEIF, THEN, IF, WHILE, REPEAT,
+   DO, NAME, LOCAL, FUNCTION, END, UNTIL, RETURN, ')', ']', '}', ';',
+   EOS, ',',  0};
 
 
-static int is_in (int tok, int *toks) {
-  int *t;
+static int is_in (int tok, const int *toks) {
+  const int *t;
   for (t=toks; *t; t++)
     if (*t == tok) return t-toks;
   return -1;
@@ -923,13 +924,13 @@ static void ret (LexState *ls) {
 */
 #define POW	13
 
-static int binop [] = {EQ, NE, '>', '<', LE, GE, CONC,
-                        '+', '-', '*', '/', '^', 0};
+static const int binop [] = {EQ, NE, '>', '<', LE, GE, CONC,
+                             '+', '-', '*', '/', '^', 0};
 
-static int priority [POW+1] =  {5, 5, 1, 1, 1, 1, 1, 1, 2, 3, 3, 4, 4, 6};
+static const int priority [POW+1] =  {5, 5, 1, 1, 1, 1, 1, 1, 2, 3, 3, 4, 4, 6};
 
-static OpCode opcodes [POW+1] = {NOTOP, MINUSOP, EQOP, NEQOP, GTOP, LTOP,
-  LEOP, GEOP, CONCOP, ADDOP, SUBOP, MULTOP, DIVOP, POWOP};
+static const OpCode opcodes [POW+1] = {NOTOP, MINUSOP, EQOP, NEQOP, GTOP,
+  LTOP, LEOP, GEOP, CONCOP, ADDOP, SUBOP, MULTOP, DIVOP, POWOP};
 
 #define MAXOPS	20  /* op's stack size (arbitrary limit) */
 

+ 3 - 3
lparser.h

@@ -1,5 +1,5 @@
 /*
-** $Id: lparser.h,v 1.2 1997/12/22 20:57:18 roberto Exp roberto $
+** $Id: lparser.h,v 1.3 1999/02/25 19:13:56 roberto Exp roberto $
 ** LL(1) Parser and code generator for Lua
 ** See Copyright Notice in lua.h
 */
@@ -13,8 +13,8 @@
 
 void luaY_codedebugline (int line);
 TProtoFunc *luaY_parser (ZIO *z);
-void luaY_error (char *s);
-void luaY_syntaxerror (char *s, char *token);
+void luaY_error (const char *s);
+void luaY_syntaxerror (const char *s, const char *token);
 
 
 #endif

+ 3 - 5
lstate.c

@@ -1,5 +1,5 @@
 /*
-** $Id: lstate.c,v 1.11 1999/05/11 14:19:32 roberto Exp roberto $
+** $Id: lstate.c,v 1.12 1999/05/11 20:08:20 roberto Exp roberto $
 ** Global State
 ** See Copyright Notice in lua.h
 */
@@ -20,8 +20,7 @@
 lua_State *lua_state = NULL;
 
 
-void lua_open (void)
-{
+void lua_open (void) {
   if (lua_state) return;
   lua_state = luaM_new(lua_State);
   L->Cstack.base = 0;
@@ -58,8 +57,7 @@ void lua_open (void)
 }
 
 
-void lua_close (void)
-{
+void lua_close (void) {
   TaggedString *alludata = luaS_collectudata();
   L->GCthreshold = MAX_INT;  /* to avoid GC during GC */
   luaC_hashcallIM((Hash *)L->roottable.next);  /* GC t.methods for tables */

+ 10 - 10
lstring.c

@@ -1,5 +1,5 @@
 /*
-** $Id: lstring.c,v 1.18 1999/02/08 16:28:48 roberto Exp roberto $
+** $Id: lstring.c,v 1.19 1999/02/26 15:49:53 roberto Exp roberto $
 ** String table (keeps all strings handled by Lua)
 ** See Copyright Notice in lua.h
 */
@@ -38,7 +38,7 @@ void luaS_init (void) {
 }
 
 
-static unsigned long hash_s (char *s, long l) {
+static unsigned long hash_s (const char *s, long l) {
   unsigned long h = 0;  /* seed */
   while (l--)
       h = h ^ ((h<<5)+(h>>2)+(unsigned char)*(s++));
@@ -83,7 +83,7 @@ static void grow (stringtable *tb) {
 }
 
 
-static TaggedString *newone_s (char *str, long l, unsigned long h) {
+static TaggedString *newone_s (const char *str, long l, unsigned long h) {
   TaggedString *ts = (TaggedString *)luaM_malloc(sizeof(TaggedString)+l);
   memcpy(ts->str, str, l);
   ts->str[l] = 0;  /* ending 0 */
@@ -97,7 +97,7 @@ static TaggedString *newone_s (char *str, long l, unsigned long h) {
   return ts;
 }
 
-static TaggedString *newone_u (char *buff, int tag, unsigned long h) {
+static TaggedString *newone_u (void *buff, int tag, unsigned long h) {
   TaggedString *ts = luaM_new(TaggedString);
   ts->u.d.v = buff;
   ts->u.d.tag = (tag == LUA_ANYTAG) ? 0 : tag;
@@ -109,7 +109,7 @@ static TaggedString *newone_u (char *buff, int tag, unsigned long h) {
   return ts;
 }
 
-static TaggedString *insert_s (char *str, long l, stringtable *tb) {
+static TaggedString *insert_s (const char *str, long l, stringtable *tb) {
   TaggedString *ts;
   unsigned long h = hash_s(str, l);
   int size = tb->size;
@@ -172,16 +172,16 @@ TaggedString *luaS_createudata (void *udata, int tag) {
   return insert_u(udata, tag, &L->string_root[t]);
 }
 
-TaggedString *luaS_newlstr (char *str, long l) {
+TaggedString *luaS_newlstr (const char *str, long l) {
   int t = (l==0) ? 0 : ((int)((unsigned char)str[0]*l))%NUM_HASHSTR;
   return insert_s(str, l, &L->string_root[t]);
 }
 
-TaggedString *luaS_new (char *str) {
+TaggedString *luaS_new (const char *str) {
   return luaS_newlstr(str, strlen(str));
 }
 
-TaggedString *luaS_newfixedstring (char *str) {
+TaggedString *luaS_newfixedstring (const char *str) {
   TaggedString *ts = luaS_new(str);
   if (ts->head.marked == 0)
     ts->head.marked = 2;  /* avoid GC */
@@ -282,7 +282,7 @@ void luaS_rawsetglobal (TaggedString *ts, TObject *newval) {
 }
 
 
-char *luaS_travsymbol (int (*fn)(TObject *)) {
+const char *luaS_travsymbol (int (*fn)(TObject *)) {
   TaggedString *g;
   for (g=(TaggedString *)L->rootglobal.next; g; g=(TaggedString *)g->head.next)
     if (fn(&g->u.s.globalval))
@@ -291,7 +291,7 @@ char *luaS_travsymbol (int (*fn)(TObject *)) {
 }
 
 
-int luaS_globaldefined (char *name) {
+int luaS_globaldefined (const char *name) {
   TaggedString *ts = luaS_new(name);
   return ts->u.s.globalval.ttype != LUA_T_NIL;
 }

+ 6 - 6
lstring.h

@@ -1,5 +1,5 @@
 /*
-** $Id: lstring.h,v 1.6 1997/12/01 20:31:25 roberto Exp roberto $
+** $Id: lstring.h,v 1.7 1998/03/06 16:54:42 roberto Exp roberto $
 ** String table (keep all strings handled by Lua)
 ** See Copyright Notice in lua.h
 */
@@ -15,12 +15,12 @@ void luaS_init (void);
 TaggedString *luaS_createudata (void *udata, int tag);
 TaggedString *luaS_collector (void);
 void luaS_free (TaggedString *l);
-TaggedString *luaS_newlstr (char *str, long l);
-TaggedString *luaS_new (char *str);
-TaggedString *luaS_newfixedstring (char *str);
+TaggedString *luaS_newlstr (const char *str, long l);
+TaggedString *luaS_new (const char *str);
+TaggedString *luaS_newfixedstring (const char *str);
 void luaS_rawsetglobal (TaggedString *ts, TObject *newval);
-char *luaS_travsymbol (int (*fn)(TObject *));
-int luaS_globaldefined (char *name);
+const char *luaS_travsymbol (int (*fn)(TObject *));
+int luaS_globaldefined (const char *name);
 TaggedString *luaS_collectudata (void);
 void luaS_freeall (void);
 

+ 47 - 44
lstrlib.c

@@ -1,5 +1,5 @@
 /*
-** $Id: lstrlib.c,v 1.32 1999/06/17 17:04:03 roberto Exp roberto $
+** $Id: lstrlib.c,v 1.33 1999/08/10 12:55:56 roberto Exp roberto $
 ** Standard library for strings and pattern-matching
 ** See Copyright Notice in lua.h
 */
@@ -16,16 +16,14 @@
 
 
 
-static void addnchar (char *s, int n)
-{
+static void addnchar (const char *s, int n) {
   char *b = luaL_openspace(n);
   memcpy(b, s, n);
   luaL_addsize(n);
 }
 
 
-static void str_len (void)
-{
+static void str_len (void) {
   long l;
   luaL_check_lstr(1, &l);
   lua_pushnumber(l);
@@ -45,7 +43,7 @@ static long posrelat (long pos, long len) {
 
 static void str_sub (void) {
   long l;
-  char *s = luaL_check_lstr(1, &l);
+  const char *s = luaL_check_lstr(1, &l);
   long start = posrelat(luaL_check_long(2), l);
   long end = posrelat(luaL_opt_long(3, -1), l);
   if (start < 1) start = 1;
@@ -59,7 +57,7 @@ static void str_sub (void) {
 static void str_lower (void) {
   long l;
   int i;
-  char *s = luaL_check_lstr(1, &l);
+  const char *s = luaL_check_lstr(1, &l);
   luaL_resetbuffer();
   for (i=0; i<l; i++)
     luaL_addchar(tolower((unsigned char)(s[i])));
@@ -70,17 +68,16 @@ static void str_lower (void) {
 static void str_upper (void) {
   long l;
   int i;
-  char *s = luaL_check_lstr(1, &l);
+  const char *s = luaL_check_lstr(1, &l);
   luaL_resetbuffer();
   for (i=0; i<l; i++)
     luaL_addchar(toupper((unsigned char)(s[i])));
   closeandpush();
 }
 
-static void str_rep (void)
-{
+static void str_rep (void) {
   long l;
-  char *s = luaL_check_lstr(1, &l);
+  const char *s = luaL_check_lstr(1, &l);
   int n = luaL_check_int(2);
   luaL_resetbuffer();
   while (n-- > 0)
@@ -91,7 +88,7 @@ static void str_rep (void)
 
 static void str_byte (void) {
   long l;
-  char *s = luaL_check_lstr(1, &l);
+  const char *s = luaL_check_lstr(1, &l);
   long pos = posrelat(luaL_opt_long(2, 1), l);
   luaL_arg_check(0<pos && pos<=l, 2,  "out of range");
   lua_pushnumber((unsigned char)s[pos-1]);
@@ -123,10 +120,10 @@ static void str_char (void) {
 
 
 struct Capture {
-  char *src_end;  /* end ('\0') of source string */
+  const char *src_end;  /* end ('\0') of source string */
   int level;  /* total number of captures (finished or unfinished) */
   struct {
-    char *init;
+    const char *init;
     int len;  /* -1 signals unfinished capture */
   } capture[MAX_CAPT];
 };
@@ -163,7 +160,7 @@ static int capture_to_close (struct Capture *cap) {
 }
 
 
-char *luaI_classend (char *p) {
+const char *luaI_classend (const char *p) {
   switch (*p++) {
     case ESC:
       if (*p == '\0') lua_error("incorrect pattern (ends with `%')");
@@ -201,7 +198,7 @@ static int matchclass (int c, int cl) {
 
 
 
-static int matchbracketclass (int c, char *p, char *endclass) {
+static int matchbracketclass (int c, const char *p, const char *endclass) {
   int sig = 1;
   if (*(p+1) == '^') {
     sig = 0;
@@ -225,7 +222,7 @@ static int matchbracketclass (int c, char *p, char *endclass) {
 
 
 
-int luaI_singlematch (int c, char *p, char *ep) {
+int luaI_singlematch (int c, const char *p, const char *ep) {
   switch (*p) {
     case '.':  /* matches any char */
       return 1;
@@ -239,10 +236,11 @@ int luaI_singlematch (int c, char *p, char *ep) {
 }
 
 
-static char *match (char *s, char *p, struct Capture *cap);
+static const char *match (const char *s, const char *p, struct Capture *cap);
 
 
-static char *matchbalance (char *s, char *p, struct Capture *cap) {
+static const char *matchbalance (const char *s, const char *p,
+                                 struct Capture *cap) {
   if (*p == 0 || *(p+1) == 0)
     lua_error("unbalanced pattern");
   if (*s != *p) return NULL;
@@ -261,13 +259,14 @@ static char *matchbalance (char *s, char *p, struct Capture *cap) {
 }
 
 
-static char *max_expand (char *s, char *p, char *ep, struct Capture *cap) {
+static const char *max_expand (const char *s, const char *p, const char *ep,
+                         struct Capture *cap) {
   int i = 0;  /* counts maximum expand for item */
   while ((s+i)<cap->src_end && luaI_singlematch((unsigned char)*(s+i), p, ep))
     i++;
   /* keeps trying to match mith the maximum repetitions */
   while (i>=0) {
-    char *res = match((s+i), ep+1, cap);
+    const char *res = match((s+i), ep+1, cap);
     if (res) return res;
     i--;  /* else didn't match; reduce 1 repetition to try again */
   }
@@ -275,9 +274,10 @@ static char *max_expand (char *s, char *p, char *ep, struct Capture *cap) {
 }
 
 
-static char *min_expand (char *s, char *p, char *ep, struct Capture *cap) {
+static const char *min_expand (const char *s, const char *p, const char *ep,
+                         struct Capture *cap) {
   for (;;) {
-    char *res = match(s, ep+1, cap);
+    const char *res = match(s, ep+1, cap);
     if (res != NULL)
       return res;
     else if (s<cap->src_end && luaI_singlematch((unsigned char)*s, p, ep))
@@ -287,8 +287,9 @@ static char *min_expand (char *s, char *p, char *ep, struct Capture *cap) {
 }
 
 
-static char *start_capt (char *s, char *p, struct Capture *cap) {
-  char *res;
+static const char *start_capt (const char *s, const char *p,
+                               struct Capture *cap) {
+  const char *res;
   int level = cap->level;
   if (level >= MAX_CAPT) lua_error("too many captures");
   cap->capture[level].init = s;
@@ -300,9 +301,10 @@ static char *start_capt (char *s, char *p, struct Capture *cap) {
 }
 
 
-static char *end_capt (char *s, char *p, struct Capture *cap) {
+static const char *end_capt (const char *s, const char *p,
+                             struct Capture *cap) {
   int l = capture_to_close(cap);
-  char *res;
+  const char *res;
   cap->capture[l].len = s - cap->capture[l].init;  /* close capture */
   if ((res = match(s, p+1, cap)) == NULL)  /* match failed? */
     cap->capture[l].len = -1;  /* undo capture */
@@ -310,7 +312,8 @@ static char *end_capt (char *s, char *p, struct Capture *cap) {
 }
 
 
-static char *match_capture (char *s, int level, struct Capture *cap) {
+static const char *match_capture (const char *s, int level,
+                                  struct Capture *cap) {
   int l = check_cap(level, cap);
   int len = cap->capture[l].len;
   if (cap->src_end-s >= len &&
@@ -320,7 +323,7 @@ static char *match_capture (char *s, int level, struct Capture *cap) {
 }
 
 
-static char *match (char *s, char *p, struct Capture *cap) {
+static const char *match (const char *s, const char *p, struct Capture *cap) {
   init: /* using goto's to optimize tail recursion */
   switch (*p) {
     case '(':  /* start capture */
@@ -346,11 +349,11 @@ static char *match (char *s, char *p, struct Capture *cap) {
         return (s == cap->src_end) ? s : NULL;  /* check end of string */
       else goto dflt;
     default: dflt: {  /* it is a pattern item */
-      char *ep = luaI_classend(p);  /* points to what is next */
+      const char *ep = luaI_classend(p);  /* points to what is next */
       int m = s<cap->src_end && luaI_singlematch((unsigned char)*s, p, ep);
       switch (*ep) {
         case '?': {  /* optional */
-          char *res;
+          const char *res;
           if (m && ((res=match(s+1, ep+1, cap)) != NULL))
             return res;
           p=ep+1; goto init;  /* else return match(s, ep+1, cap); */
@@ -372,8 +375,8 @@ static char *match (char *s, char *p, struct Capture *cap) {
 
 static void str_find (void) {
   long l;
-  char *s = luaL_check_lstr(1, &l);
-  char *p = luaL_check_string(2);
+  const char *s = luaL_check_lstr(1, &l);
+  const char *p = luaL_check_string(2);
   long init = posrelat(luaL_opt_long(3, 1), l) - 1;
   struct Capture cap;
   luaL_arg_check(0 <= init && init <= l, 3, "out of range");
@@ -388,10 +391,10 @@ static void str_find (void) {
   }
   else {
     int anchor = (*p == '^') ? (p++, 1) : 0;
-    char *s1=s+init;
+    const char *s1=s+init;
     cap.src_end = s+l;
     do {
-      char *res;
+      const char *res;
       cap.level = 0;
       if ((res=match(s1, p, &cap)) != NULL) {
         lua_pushnumber(s1-s+1);  /* start */
@@ -407,7 +410,7 @@ static void str_find (void) {
 
 static void add_s (lua_Object newp, struct Capture *cap) {
   if (lua_isstring(newp)) {
-    char *news = lua_getstring(newp);
+    const char *news = lua_getstring(newp);
     int l = lua_strlen(newp);
     int i;
     for (i=0; i<l; i++) {
@@ -449,8 +452,8 @@ static void add_s (lua_Object newp, struct Capture *cap) {
 
 static void str_gsub (void) {
   long srcl;
-  char *src = luaL_check_lstr(1, &srcl);
-  char *p = luaL_check_string(2);
+  const char *src = luaL_check_lstr(1, &srcl);
+  const char *p = luaL_check_string(2);
   lua_Object newp = lua_getparam(3);
   int max_s = luaL_opt_int(4, srcl+1);
   int anchor = (*p == '^') ? (p++, 1) : 0;
@@ -461,7 +464,7 @@ static void str_gsub (void) {
   luaL_resetbuffer();
   cap.src_end = src+srcl;
   while (n < max_s) {
-    char *e;
+    const char *e;
     cap.level = 0;
     e = match(src, p, &cap);
     if (e) {
@@ -485,7 +488,7 @@ static void str_gsub (void) {
 
 static void luaI_addquoted (int arg) {
   long l;
-  char *s = luaL_check_lstr(arg, &l);
+  const char *s = luaL_check_lstr(arg, &l);
   luaL_addchar('"');
   while (l--) {
     switch (*s) {
@@ -506,7 +509,7 @@ static void luaI_addquoted (int arg) {
 
 static void str_format (void) {
   int arg = 1;
-  char *strfrmt = luaL_check_string(arg);
+  const char *strfrmt = luaL_check_string(arg);
   luaL_resetbuffer();
   while (*strfrmt) {
     if (*strfrmt != '%')
@@ -517,7 +520,7 @@ static void str_format (void) {
       struct Capture cap;
       char form[MAX_FORMAT];  /* to store the format ('%...') */
       char *buff;  /* to store the formatted item */
-      char *initf = strfrmt;
+      const char *initf = strfrmt;
       form[0] = '%';
       if (isdigit((unsigned char)*initf) && *(initf+1) == '$') {
         arg = *initf - '0';
@@ -548,7 +551,7 @@ static void str_format (void) {
           continue;  /* skip the "addsize" at the end */
         case 's': {
           long l;
-          char *s = luaL_check_lstr(arg, &l);
+          const char *s = luaL_check_lstr(arg, &l);
           if (cap.capture[1].len == 0 && l >= 100) {
             /* no precision and string is too big to be formatted;
                keep original string */
@@ -570,7 +573,7 @@ static void str_format (void) {
 }
 
 
-static struct luaL_reg strlib[] = {
+static const struct luaL_reg strlib[] = {
 {"strlen", str_len},
 {"strsub", str_sub},
 {"strlower", str_lower},

+ 7 - 7
ltable.c

@@ -1,5 +1,5 @@
 /*
-** $Id: ltable.c,v 1.21 1999/02/23 14:57:28 roberto Exp roberto $
+** $Id: ltable.c,v 1.22 1999/05/21 19:41:49 roberto Exp roberto $
 ** Lua tables (hash)
 ** See Copyright Notice in lua.h
 */
@@ -24,7 +24,7 @@
 
 
 
-static long int hashindex (TObject *ref) {
+static long int hashindex (const TObject *ref) {
   long int h;
   switch (ttype(ref)) {
     case LUA_T_NUMBER:
@@ -53,7 +53,7 @@ static long int hashindex (TObject *ref) {
 }
 
 
-Node *luaH_present (Hash *t, TObject *key) {
+Node *luaH_present (const Hash *t, const TObject *key) {
   int tsize = nhash(t);
   long int h = hashindex(key);
   int h1 = h%tsize;
@@ -135,7 +135,7 @@ static void rehash (Hash *t) {
 }
 
 
-void luaH_set (Hash *t, TObject *ref, TObject *val) {
+void luaH_set (Hash *t, const TObject *ref, const TObject *val) {
   Node *n = luaH_present(t, ref);
   if (ttype(ref(n)) != LUA_T_NIL)
     *val(n) = *val;
@@ -153,14 +153,14 @@ void luaH_set (Hash *t, TObject *ref, TObject *val) {
 }
 
 
-int luaH_pos (Hash *t, TObject *r) {
+int luaH_pos (const Hash *t, const TObject *r) {
   Node *n = luaH_present(t, r);
   luaL_arg_check(ttype(val(n)) != LUA_T_NIL, 2, "key not found");
   return n-(t->node);
 }
 
 
-void luaH_setint (Hash *t, int ref, TObject *val) {
+void luaH_setint (Hash *t, int ref, const TObject *val) {
   TObject index;
   ttype(&index) = LUA_T_NUMBER;
   nvalue(&index) = ref;
@@ -168,7 +168,7 @@ void luaH_setint (Hash *t, int ref, TObject *val) {
 }
 
 
-TObject *luaH_getint (Hash *t, int ref) {
+TObject *luaH_getint (const Hash *t, int ref) {
   TObject index;
   ttype(&index) = LUA_T_NUMBER;
   nvalue(&index) = ref;

+ 6 - 6
ltable.h

@@ -1,5 +1,5 @@
 /*
-** $Id: ltable.h,v 1.10 1999/01/25 17:40:10 roberto Exp roberto $
+** $Id: ltable.h,v 1.11 1999/02/23 14:57:28 roberto Exp roberto $
 ** Lua tables (hash)
 ** See Copyright Notice in lua.h
 */
@@ -20,11 +20,11 @@
 
 Hash *luaH_new (int nhash);
 void luaH_free (Hash *frees);
-Node *luaH_present (Hash *t, TObject *key);
-void luaH_set (Hash *t, TObject *ref, TObject *val);
-int luaH_pos (Hash *t, TObject *r);
-void luaH_setint (Hash *t, int ref, TObject *val);
-TObject *luaH_getint (Hash *t, int ref);
+Node *luaH_present (const Hash *t, const TObject *key);
+void luaH_set (Hash *t, const TObject *ref, const TObject *val);
+int luaH_pos (const Hash *t, const TObject *r);
+void luaH_setint (Hash *t, int ref, const TObject *val);
+TObject *luaH_getint (const Hash *t, int ref);
 
 
 #endif

+ 12 - 10
ltm.c

@@ -1,5 +1,5 @@
 /*
-** $Id: ltm.c,v 1.24 1999/02/26 15:48:55 roberto Exp roberto $
+** $Id: ltm.c,v 1.25 1999/05/21 19:41:49 roberto Exp roberto $
 ** Tag methods
 ** See Copyright Notice in lua.h
 */
@@ -15,14 +15,14 @@
 #include "ltm.h"
 
 
-char *luaT_eventname[] = {  /* ORDER IM */
+const char *const luaT_eventname[] = {  /* ORDER IM */
   "gettable", "settable", "index", "getglobal", "setglobal", "add",
   "sub", "mul", "div", "pow", "unm", "lt", "le", "gt", "ge",
   "concat", "gc", "function", NULL
 };
 
 
-static int luaI_checkevent (char *name, char *list[]) {
+static int luaI_checkevent (const char *name, const char *const list[]) {
   int e = luaL_findstring(name, list);
   if (e < 0)
     luaL_verror("`%.50s' is not a valid event name", name);
@@ -34,7 +34,8 @@ static int luaI_checkevent (char *name, char *list[]) {
 /* events in LUA_T_NIL are all allowed, since this is used as a
 *  'placeholder' for "default" fallbacks
 */
-static char luaT_validevents[NUM_TAGS][IM_N] = { /* ORDER LUA_T, ORDER IM */
+/* ORDER LUA_T, ORDER IM */
+static const char luaT_validevents[NUM_TAGS][IM_N] = {
 {1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1},  /* LUA_T_USERDATA */
 {1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1},  /* LUA_T_NUMBER */
 {1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1},  /* LUA_T_STRING */
@@ -96,7 +97,7 @@ int lua_copytagmethods (int tagto, int tagfrom) {
 }
 
 
-int luaT_effectivetag (TObject *o) {
+int luaT_effectivetag (const TObject *o) {
   int t;
   switch (t = ttype(o)) {
     case LUA_T_ARRAY:
@@ -118,7 +119,7 @@ int luaT_effectivetag (TObject *o) {
 }
 
 
-TObject *luaT_gettagmethod (int t, char *event) {
+const TObject *luaT_gettagmethod (int t, const char *event) {
   int e = luaI_checkevent(event, luaT_eventname);
   checktag(t);
   if (luaT_validevent(t, e))
@@ -128,7 +129,7 @@ TObject *luaT_gettagmethod (int t, char *event) {
 }
 
 
-void luaT_settagmethod (int t, char *event, TObject *func) {
+void luaT_settagmethod (int t, const char *event, TObject *func) {
   TObject temp;
   int e = luaI_checkevent(event, luaT_eventname);
   checktag(t);
@@ -143,7 +144,7 @@ void luaT_settagmethod (int t, char *event, TObject *func) {
 }
 
 
-char *luaT_travtagmethods (int (*fn)(TObject *)) {  /* ORDER IM */
+const char *luaT_travtagmethods (int (*fn)(TObject *)) {  /* ORDER IM */
   int e;
   for (e=IM_GETTABLE; e<=IM_FUNCTION; e++) {
     int t;
@@ -191,10 +192,11 @@ static void fillvalids (IMS e, TObject *func) {
 
 
 void luaT_setfallback (void) {
-  static char *oldnames [] = {"error", "getglobal", "arith", "order", NULL};
+  static const char *const oldnames [] = {"error", "getglobal", "arith",
+                                          "order", NULL};
   TObject oldfunc;
   lua_CFunction replace;
-  char *name = luaL_check_string(1);
+  const char *name = luaL_check_string(1);
   lua_Object func = lua_getparam(2);
   luaL_arg_check(lua_isfunction(func), 2, "function expected");
   switch (luaL_findstring(name, oldnames)) {

+ 6 - 6
ltm.h

@@ -1,5 +1,5 @@
 /*
-** $Id: ltm.h,v 1.4 1997/11/26 18:53:45 roberto Exp roberto $
+** $Id: ltm.h,v 1.5 1999/01/15 13:11:57 roberto Exp roberto $
 ** Tag methods
 ** See Copyright Notice in lua.h
 */
@@ -47,15 +47,15 @@ struct IM {
 #define luaT_getim(tag,event) (&L->IMtable[-(tag)].int_method[event])
 #define luaT_getimbyObj(o,e)  (luaT_getim(luaT_effectivetag(o),(e)))
 
-extern char *luaT_eventname[];
+extern const char *const luaT_eventname[];
 
 
 void luaT_init (void);
 void luaT_realtag (int tag);
-int luaT_effectivetag (TObject *o);
-void luaT_settagmethod (int t, char *event, TObject *func);
-TObject *luaT_gettagmethod (int t, char *event);
-char *luaT_travtagmethods (int (*fn)(TObject *));
+int luaT_effectivetag (const TObject *o);
+void luaT_settagmethod (int t, const char *event, TObject *func);
+const TObject *luaT_gettagmethod (int t, const char *event);
+const char *luaT_travtagmethods (int (*fn)(TObject *));
 
 void luaT_setfallback (void);  /* only if LUA_COMPAT2_5 */
 

+ 2 - 2
lua.c

@@ -1,5 +1,5 @@
 /*
-** $Id: lua.c,v 1.20 1999/06/24 19:42:02 roberto Exp roberto $
+** $Id: lua.c,v 1.21 1999/07/02 18:22:38 roberto Exp roberto $
 ** Lua stand-alone interpreter
 ** See Copyright Notice in lua.h
 */
@@ -52,7 +52,7 @@ static void laction (int i) {
 }
 
 
-static int ldo (int (*f)(char *), char *name) {
+static int ldo (int (*f)(const char *), const char *name) {
   int res;
   handler h = lreset();
   res = f(name);  /* dostring | dofile */

+ 19 - 16
lua.h

@@ -1,5 +1,5 @@
 /*
-** $Id: lua.h,v 1.32 1999/05/11 20:29:19 roberto Exp roberto $
+** $Id: lua.h,v 1.33 1999/08/11 17:00:59 roberto Exp roberto $
 ** Lua - An Extensible Extension Language
 ** TeCGraf: Grupo de Tecnologia em Computacao Grafica, PUC-Rio, Brazil
 ** e-mail: [email protected]
@@ -33,18 +33,21 @@ void	       lua_open			(void);
 void           lua_close		(void);
 lua_State      *lua_setstate		(lua_State *st);
 
-lua_Object     lua_settagmethod	(int tag, char *event); /* In: new method */
-lua_Object     lua_gettagmethod	(int tag, char *event);
+lua_Object     lua_settagmethod	(int tag, const char *event);
+                                                       /* In: new method */
+lua_Object     lua_gettagmethod	(int tag, const char *event);
 
 int            lua_newtag		(void);
 int            lua_copytagmethods	(int tagto, int tagfrom);
 void           lua_settag		(int tag); /* In: object */
 
-void           lua_error		(char *s);
-int            lua_dofile 		(char *filename); /* Out: returns */
-int            lua_dostring 		(char *string); /* Out: returns */
-int            lua_dobuffer		(char *buff, int size, char *name);
-					  /* Out: returns */
+void           lua_error		(const char *s);
+int            lua_dofile 		(const char *filename);
+                                                        /* Out: returns */
+int            lua_dostring 		(const char *string);
+                                                        /* Out: returns */
+int            lua_dobuffer		(const char *buff, int size,
+                                         const char *name); /* Out: returns */
 int            lua_callfunction		(lua_Object f);
 					  /* In: parameters; Out: returns */
 
@@ -64,7 +67,7 @@ int            lua_isstring             (lua_Object object);
 int            lua_isfunction           (lua_Object object);
 
 double         lua_getnumber 		(lua_Object object);
-char          *lua_getstring 		(lua_Object object);
+const char    *lua_getstring 		(lua_Object object);
 long           lua_strlen 		(lua_Object object);
 lua_CFunction  lua_getcfunction 	(lua_Object object);
 void	      *lua_getuserdata		(lua_Object object);
@@ -72,18 +75,18 @@ void	      *lua_getuserdata		(lua_Object object);
 
 void 	       lua_pushnil 		(void);
 void           lua_pushnumber 		(double n);
-void           lua_pushlstring		(char *s, long len);
-void           lua_pushstring 		(char *s);
+void           lua_pushlstring		(const char *s, long len);
+void           lua_pushstring 		(const char *s);
 void           lua_pushcclosure		(lua_CFunction fn, int n);
 void           lua_pushusertag          (void *u, int tag);
 void           lua_pushobject       	(lua_Object object);
 
 lua_Object     lua_pop			(void);
 
-lua_Object     lua_getglobal 		(char *name);
-lua_Object     lua_rawgetglobal		(char *name);
-void           lua_setglobal		(char *name); /* In: value */
-void           lua_rawsetglobal		(char *name); /* In: value */
+lua_Object     lua_getglobal 		(const char *name);
+lua_Object     lua_rawgetglobal		(const char *name);
+void           lua_setglobal		(const char *name); /* In: value */
+void           lua_rawsetglobal		(const char *name); /* In: value */
 
 void           lua_settable	(void); /* In: table, index, value */
 void           lua_rawsettable	(void); /* In: table, index, value */
@@ -92,7 +95,7 @@ lua_Object     lua_rawgettable		(void); /* In: table, index */
 
 int            lua_tag			(lua_Object object);
 
-char          *lua_nextvar		(char *varname);  /* Out: value */
+const char    *lua_nextvar		(const char *varname);  /* Out: value */
 int            lua_next			(lua_Object o, int i);
 						/* Out: ref, value */ 
 

+ 6 - 5
luadebug.h

@@ -1,5 +1,5 @@
 /*
-** $Id: luadebug.h,v 1.5 1999/02/04 17:47:59 roberto Exp roberto $
+** $Id: luadebug.h,v 1.6 1999/03/04 21:17:26 roberto Exp roberto $
 ** Debugging API
 ** See Copyright Notice in lua.h
 */
@@ -14,14 +14,15 @@
 typedef lua_Object lua_Function;
 
 typedef void (*lua_LHFunction) (int line);
-typedef void (*lua_CHFunction) (lua_Function func, char *file, int line);
+typedef void (*lua_CHFunction) (lua_Function func, const char *file, int line);
 
 lua_Function lua_stackedfunction (int level);
-void lua_funcinfo (lua_Object func, char **source, int *linedefined);
+void lua_funcinfo (lua_Object func, const char **source, int *linedefined);
 int lua_currentline (lua_Function func);
-char *lua_getobjname (lua_Object o, char **name);
+const char *lua_getobjname (lua_Object o, const char **name);
 
-lua_Object lua_getlocal (lua_Function func, int local_number, char **name);
+lua_Object lua_getlocal (lua_Function func, int local_number,
+                         const char **name);
 int lua_setlocal (lua_Function func, int local_number);
 
 int lua_nups (lua_Function func);

+ 3 - 3
lualib.h

@@ -1,5 +1,5 @@
 /*
-** $Id: lualib.h,v 1.5 1999/01/08 16:47:44 roberto Exp roberto $
+** $Id: lualib.h,v 1.6 1999/05/05 19:23:11 roberto Exp roberto $
 ** Lua standard libraries
 ** See Copyright Notice in lua.h
 */
@@ -29,8 +29,8 @@ void lua_userinit (void);
 
 /* Auxiliary functions (private) */
 
-char *luaI_classend (char *p);
-int luaI_singlematch (int c, char *p, char *ep);
+const char *luaI_classend (const char *p);
+int luaI_singlematch (int c, const char *p, const char *ep);
 
 #endif
 

+ 6 - 6
lundump.c

@@ -1,5 +1,5 @@
 /*
-** $Id: lundump.c,v 1.21 1999/07/02 19:34:26 lhf Exp $
+** $Id: lundump.c,v 1.12 1999/07/08 12:43:23 roberto Exp roberto $
 ** load bytecodes from files
 ** See Copyright Notice in lua.h
 */
@@ -50,7 +50,7 @@ static unsigned long LoadLong (ZIO* Z)
 /*
 * convert number from text
 */
-double luaU_str2d (char* b, char* where)
+double luaU_str2d (const char* b, const char* where)
 {
  int negative=(b[0]=='-');
  double x=luaO_str2d(b+negative);
@@ -76,7 +76,7 @@ static real LoadNumber (ZIO* Z, int native)
  }
 }
 
-static int LoadInt (ZIO* Z, char* message)
+static int LoadInt (ZIO* Z, const char* message)
 {
  unsigned long l=LoadLong(Z);
  unsigned int i=l;
@@ -169,7 +169,7 @@ static TProtoFunc* LoadFunction (ZIO* Z, int native)
 
 static void LoadSignature (ZIO* Z)
 {
- char* s=SIGNATURE;
+ const char* s=SIGNATURE;
  while (*s!=0 && ezgetc(Z)==*s)
   ++s;
  if (*s!=0) luaL_verror("bad signature in %s",zname(Z));
@@ -231,9 +231,9 @@ TProtoFunc* luaU_undump1 (ZIO* Z)
 /*
 * handle constants that cannot happen
 */
-void luaU_badconstant (char* s, int i, TObject* o, TProtoFunc* tf)
+void luaU_badconstant (const char* s, int i, const TObject* o, TProtoFunc* tf)
 {
  int t=ttype(o);
- char* name= (t>0 || t<LUA_T_LINE) ? "?" : luaO_typenames[-t];
+ const char* name= (t>0 || t<LUA_T_LINE) ? "?" : luaO_typenames[-t];
  luaL_verror("cannot %s constant #%d: type=%d [%s]" IN,s,i,t,name,INLOC);
 }

+ 3 - 3
lundump.h

@@ -1,5 +1,5 @@
 /*
-** $Id: lundump.h,v 1.15 1999/07/02 19:34:26 lhf Exp $
+** $Id: lundump.h,v 1.9 1999/07/08 12:43:23 roberto Exp roberto $
 ** load pre-compiled Lua chunks
 ** See Copyright Notice in lua.h
 */
@@ -11,9 +11,9 @@
 #include "lzio.h"
 
 TProtoFunc* luaU_undump1 (ZIO* Z);	/* load one chunk */
-void luaU_badconstant (char* s, int i, TObject* o, TProtoFunc* tf);
+void luaU_badconstant (const char* s, int i, const TObject* o, TProtoFunc* tf);
 					/* handle cases that cannot happen */
-double luaU_str2d (char* b, char* where);
+double luaU_str2d (const char* b, const char* where);
 					/* convert number from text */
 
 /* definitions for headers of binary files */

+ 18 - 21
lvm.c

@@ -1,5 +1,5 @@
 /*
-** $Id: lvm.c,v 1.58 1999/06/22 20:37:23 roberto Exp roberto $
+** $Id: lvm.c,v 1.59 1999/08/10 12:55:47 roberto Exp roberto $
 ** Lua virtual machine
 ** See Copyright Notice in lua.h
 */
@@ -114,7 +114,7 @@ void luaV_closure (int nelems) {
 */
 void luaV_gettable (void) {
   TObject *table = L->stack.top-2;
-  TObject *im;
+  const TObject *im;
   if (ttype(table) != LUA_T_ARRAY) {  /* not a table, get gettable method */
     im = luaT_getimbyObj(table, IM_GETTABLE);
     if (ttype(im) == LUA_T_NIL)
@@ -146,9 +146,9 @@ void luaV_gettable (void) {
 /*
 ** Receives table at *t, index at *(t+1) and value at top.
 */
-void luaV_settable (TObject *t) {
+void luaV_settable (const TObject *t) {
   struct Stack *S = &L->stack;
-  TObject *im;
+  const TObject *im;
   if (ttype(t) != LUA_T_ARRAY) {  /* not a table, get "settable" method */
     im = luaT_getimbyObj(t, IM_SETTABLE);
     if (ttype(im) == LUA_T_NIL)
@@ -173,7 +173,7 @@ void luaV_settable (TObject *t) {
 }
 
 
-void luaV_rawsettable (TObject *t) {
+void luaV_rawsettable (const TObject *t) {
   if (ttype(t) != LUA_T_ARRAY)
     lua_error("indexed expression not a table");
   else {
@@ -186,7 +186,7 @@ void luaV_rawsettable (TObject *t) {
 
 void luaV_getglobal (TaggedString *ts) {
   /* WARNING: caller must assure stack space */
-  TObject *value = &ts->u.s.globalval;
+  const TObject *value = &ts->u.s.globalval;
   switch (ttype(value)) {
     /* only userdata, tables and nil can have getglobal tag methods */
     case LUA_T_USERDATA: case LUA_T_ARRAY: case LUA_T_NIL: {
@@ -208,8 +208,8 @@ void luaV_getglobal (TaggedString *ts) {
 
 
 void luaV_setglobal (TaggedString *ts) {
-  TObject *oldvalue = &ts->u.s.globalval;
-  TObject *im = luaT_getimbyObj(oldvalue, IM_SETGLOBAL);
+  const TObject *oldvalue = &ts->u.s.globalval;
+  const TObject *im = luaT_getimbyObj(oldvalue, IM_SETGLOBAL);
   if (ttype(im) == LUA_T_NIL)  /* is there a tag method? */
     luaS_rawsetglobal(ts, --L->stack.top);
   else {
@@ -226,9 +226,9 @@ void luaV_setglobal (TaggedString *ts) {
 }
 
 
-static void call_binTM (IMS event, char *msg)
-{
-  TObject *im = luaT_getimbyObj(L->stack.top-2, event);/* try first operand */
+static void call_binTM (IMS event, const char *msg) {
+  /* try first operand */
+  const TObject *im = luaT_getimbyObj(L->stack.top-2, event);
   if (ttype(im) == LUA_T_NIL) {
     im = luaT_getimbyObj(L->stack.top-1, event);  /* try second operand */
     if (ttype(im) == LUA_T_NIL) {
@@ -242,14 +242,12 @@ static void call_binTM (IMS event, char *msg)
 }
 
 
-static void call_arith (IMS event)
-{
+static void call_arith (IMS event) {
   call_binTM(event, "unexpected type in arithmetic operation");
 }
 
 
-static int luaV_strcomp (char *l, long ll, char *r, long lr)
-{
+static int luaV_strcomp (const char *l, long ll, const char *r, long lr) {
   for (;;) {
     long temp = strcoll(l, r);
     if (temp != 0) return temp;
@@ -268,8 +266,8 @@ static int luaV_strcomp (char *l, long ll, char *r, long lr)
 void luaV_comparison (lua_Type ttype_less, lua_Type ttype_equal,
                       lua_Type ttype_great, IMS op) {
   struct Stack *S = &L->stack;
-  TObject *l = S->top-2;
-  TObject *r = S->top-1;
+  const TObject *l = S->top-2;
+  const TObject *r = S->top-1;
   real result;
   if (ttype(l) == LUA_T_NUMBER && ttype(r) == LUA_T_NUMBER)
     result = nvalue(l)-nvalue(r);
@@ -300,8 +298,7 @@ void luaV_pack (StkId firstel, int nvararg, TObject *tab) {
 }
 
 
-static void adjust_varargs (StkId first_extra_arg)
-{
+static void adjust_varargs (StkId first_extra_arg) {
   TObject arg;
   luaV_pack(first_extra_arg,
        (L->stack.top-L->stack.stack)-first_extra_arg, &arg);
@@ -318,8 +315,8 @@ static void adjust_varargs (StkId first_extra_arg)
 */
 StkId luaV_execute (Closure *cl, TProtoFunc *tf, StkId base) {
   struct Stack *S = &L->stack;  /* to optimize */
-  register Byte *pc = tf->code;
-  TObject *consts = tf->consts;
+  register const Byte *pc = tf->code;
+  const TObject *consts = tf->consts;
   if (L->callhook)
     luaD_callHook(base, tf, 0);
   luaD_checkstack((*pc++)+EXTRA_STACK);

+ 3 - 3
lvm.h

@@ -1,5 +1,5 @@
 /*
-** $Id: lvm.h,v 1.7 1998/12/30 17:26:49 roberto Exp roberto $
+** $Id: lvm.h,v 1.8 1999/02/08 17:07:59 roberto Exp roberto $
 ** Lua virtual machine
 ** See Copyright Notice in lua.h
 */
@@ -22,8 +22,8 @@ int luaV_tonumber (TObject *obj);
 int luaV_tostring (TObject *obj);
 void luaV_setn (Hash *t, int val);
 void luaV_gettable (void);
-void luaV_settable (TObject *t);
-void luaV_rawsettable (TObject *t);
+void luaV_settable (const TObject *t);
+void luaV_rawsettable (const TObject *t);
 void luaV_getglobal (TaggedString *ts);
 void luaV_setglobal (TaggedString *ts);
 StkId luaV_execute (Closure *cl, TProtoFunc *tf, StkId base);

+ 28 - 31
lzio.c

@@ -1,5 +1,5 @@
 /*
-** $Id: lzio.c,v 1.6 1999/03/04 14:49:18 roberto Exp roberto $
+** $Id: lzio.c,v 1.7 1999/03/05 13:15:50 roberto Exp roberto $
 ** a generic input stream interface
 ** See Copyright Notice in lua.h
 */
@@ -16,51 +16,48 @@
 /* ----------------------------------------------------- memory buffers --- */
 
 static int zmfilbuf (ZIO* z) {
- return EOZ;
+  return EOZ;
 }
 
 
-ZIO* zmopen (ZIO* z, char* b, int size, char *name)
-{
- if (b==NULL) return NULL;
- z->n=size;
- z->p= (unsigned char *)b;
- z->filbuf=zmfilbuf;
- z->u=NULL;
- z->name=name;
- return 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->filbuf = zmfilbuf;
+  z->u = NULL;
+  z->name = name;
+  return z;
 }
 
 /* ------------------------------------------------------------ strings --- */
 
-ZIO* zsopen (ZIO* z, char* s, char *name)
-{
- if (s==NULL) return NULL;
- return zmopen(z,s,strlen(s),name);
+ZIO* zsopen (ZIO* z, const char* s, const char *name) {
+  if (s==NULL) return NULL;
+  return zmopen(z,s,strlen(s),name);
 }
 
 /* -------------------------------------------------------------- FILEs --- */
 
 static int zffilbuf (ZIO* z) {
- int n;
- if (feof((FILE *)z->u)) return EOZ;
- n=fread(z->buffer,1,ZBSIZE,z->u);
- if (n==0) return EOZ;
- z->n=n-1;
- z->p=z->buffer;
- return *(z->p++);
+  int n;
+  if (feof((FILE *)z->u)) return EOZ;
+  n = fread(z->buffer,1,ZBSIZE,z->u);
+  if (n==0) return EOZ;
+  z->n = n-1;
+  z->p = z->buffer;
+  return *(z->p++);
 }
 
 
-ZIO* zFopen (ZIO* z, FILE* f, char *name)
-{
- if (f==NULL) return NULL;
- z->n=0;
- z->p=z->buffer;
- z->filbuf=zffilbuf;
- z->u=f;
- z->name=name;
- return z;
+ZIO* zFopen (ZIO* z, FILE* f, const char *name) {
+  if (f==NULL) return NULL;
+  z->n = 0;
+  z->p = z->buffer;
+  z->filbuf = zffilbuf;
+  z->u = f;
+  z->name = name;
+  return z;
 }
 
 

+ 10 - 10
lzio.h

@@ -1,5 +1,5 @@
 /*
-** $Id: lzio.h,v 1.3 1997/12/22 20:57:18 roberto Exp roberto $
+** $Id: lzio.h,v 1.4 1998/01/09 14:57:43 roberto Exp roberto $
 ** Buffered streams
 ** See Copyright Notice in lua.h
 */
@@ -22,9 +22,9 @@
 
 typedef struct zio ZIO;
 
-ZIO* zFopen (ZIO* z, FILE* f, char *name);		/* open FILEs */
-ZIO* zsopen (ZIO* z, char* s, char *name);		/* string */
-ZIO* zmopen (ZIO* z, char* b, int size, char *name);	/* memory */
+ZIO* zFopen (ZIO* z, FILE* f, const char *name);	/* open FILEs */
+ZIO* zsopen (ZIO* z, const char* s, const char *name);	/* string */
+ZIO* zmopen (ZIO* z, const char* b, int size, const char *name);  /* memory */
 
 int zread (ZIO* z, void* b, int n);	/* read next n bytes */
 
@@ -38,12 +38,12 @@ int zread (ZIO* z, void* b, int n);	/* read next n bytes */
 #define ZBSIZE	256			/* buffer size */
 
 struct zio {
- int n;					/* bytes still unread */
- unsigned char* p;			/* current position in buffer */
- int (*filbuf)(ZIO* z);
- void* u;				/* additional data */
- char *name;
- unsigned char buffer[ZBSIZE];		/* buffer */
+  int n;				/* bytes still unread */
+  const unsigned char* p;		/* current position in buffer */
+  int (*filbuf)(ZIO* z);
+  void* u;				/* additional data */
+  const char *name;
+  unsigned char buffer[ZBSIZE];		/* buffer */
 };