summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2001-03-26 11:31:49 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2001-03-26 11:31:49 -0300
commitdd3a63c205a97339d8c8aec3cd49941bc10ba45c (patch)
tree763c1701607ace52692c8566277c6c70c7895acd
parentcb49b088b61b75b905663a58a2c545de1ffea13a (diff)
downloadlua-github-dd3a63c205a97339d8c8aec3cd49941bc10ba45c.tar.gz
new way to handle `profiles'
-rw-r--r--lapi.c7
-rw-r--r--lauxlib.c3
-rw-r--r--lbaselib.c83
-rw-r--r--lcode.c3
-rw-r--r--ldblib.c3
-rw-r--r--ldebug.c3
-rw-r--r--ldo.c5
-rw-r--r--lfunc.c3
-rw-r--r--lgc.c3
-rw-r--r--liolib.c12
-rw-r--r--llex.c3
-rw-r--r--llimits.h33
-rw-r--r--lmathlib.c3
-rw-r--r--lmem.c3
-rw-r--r--lobject.c5
-rw-r--r--lparser.c3
-rw-r--r--lstate.c3
-rw-r--r--lstring.c3
-rw-r--r--lstrlib.c3
-rw-r--r--ltable.c3
-rw-r--r--ltests.c3
-rw-r--r--ltm.c3
-rw-r--r--lua.c5
-rw-r--r--lua.h69
-rw-r--r--lualib.h27
-rw-r--r--lundump.c12
-rw-r--r--lundump.h6
-rw-r--r--lvm.c5
-rw-r--r--lzio.c8
-rw-r--r--lzio.h3
30 files changed, 208 insertions, 120 deletions
diff --git a/lapi.c b/lapi.c
index aa628469..6652e7f4 100644
--- a/lapi.c
+++ b/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(" $");
diff --git a/lauxlib.c b/lauxlib.c
index 5e9f4e89..08bc818f 100644
--- a/lauxlib.c
+++ b/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"
diff --git a/lbaselib.c b/lbaselib.c
index 20efb03e..d26bc7b0 100644
--- a/lbaselib.c
+++ b/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;
diff --git a/lcode.c b/lcode.c
index 9ef6c781..72a1b71e 100644
--- a/lcode.c
+++ b/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"
diff --git a/ldblib.c b/ldblib.c
index 98faf5a7..d5604f51 100644
--- a/ldblib.c
+++ b/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"
diff --git a/ldebug.c b/ldebug.c
index c3bf8756..5f114f88 100644
--- a/ldebug.c
+++ b/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"
diff --git a/ldo.c b/ldo.c
index 95db67a3..e9129805 100644
--- a/ldo.c
+++ b/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));
diff --git a/lfunc.c b/lfunc.c
index 7d6353cc..5fe9fa99 100644
--- a/lfunc.c
+++ b/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"
diff --git a/lgc.c b/lgc.c
index 26aa51ff..3a665660 100644
--- a/lgc.c
+++ b/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"
diff --git a/liolib.c b/liolib.c
index e1703ba7..d20fd12b 100644
--- a/liolib.c
+++ b/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}
};
diff --git a/llex.c b/llex.c
index 3dc87470..dfe7dbac 100644
--- a/llex.c
+++ b/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"
diff --git a/llimits.h b/llimits.h
index da14a37c..51dbe7af 100644
--- a/llimits.h
+++ b/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)
diff --git a/lmathlib.c b/lmathlib.c
index 739426bb..4135d030 100644
--- a/lmathlib.c
+++ b/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"
diff --git a/lmem.c b/lmem.c
index f88e769e..189986a5 100644
--- a/lmem.c
+++ b/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"
diff --git a/lobject.c b/lobject.c
index 6d283f2e..0b597ff1 100644
--- a/lobject.c
+++ b/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 */
diff --git a/lparser.c b/lparser.c
index 53e05565..fbf2009a 100644
--- a/lparser.c
+++ b/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"
diff --git a/lstate.c b/lstate.c
index 059390fb..1006dbec 100644
--- a/lstate.c
+++ b/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"
diff --git a/lstring.c b/lstring.c
index 7dee4285..4318070d 100644
--- a/lstring.c
+++ b/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"
diff --git a/lstrlib.c b/lstrlib.c
index c448f57e..a1f1acf7 100644
--- a/lstrlib.c
+++ b/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"
diff --git a/ltable.c b/ltable.c
index 845e639e..284826ef 100644
--- a/ltable.c
+++ b/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"
diff --git a/ltests.c b/ltests.c
index 8f20c67b..4b8fcd01 100644
--- a/ltests.c
+++ b/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"
diff --git a/ltm.c b/ltm.c
index df30955b..b66d3d46 100644
--- a/ltm.c
+++ b/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"
diff --git a/lua.c b/lua.c
index e964518b..fc2e89b0 100644
--- a/lua.c
+++ b/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));
}
diff --git a/lua.h b/lua.h
index bf04e14f..95b86cdf 100644
--- a/lua.h
+++ b/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: lua@tecgraf.puc-rio.br
-** 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.
*
diff --git a/lualib.h b/lualib.h
index 3ef1ded8..349696f5 100644
--- a/lualib.h
+++ b/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
diff --git a/lundump.c b/lundump.c
index 353e746e..f12bade5 100644
--- a/lundump.c
+++ b/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;
}
diff --git a/lundump.h b/lundump.h
index 19bef569..ba7dd82b 100644
--- a/lundump.h
+++ b/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 */
diff --git a/lvm.c b/lvm.c
index 0a7324a8..14f6feb3 100644
--- a/lvm.c
+++ b/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 {
diff --git a/lzio.c b/lzio.c
index c523ece5..b5892ce0 100644
--- a/lzio.c
+++ b/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);
diff --git a/lzio.h b/lzio.h
index ea838ad0..437ac1d2 100644
--- a/lzio.h
+++ b/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)