Explorar o código

new way to handle `profiles'

Roberto Ierusalimschy %!s(int64=24) %!d(string=hai) anos
pai
achega
dd3a63c205
Modificáronse 30 ficheiros con 208 adicións e 120 borrados
  1. 4 3
      lapi.c
  2. 2 1
      lauxlib.c
  3. 74 9
      lbaselib.c
  4. 2 1
      lcode.c
  5. 2 1
      ldblib.c
  6. 2 1
      ldebug.c
  7. 3 2
      ldo.c
  8. 2 1
      lfunc.c
  9. 2 1
      lgc.c
  10. 7 5
      liolib.c
  11. 2 1
      llex.c
  12. 1 32
      llimits.h
  13. 2 1
      lmathlib.c
  14. 2 1
      lmem.c
  15. 3 2
      lobject.c
  16. 2 1
      lparser.c
  17. 2 1
      lstate.c
  18. 2 1
      lstring.c
  19. 2 1
      lstrlib.c
  20. 2 1
      ltable.c
  21. 2 1
      ltests.c
  22. 2 1
      ltm.c
  23. 3 2
      lua.c
  24. 59 10
      lua.h
  25. 2 25
      lualib.h
  26. 8 4
      lundump.c
  27. 2 4
      lundump.h
  28. 3 2
      lvm.c
  29. 6 2
      lzio.c
  30. 1 2
      lzio.h

+ 4 - 3
lapi.c

@@ -1,5 +1,5 @@
 /*
-** $Id: lapi.c,v 1.135 2001/03/02 17:27:50 roberto Exp roberto $
+** $Id: lapi.c,v 1.136 2001/03/07 18:09:25 roberto Exp roberto $
 ** Lua API
 ** See Copyright Notice in lua.h
 */
@@ -7,6 +7,7 @@
 
 #include <string.h>
 
+#define LUA_PRIVATE
 #include "lua.h"
 
 #include "lapi.h"
@@ -22,8 +23,8 @@
 #include "lvm.h"
 
 
-const l_char lua_ident[] = l_s("$Lua: ") LUA_VERSION l_s(" ")
-  LUA_COPYRIGHT l_s(" $\n") l_s("$Authors: ") LUA_AUTHORS l_s(" $");
+const l_char lua_ident[] = l_s("$Lua: ") l_s(LUA_VERSION) l_s(" ")
+  l_s(LUA_COPYRIGHT) l_s(" $\n") l_s("$Authors: ") l_s(LUA_AUTHORS) l_s(" $");
 
 
 

+ 2 - 1
lauxlib.c

@@ -1,5 +1,5 @@
 /*
-** $Id: lauxlib.c,v 1.47 2001/02/14 17:04:11 roberto Exp roberto $
+** $Id: lauxlib.c,v 1.48 2001/02/23 17:17:25 roberto Exp roberto $
 ** Auxiliary functions for building Lua libraries
 ** See Copyright Notice in lua.h
 */
@@ -14,6 +14,7 @@
 ** With care, these functions can be used by other libraries.
 */
 
+#define LUA_PRIVATE
 #include "lua.h"
 
 #include "lauxlib.h"

+ 74 - 9
lbaselib.c

@@ -1,5 +1,5 @@
 /*
-** $Id: lbaselib.c,v 1.29 2001/03/06 20:09:38 roberto Exp roberto $
+** $Id: lbaselib.c,v 1.30 2001/03/07 12:43:52 roberto Exp roberto $
 ** Basic library
 ** See Copyright Notice in lua.h
 */
@@ -11,6 +11,7 @@
 #include <stdlib.h>
 #include <string.h>
 
+#define LUA_PRIVATE
 #include "lua.h"
 
 #include "lauxlib.h"
@@ -42,7 +43,7 @@ static int luaB__ALERT (lua_State *L) {
 */
 static int luaB__ERRORMESSAGE (lua_State *L) {
   luaL_checktype(L, 1, LUA_TSTRING);
-  lua_getglobal(L, LUA_ALERT);
+  lua_getglobal(L, l_s(LUA_ALERT));
   if (lua_isfunction(L, -1)) {  /* avoid error loop if _ALERT is not defined */
     lua_Debug ar;
     lua_pushliteral(L, l_s("error: "));
@@ -303,6 +304,68 @@ static int luaB_dofile (lua_State *L) {
 }
 
 
+#define LUA_PATH	l_s("LUA_PATH")
+
+#define LUA_PATH_SEP	l_s(";")
+
+#ifndef LUA_PATH_DEFAULT
+#define LUA_PATH_DEFAULT	l_s("./")
+#endif
+
+static int luaB_require (lua_State *L) {
+  const l_char *path;
+  luaL_check_string(L, 1);
+  lua_settop(L, 1);
+  lua_getglobal(L, LUA_PATH);  /* get path */
+  if (lua_isstring(L, 2))  /* is LUA_PATH defined? */
+    path = lua_tostring(L, 2);
+  else {  /* LUA_PATH not defined */
+    lua_pop(L, 1);  /* pop old global value */
+    path = getenv(LUA_PATH);  /* try environment variable */
+    if (path == NULL) path = LUA_PATH_DEFAULT;  /* else use default */
+    lua_pushstring(L, path);
+    lua_pushvalue(L, -1);  /* duplicate to leave a copy on stack */
+    lua_setglobal(L, LUA_PATH);
+  }
+  lua_getregistry(L);
+  lua_pushliteral(L, LUA_PATH);
+  lua_gettable(L, 3);  /* get book-keeping table */
+  if (lua_isnil(L, 4)) {  /* no book-keeping table? */
+    lua_pop(L, 1);  /* pop the `nil' */
+    lua_newtable(L);  /* create book-keeping table */
+    lua_pushliteral(L, LUA_PATH);
+    lua_pushvalue(L, -2);  /* duplicate table to leave a copy on stack */
+    lua_settable(L, 3);  /* store book-keeping table in registry */
+  }
+  lua_pushvalue(L, 1);
+  lua_gettable(L, 4);  /* check package's name in book-keeping table */
+  if (!lua_isnil(L, -1))  /* is it there? */
+    return 0;  /* package is already loaded */
+  else {  /* must load it */
+    for (;;) {  /* traverse path */
+      int res;
+      int l = strcspn(path, LUA_PATH_SEP);  /* find separator */
+      lua_pushlstring(L, path, l);  /* directory name */
+      lua_pushvalue(L, 1);  /* package name */
+      lua_concat(L, 2);  /* concat directory with package name */
+      res = lua_dofile(L, lua_tostring(L, -1));  /* try to load it */
+      lua_settop(L, 4);  /* pop string and eventual results from dofile */
+      if (res == 0) break;  /* ok; file done */
+      else if (res != LUA_ERRFILE)
+        lua_error(L, NULL);  /* error running package; propagate it */
+      if (*(path+l) == l_c('\0'))  /* no more directories? */
+        luaL_verror(L, l_s("could not load package `%.20s' from path `%.200s'"),
+                    lua_tostring(L, 1), lua_tostring(L, 2));
+      path += l+1;  /* try next directory */
+    }
+  }
+  lua_pushvalue(L, 1);
+  lua_pushnumber(L, 1);
+  lua_settable(L, 4);  /* mark it as loaded */
+  return 0;
+}
+
+
 static int luaB_pack (lua_State *L) {
   int n = lua_gettop(L);
   lua_newtable(L);
@@ -337,10 +400,10 @@ static int luaB_call (lua_State *L) {
   int status;
   int n;
   if (!lua_isnull(L, 4)) {  /* set new error method */
-    lua_getglobal(L, LUA_ERRORMESSAGE);
+    lua_getglobal(L, l_s(LUA_ERRORMESSAGE));
     err = lua_gettop(L);  /* get index */
     lua_pushvalue(L, 4);
-    lua_setglobal(L, LUA_ERRORMESSAGE);
+    lua_setglobal(L, l_s(LUA_ERRORMESSAGE));
   }
   oldtop = lua_gettop(L);  /* top before function-call preparation */
   /* push function */
@@ -349,7 +412,7 @@ static int luaB_call (lua_State *L) {
   status = lua_call(L, n, LUA_MULTRET);
   if (err != 0) {  /* restore old error method */
     lua_pushvalue(L, err);
-    lua_setglobal(L, LUA_ERRORMESSAGE);
+    lua_setglobal(L, l_s(LUA_ERRORMESSAGE));
   }
   if (status != 0) {  /* error in call? */
     if (strchr(options, l_c('x')))
@@ -382,7 +445,8 @@ static int luaB_tostring (lua_State *L) {
     case LUA_TUSERDATA: {
       const l_char *t = lua_xtype(L, 1);
       if (strcmp(t, l_s("userdata")) == 0)
-        sprintf(buff, l_s("userdata(%d): %p"), lua_tag(L, 1), lua_touserdata(L, 1));
+        sprintf(buff, l_s("userdata(%d): %p"), lua_tag(L, 1),
+                lua_touserdata(L, 1));
       else
         sprintf(buff, l_s("%.40s: %p"), t, lua_touserdata(L, 1));
       break;
@@ -663,8 +727,8 @@ static void deprecated_funcs (lua_State *L) {
 /* }====================================================== */
 
 static const luaL_reg base_funcs[] = {
-  {LUA_ALERT, luaB__ALERT},
-  {LUA_ERRORMESSAGE, luaB__ERRORMESSAGE},
+  {l_s(LUA_ALERT), luaB__ALERT},
+  {l_s(LUA_ERRORMESSAGE), luaB__ERRORMESSAGE},
   {l_s("call"), luaB_call},
   {l_s("collectgarbage"), luaB_collectgarbage},
   {l_s("copytagmethods"), luaB_copytagmethods},
@@ -685,6 +749,7 @@ static const luaL_reg base_funcs[] = {
   {l_s("rawset"), luaB_rawset},
   {l_s("rawgettable"), luaB_rawget},  /* for compatibility 3.2 */
   {l_s("rawsettable"), luaB_rawset},  /* for compatibility 3.2 */
+  {l_s("require"), luaB_require},
   {l_s("setglobal"), luaB_setglobal},
   {l_s("settag"), luaB_settag},
   {l_s("settagmethod"), luaB_settagmethod},
@@ -706,7 +771,7 @@ static const luaL_reg base_funcs[] = {
 
 LUALIB_API int lua_baselibopen (lua_State *L) {
   luaL_openl(L, base_funcs);
-  lua_pushliteral(L, LUA_VERSION);
+  lua_pushliteral(L, l_s(LUA_VERSION));
   lua_setglobal(L, l_s("_VERSION"));
   deprecated_funcs(L);
   return 0;

+ 2 - 1
lcode.c

@@ -1,5 +1,5 @@
 /*
-** $Id: lcode.c,v 1.64 2001/02/23 20:28:19 roberto Exp roberto $
+** $Id: lcode.c,v 1.65 2001/03/07 13:22:55 roberto Exp roberto $
 ** Code generator for Lua
 ** See Copyright Notice in lua.h
 */
@@ -7,6 +7,7 @@
 
 #include <stdlib.h>
 
+#define LUA_PRIVATE
 #include "lua.h"
 
 #include "lcode.h"

+ 2 - 1
ldblib.c

@@ -1,5 +1,5 @@
 /*
-** $Id: ldblib.c,v 1.34 2001/03/06 20:09:38 roberto Exp roberto $
+** $Id: ldblib.c,v 1.35 2001/03/07 18:09:25 roberto Exp roberto $
 ** Interface from Lua to its debug API
 ** See Copyright Notice in lua.h
 */
@@ -9,6 +9,7 @@
 #include <stdlib.h>
 #include <string.h>
 
+#define LUA_PRIVATE
 #include "lua.h"
 
 #include "lauxlib.h"

+ 2 - 1
ldebug.c

@@ -1,5 +1,5 @@
 /*
-** $Id: ldebug.c,v 1.73 2001/03/07 13:22:55 roberto Exp roberto $
+** $Id: ldebug.c,v 1.74 2001/03/07 18:09:25 roberto Exp roberto $
 ** Debug Interface
 ** See Copyright Notice in lua.h
 */
@@ -7,6 +7,7 @@
 
 #include <stdlib.h>
 
+#define LUA_PRIVATE
 #include "lua.h"
 
 #include "lapi.h"

+ 3 - 2
ldo.c

@@ -1,5 +1,5 @@
 /*
-** $Id: ldo.c,v 1.130 2001/03/02 17:27:50 roberto Exp roberto $
+** $Id: ldo.c,v 1.131 2001/03/07 18:09:25 roberto Exp roberto $
 ** Stack and Call structure of Lua
 ** See Copyright Notice in lua.h
 */
@@ -10,6 +10,7 @@
 #include <stdlib.h>
 #include <string.h>
 
+#define LUA_PRIVATE
 #include "lua.h"
 
 #include "ldebug.h"
@@ -328,7 +329,7 @@ struct lua_longjmp {
 
 
 static void message (lua_State *L, const l_char *s) {
-  luaV_getglobal(L, luaS_newliteral(L, LUA_ERRORMESSAGE), L->top);
+  luaV_getglobal(L, luaS_newliteral(L, l_s(LUA_ERRORMESSAGE)), L->top);
   if (ttype(L->top) == LUA_TFUNCTION) {
     incr_top;
     setsvalue(L->top, luaS_new(L, s));

+ 2 - 1
lfunc.c

@@ -1,5 +1,5 @@
 /*
-** $Id: lfunc.c,v 1.41 2001/02/20 18:28:11 roberto Exp roberto $
+** $Id: lfunc.c,v 1.42 2001/02/23 17:17:25 roberto Exp roberto $
 ** Auxiliary functions to manipulate prototypes and closures
 ** See Copyright Notice in lua.h
 */
@@ -7,6 +7,7 @@
 
 #include <stdlib.h>
 
+#define LUA_PRIVATE
 #include "lua.h"
 
 #include "lfunc.h"

+ 2 - 1
lgc.c

@@ -1,9 +1,10 @@
 /*
-** $Id: lgc.c,v 1.93 2001/03/02 17:27:50 roberto Exp roberto $
+** $Id: lgc.c,v 1.94 2001/03/07 18:09:25 roberto Exp roberto $
 ** Garbage Collector
 ** See Copyright Notice in lua.h
 */
 
+#define LUA_PRIVATE
 #include "lua.h"
 
 #include "ldo.h"

+ 7 - 5
liolib.c

@@ -1,5 +1,5 @@
 /*
-** $Id: liolib.c,v 1.109 2001/02/23 17:28:12 roberto Exp roberto $
+** $Id: liolib.c,v 1.110 2001/03/06 20:09:38 roberto Exp roberto $
 ** Standard I/O (and system) library
 ** See Copyright Notice in lua.h
 */
@@ -11,6 +11,7 @@
 #include <string.h>
 #include <time.h>
 
+#define LUA_PRIVATE
 #include "lua.h"
 
 #include "lauxlib.h"
@@ -353,9 +354,10 @@ static int io_write (lua_State *L) {
   int arg;
   int status = 1;
   for (arg=1; arg<=nargs; arg++) {
-    if (lua_type(L, arg) == LUA_TNUMBER) {  /* LUA_NUMBER */
+    if (lua_type(L, arg) == LUA_TNUMBER) {
       /* optimization: could be done exactly as for strings */
-      status = status && fprintf(f, l_s("%.16g"), lua_tonumber(L, arg)) > 0;
+      status = status &&
+          fprintf(f, l_s(LUA_NUMBER_FMT), lua_tonumber(L, arg)) > 0;
     }
     else {
       size_t l;
@@ -638,7 +640,7 @@ static int errorfb (lua_State *L) {
     luaL_addstring(&b, l_s("\n"));
   }
   luaL_pushresult(&b);
-  lua_getglobal(L, LUA_ALERT);
+  lua_getglobal(L, l_s(LUA_ALERT));
   if (lua_isfunction(L, -1)) {  /* avoid loop if _ALERT is not defined */
     lua_pushvalue(L, -2);  /* error message */
     lua_rawcall(L, 1, 0);
@@ -671,7 +673,7 @@ static const luaL_reg iolib[] = {
   {l_s("tmpname"),   io_tmpname},
   {l_s("write"),     io_write},
   {l_s("writeto"),   io_writeto},
-  {LUA_ERRORMESSAGE, errorfb}
+  {l_s(LUA_ERRORMESSAGE), errorfb}
 };
 
 

+ 2 - 1
llex.c

@@ -1,5 +1,5 @@
 /*
-** $Id: llex.c,v 1.82 2001/03/06 14:46:54 roberto Exp roberto $
+** $Id: llex.c,v 1.83 2001/03/07 12:49:37 roberto Exp roberto $
 ** Lexical Analyzer
 ** See Copyright Notice in lua.h
 */
@@ -9,6 +9,7 @@
 #include <stdio.h>
 #include <string.h>
 
+#define LUA_PRIVATE
 #include "lua.h"
 
 #include "llex.h"

+ 1 - 32
llimits.h

@@ -1,5 +1,5 @@
 /*
-** $Id: llimits.h,v 1.26 2001/02/23 17:28:12 roberto Exp roberto $
+** $Id: llimits.h,v 1.27 2001/02/23 20:28:56 roberto Exp roberto $
 ** Limits, basic types, and some other `installation-dependent' definitions
 ** See Copyright Notice in lua.h
 */
@@ -33,31 +33,6 @@
 #endif
 
 
-/* function to convert a lua_Number to a string */
-#ifndef NUMBER_FMT
-#define NUMBER_FMT	l_s("%.16g")		/* LUA_NUMBER */
-#endif
-#ifndef lua_number2str
-#define lua_number2str(s,n)	sprintf((s), NUMBER_FMT, (n))
-#endif
-
-/* function to convert a string to a lua_Number */
-#ifndef lua_str2number
-#define lua_str2number(s,p)	strtod((s), (p))
-#endif
-
-
-/* macro to control type of literal strings */
-#ifndef l_s
-#define l_s(x)	x
-#endif
-
-/* macro to control type of literal chars */
-#ifndef l_c
-#define l_c(x)	x
-#endif
-
-
 /*
 ** the following types define integer types for values that may not
 ** fit in a `small int' (16 bits), but may waste space in a
@@ -81,12 +56,6 @@ typedef long ls_nstr;
 typedef unsigned char lu_byte;
 
 
-/* macro to `unsign' a character */
-#ifndef uchar
-#define uchar(c)	((unsigned char)(c))
-#endif
-
-
 #define MAX_SIZET	((size_t)(~(size_t)0)-2)
 
 

+ 2 - 1
lmathlib.c

@@ -1,5 +1,5 @@
 /*
-** $Id: lmathlib.c,v 1.36 2001/02/23 17:17:25 roberto Exp roberto $
+** $Id: lmathlib.c,v 1.37 2001/03/06 20:09:38 roberto Exp roberto $
 ** Standard mathematical library
 ** See Copyright Notice in lua.h
 */
@@ -8,6 +8,7 @@
 #include <stdlib.h>
 #include <math.h>
 
+#define LUA_PRIVATE
 #include "lua.h"
 
 #include "lauxlib.h"

+ 2 - 1
lmem.c

@@ -1,5 +1,5 @@
 /*
-** $Id: lmem.c,v 1.47 2001/02/20 18:15:33 roberto Exp roberto $
+** $Id: lmem.c,v 1.48 2001/02/23 17:17:25 roberto Exp roberto $
 ** Interface to Memory Manager
 ** See Copyright Notice in lua.h
 */
@@ -7,6 +7,7 @@
 
 #include <stdlib.h>
 
+#define LUA_PRIVATE
 #include "lua.h"
 
 #include "ldo.h"

+ 3 - 2
lobject.c

@@ -1,5 +1,5 @@
 /*
-** $Id: lobject.c,v 1.68 2001/02/23 20:30:01 roberto Exp roberto $
+** $Id: lobject.c,v 1.69 2001/03/07 12:27:06 roberto Exp roberto $
 ** Some generic functions over Lua objects
 ** See Copyright Notice in lua.h
 */
@@ -10,6 +10,7 @@
 #include <stdlib.h>
 #include <string.h>
 
+#define LUA_PRIVATE
 #include "lua.h"
 
 #include "ldo.h"
@@ -44,7 +45,7 @@ void *luaO_openspaceaux (lua_State *L, size_t n) {
 }
 
 
-int luaO_str2d (const l_char *s, lua_Number *result) {  /* LUA_NUMBER */
+int luaO_str2d (const l_char *s, lua_Number *result) {
   l_char *endptr;
   lua_Number res = lua_str2number(s, &endptr);
   if (endptr == s) return 0;  /* no conversion */

+ 2 - 1
lparser.c

@@ -1,5 +1,5 @@
 /*
-** $Id: lparser.c,v 1.138 2001/02/23 13:38:56 roberto Exp roberto $
+** $Id: lparser.c,v 1.139 2001/02/23 17:17:25 roberto Exp roberto $
 ** LL(1) Parser and code generator for Lua
 ** See Copyright Notice in lua.h
 */
@@ -8,6 +8,7 @@
 #include <stdio.h>
 #include <string.h>
 
+#define LUA_PRIVATE
 #include "lua.h"
 
 #include "lcode.h"

+ 2 - 1
lstate.c

@@ -1,5 +1,5 @@
 /*
-** $Id: lstate.c,v 1.59 2001/03/07 18:09:25 roberto Exp roberto $
+** $Id: lstate.c,v 1.60 2001/03/09 18:05:05 roberto Exp roberto $
 ** Global State
 ** See Copyright Notice in lua.h
 */
@@ -7,6 +7,7 @@
 
 #include <stdio.h>
 
+#define LUA_PRIVATE
 #include "lua.h"
 
 #include "ldo.h"

+ 2 - 1
lstring.c

@@ -1,5 +1,5 @@
 /*
-** $Id: lstring.c,v 1.60 2001/02/22 17:15:18 roberto Exp roberto $
+** $Id: lstring.c,v 1.61 2001/02/23 17:17:25 roberto Exp roberto $
 ** String table (keeps all strings handled by Lua)
 ** See Copyright Notice in lua.h
 */
@@ -7,6 +7,7 @@
 
 #include <string.h>
 
+#define LUA_PRIVATE
 #include "lua.h"
 
 #include "lmem.h"

+ 2 - 1
lstrlib.c

@@ -1,5 +1,5 @@
 /*
-** $Id: lstrlib.c,v 1.66 2001/03/02 17:40:08 roberto Exp roberto $
+** $Id: lstrlib.c,v 1.67 2001/03/06 20:09:38 roberto Exp roberto $
 ** Standard library for string operations and pattern-matching
 ** See Copyright Notice in lua.h
 */
@@ -11,6 +11,7 @@
 #include <stdlib.h>
 #include <string.h>
 
+#define LUA_PRIVATE
 #include "lua.h"
 
 #include "lauxlib.h"

+ 2 - 1
ltable.c

@@ -1,5 +1,5 @@
 /*
-** $Id: ltable.c,v 1.76 2001/02/20 18:15:33 roberto Exp roberto $
+** $Id: ltable.c,v 1.77 2001/02/23 17:17:25 roberto Exp roberto $
 ** Lua tables (hash)
 ** See Copyright Notice in lua.h
 */
@@ -18,6 +18,7 @@
 */
 
 
+#define LUA_PRIVATE
 #include "lua.h"
 
 #include "ldo.h"

+ 2 - 1
ltests.c

@@ -1,5 +1,5 @@
 /*
-** $Id: ltests.c,v 1.75 2001/03/07 13:22:55 roberto Exp roberto $
+** $Id: ltests.c,v 1.76 2001/03/09 18:05:05 roberto Exp roberto $
 ** Internal Module for Debugging of the Lua Implementation
 ** See Copyright Notice in lua.h
 */
@@ -12,6 +12,7 @@
 #include <string.h>
 
 
+#define LUA_PRIVATE
 #include "lua.h"
 
 #include "lapi.h"

+ 2 - 1
ltm.c

@@ -1,5 +1,5 @@
 /*
-** $Id: ltm.c,v 1.69 2001/02/23 17:17:25 roberto Exp roberto $
+** $Id: ltm.c,v 1.70 2001/03/02 17:27:50 roberto Exp roberto $
 ** Tag methods
 ** See Copyright Notice in lua.h
 */
@@ -8,6 +8,7 @@
 #include <stdio.h>
 #include <string.h>
 
+#define LUA_PRIVATE
 #include "lua.h"
 
 #include "ldo.h"

+ 3 - 2
lua.c

@@ -1,5 +1,5 @@
 /*
-** $Id: lua.c,v 1.64 2001/02/23 20:28:26 roberto Exp roberto $
+** $Id: lua.c,v 1.65 2001/03/09 18:05:05 roberto Exp roberto $
 ** Lua stand-alone interpreter
 ** See Copyright Notice in lua.h
 */
@@ -10,6 +10,7 @@
 #include <stdlib.h>
 #include <string.h>
 
+#define LUA_PRIVATE
 #include "lua.h"
 
 #include "luadebug.h"
@@ -118,7 +119,7 @@ static void print_message (void) {
 
 
 static void print_version (void) {
-  printf(l_s("%.80s  %.80s\n"), LUA_VERSION, LUA_COPYRIGHT);
+  printf(l_s("%.80s  %.80s\n"), l_s(LUA_VERSION), l_s(LUA_COPYRIGHT));
 }
 
 

+ 59 - 10
lua.h

@@ -1,9 +1,9 @@
 /*
-** $Id: lua.h,v 1.90 2001/02/23 17:28:12 roberto Exp roberto $
+** $Id: lua.h,v 1.91 2001/03/09 18:05:05 roberto Exp roberto $
 ** Lua - An Extensible Extension Language
 ** TeCGraf: Grupo de Tecnologia em Computacao Grafica, PUC-Rio, Brazil
 ** e-mail: [email protected]
-** www: http://www.tecgraf.puc-rio.br/lua/
+** www: http://www.lua.org
 ** See Copyright Notice at the end of this file
 */
 
@@ -17,13 +17,13 @@
 
 
 
-#define LUA_VERSION	l_s("Lua 4.1 (work)")
-#define LUA_COPYRIGHT	l_s("Copyright (C) 1994-2000 TeCGraf, PUC-Rio")
-#define LUA_AUTHORS 	l_s("W. Celes, R. Ierusalimschy & L. H. de Figueiredo")
+#define LUA_VERSION	"Lua 4.1 (work)"
+#define LUA_COPYRIGHT	"Copyright (C) 1994-2001 TeCGraf, PUC-Rio"
+#define LUA_AUTHORS 	"W. Celes, R. Ierusalimschy & L. H. de Figueiredo"
 
 
 /* name of global variable with error handler */
-#define LUA_ERRORMESSAGE	l_s("_ERRORMESSAGE")
+#define LUA_ERRORMESSAGE	"_ERRORMESSAGE"
 
 
 /* pre-defined references */
@@ -77,10 +77,16 @@ typedef int (*lua_CFunction) (lua_State *L);
 
 
 /* Lua numerical type */
-typedef double lua_Number;
+#ifndef LUA_NUMBER
+#define LUA_NUMBER	double
+#endif
+typedef LUA_NUMBER lua_Number;
 
 /* Lua character type */
-typedef char l_char;
+#ifndef L_CHAR
+#define L_CHAR	char
+#endif
+typedef L_CHAR l_char;
 
 
 /* mark for all API functions */
@@ -89,7 +95,6 @@ typedef char l_char;
 #endif
 
 
-
 /*
 ** state manipulation
 */
@@ -227,7 +232,7 @@ LUA_API void *lua_newuserdata (lua_State *L, size_t size);
 
 #define lua_getregistry(L)	lua_getref(L, LUA_REFREGISTRY)
 
-#define lua_pushliteral(L, s)	lua_pushlstring(L, l_s("") s, \
+#define lua_pushliteral(L, s)	lua_pushlstring(L, s, \
                                                 (sizeof(s)/sizeof(l_char))-1)
 
 
@@ -238,6 +243,50 @@ LUA_API void *lua_newuserdata (lua_State *L, size_t size);
 
 
 
+/*
+** {======================================================================
+** useful definitions for Lua kernel and libraries
+*/
+#ifdef LUA_PRIVATE
+
+/* macro to control type of literal strings */
+#ifndef l_s
+#define l_s(x)  x
+#endif
+
+/* macro to control type of literal chars */
+#ifndef l_c
+#define l_c(x)  x
+#endif
+
+/* macro to `unsign' a character */
+#ifndef uchar
+#define uchar(c)        ((unsigned char)(c))
+#endif
+
+/* integer type to hold the result of fgetc */
+#ifndef l_charint
+#define l_charint	int
+#endif
+
+/* function to convert a lua_Number to a string */
+#ifndef LUA_NUMBER_FMT
+#define LUA_NUMBER_FMT      "%.16g"
+#endif
+#ifndef lua_number2str
+#define lua_number2str(s,n)     sprintf((s), l_s(LUA_NUMBER_FMT), (n))
+#endif
+
+/* function to convert a string to a lua_Number */
+#ifndef lua_str2number
+#define lua_str2number(s,p)     strtod((s), (p))
+#endif
+
+#endif
+/* }====================================================================== */
+
+
+
 /******************************************************************************
 * Copyright (C) 1994-2000 TeCGraf, PUC-Rio.  All rights reserved.
 * 

+ 2 - 25
lualib.h

@@ -1,5 +1,5 @@
 /*
-** $Id: lualib.h,v 1.19 2001/02/23 20:31:37 roberto Exp roberto $
+** $Id: lualib.h,v 1.20 2001/03/06 20:09:38 roberto Exp roberto $
 ** Lua standard libraries
 ** See Copyright Notice in lua.h
 */
@@ -16,7 +16,7 @@
 #endif
 
 
-#define LUA_ALERT               l_s("_ALERT")
+#define LUA_ALERT               "_ALERT"
 
 LUALIB_API int lua_baselibopen (lua_State *L);
 LUALIB_API int lua_iolibopen (lua_State *L);
@@ -25,27 +25,4 @@ LUALIB_API int lua_mathlibopen (lua_State *L);
 LUALIB_API int lua_dblibopen (lua_State *L);
 
 
-
-/*
-** `private' part
-*/
-
-/* macro to `unsign' a character */
-#ifndef uchar
-#define uchar(c)	((unsigned char)(c))
-#endif
-
-/* integer type to hold the result of fgetc */
-typedef int l_charint;
-
-/* macro to control type of literal strings */
-#ifndef l_s
-#define l_s(x)	x
-#endif
-
-/* macro to control type of literal chars */
-#ifndef l_c
-#define l_c(x)	x
-#endif
-
 #endif

+ 8 - 4
lundump.c

@@ -1,5 +1,5 @@
 /*
-** $Id: lundump.c,v 1.38 2001/01/15 16:13:24 roberto Exp roberto $
+** $Id: lundump.c,v 1.39 2001/02/23 17:17:25 roberto Exp roberto $
 ** load bytecodes from files
 ** See Copyright Notice in lua.h
 */
@@ -7,6 +7,9 @@
 #include <stdio.h>
 #include <string.h>
 
+#define LUA_PRIVATE
+#include "lua.h"
+
 #include "lfunc.h"
 #include "lmem.h"
 #include "lopcodes.h"
@@ -96,7 +99,7 @@ static TString* LoadString (lua_State* L, ZIO* Z, int swap)
   return NULL;
  else
  {
-  l_char* s=luaO_openspace(L,size);
+  char* s=luaO_openspace(L,size,char);
   LoadBlock(L,s,size,Z,0);
   return luaS_newlstr(L,s,size-1);	/* remove trailing l_c('\0') */
  }
@@ -171,7 +174,7 @@ static Proto* LoadFunction (lua_State* L, ZIO* Z, int swap)
 
 static void LoadSignature (lua_State* L, ZIO* Z)
 {
- const l_char* s=SIGNATURE;
+ const l_char* s=l_s(SIGNATURE);
  while (*s!=0 && ezgetc(L,Z)==*s)
   ++s;
  if (*s!=0) luaO_verror(L,l_s("bad signature in `%.99s'"),ZNAME(Z));
@@ -213,7 +216,8 @@ static int LoadHeader (lua_State* L, ZIO* Z)
  f=LoadNumber(L,Z,swap);
  if ((long)f!=(long)tf)		/* disregard errors in last bit of fraction */
   luaO_verror(L,l_s("unknown number format in `%.99s':\n")
-      l_s("  read ") NUMBER_FMT l_s("; expected ") NUMBER_FMT, ZNAME(Z),f,tf);
+      l_s("  read ") l_s(LUA_NUMBER_FMT) l_s("; expected ") l_s(LUA_NUMBER_FMT),
+      ZNAME(Z),f,tf);
  return swap;
 }
 

+ 2 - 4
lundump.h

@@ -1,5 +1,5 @@
 /*
-** $Id: lundump.h,v 1.19 2000/11/07 12:44:44 roberto Exp roberto $
+** $Id: lundump.h,v 1.20 2001/02/23 17:17:25 roberto Exp roberto $
 ** load pre-compiled Lua chunks
 ** See Copyright Notice in lua.h
 */
@@ -20,12 +20,10 @@ int luaU_endianess (void);
 #define	VERSION		0x40		/* last format change was in 4.0 */
 #define	VERSION0	0x40		/* last major  change was in 4.0 */
 #define ID_CHUNK	27		/* binary files start with ESC... */
-#define	SIGNATURE	l_s("Lua")		/* ...followed by this signature */
+#define	SIGNATURE	"Lua"		/* ...followed by this signature */
 
 /* formats for error messages */
-#define SOURCE_FMT	l_s("<%d:%.99s>")
 #define SOURCE		tf->lineDefined,tf->source->str
-#define IN_FMT		l_s(" in %p ") SOURCE_FMT
 #define IN		tf,SOURCE
 
 /* a multiple of PI for testing native format */

+ 3 - 2
lvm.c

@@ -1,5 +1,5 @@
 /*
-** $Id: lvm.c,v 1.175 2001/03/07 18:09:25 roberto Exp roberto $
+** $Id: lvm.c,v 1.176 2001/03/07 18:16:22 roberto Exp roberto $
 ** Lua virtual machine
 ** See Copyright Notice in lua.h
 */
@@ -10,6 +10,7 @@
 #include <stdlib.h>
 #include <string.h>
 
+#define LUA_PRIVATE
 #include "lua.h"
 
 #include "lapi.h"
@@ -39,7 +40,7 @@ int luaV_tonumber (TObject *obj) {
 }
 
 
-int luaV_tostring (lua_State *L, TObject *obj) {  /* LUA_NUMBER */
+int luaV_tostring (lua_State *L, TObject *obj) {
   if (ttype(obj) != LUA_TNUMBER)
     return 1;
   else {

+ 6 - 2
lzio.c

@@ -1,5 +1,5 @@
 /*
-** $Id: lzio.c,v 1.12 2000/05/24 13:54:49 roberto Exp roberto $
+** $Id: lzio.c,v 1.13 2000/06/12 13:52:05 roberto Exp roberto $
 ** a generic input stream interface
 ** See Copyright Notice in lua.h
 */
@@ -9,6 +9,7 @@
 #include <stdio.h>
 #include <string.h>
 
+#define LUA_PRIVATE
 #include "lua.h"
 
 #include "lzio.h"
@@ -71,7 +72,10 @@ size_t zread (ZIO *z, void *b, size_t n) {
     if (z->n == 0) {
       if (z->filbuf(z) == EOZ)
         return n;  /* return number of missing bytes */
-      zungetc(z);  /* put result from `filbuf' in the buffer */
+      else {
+        ++z->n;  /* filbuf removed first byte; put back it */
+        --z->p;
+      }
     }
     m = (n <= z->n) ? n : z->n;  /* min. between n and z->n */
     memcpy(b, z->p, m);

+ 1 - 2
lzio.h

@@ -1,5 +1,5 @@
 /*
-** $Id: lzio.h,v 1.6 2000/05/24 13:54:49 roberto Exp roberto $
+** $Id: lzio.h,v 1.7 2000/10/20 16:36:32 roberto Exp roberto $
 ** Buffered streams
 ** See Copyright Notice in lua.h
 */
@@ -29,7 +29,6 @@ ZIO* zmopen (ZIO* z, const char* b, size_t size, const char *name); /* memory */
 size_t zread (ZIO* z, void* b, size_t n);	/* read next n bytes */
 
 #define zgetc(z)	(((z)->n--)>0 ? ((int)*(z)->p++): (z)->filbuf(z))
-#define zungetc(z)	(++(z)->n,--(z)->p)
 #define zname(z)	((z)->name)