commit b4cd38ba6c148cf7db5deae6208b660c3417cac9
parent 079facab40542ff2e6be9ecc254fd148772b47c9
Author: Roberto Ierusalimschy <roberto@inf.puc-rio.br>
Date: Fri, 30 Apr 2004 17:13:16 -0300
new scheme for configuration through `luaconf.h'
Diffstat:
34 files changed, 175 insertions(+), 394 deletions(-)
diff --git a/lapi.c b/lapi.c
@@ -1,5 +1,5 @@
/*
-** $Id: lapi.c,v 2.5 2004/03/23 17:07:34 roberto Exp roberto $
+** $Id: lapi.c,v 2.6 2004/04/05 14:43:17 roberto Exp roberto $
** Lua API
** See Copyright Notice in lua.h
*/
@@ -10,6 +10,7 @@
#include <string.h>
#define lapi_c
+#define LUA_CORE
#include "lua.h"
@@ -28,11 +29,6 @@
#include "lvm.h"
-/* function to convert a lua_Number to lua_Integer (with any rounding method) */
-#ifndef lua_number2integer
-#define lua_number2integer(i,n) ((i)=(lua_Integer)(n))
-#endif
-
const char lua_ident[] =
"$Lua: " LUA_VERSION " " LUA_COPYRIGHT " $\n"
@@ -41,10 +37,6 @@ const char lua_ident[] =
-#ifndef api_check
-#define api_check(L, o) lua_assert(o)
-#endif
-
#define api_checknelems(L, n) api_check(L, (n) <= (L->top - L->base))
#define api_checkvalidindex(L, i) api_check(L, (i) != &luaO_nilobject)
@@ -87,7 +79,7 @@ void luaA_pushobject (lua_State *L, const TValue *o) {
LUA_API int lua_checkstack (lua_State *L, int size) {
int res;
lua_lock(L);
- if ((L->top - L->base + size) > LUA_MAXCSTACK)
+ if ((L->top - L->base + size) > MAXCSTACK)
res = 0; /* stack overflow */
else {
luaD_checkstack(L, size);
diff --git a/lauxlib.c b/lauxlib.c
@@ -1,5 +1,5 @@
/*
-** $Id: lauxlib.c,v 1.109 2004/02/18 13:40:03 roberto Exp roberto $
+** $Id: lauxlib.c,v 1.110 2004/03/23 16:38:43 roberto Exp roberto $
** Auxiliary functions for building Lua libraries
** See Copyright Notice in lua.h
*/
@@ -18,6 +18,7 @@
*/
#define lauxlib_c
+#define LUA_LIB
#include "lua.h"
@@ -288,7 +289,7 @@ static void getsizes (lua_State *L) {
}
-void luaL_setn (lua_State *L, int t, int n) {
+LUALIB_API void luaL_setn (lua_State *L, int t, int n) {
t = abs_index(L, t);
getsizes(L);
lua_pushvalue(L, t);
@@ -298,7 +299,7 @@ void luaL_setn (lua_State *L, int t, int n) {
}
-int luaL_getn (lua_State *L, int t) {
+LUALIB_API int luaL_getn (lua_State *L, int t) {
int n;
t = abs_index(L, t);
getsizes(L); /* try sizes[t] */
diff --git a/lbaselib.c b/lbaselib.c
@@ -1,5 +1,5 @@
/*
-** $Id: lbaselib.c,v 1.140 2004/03/09 17:34:35 roberto Exp roberto $
+** $Id: lbaselib.c,v 1.141 2004/03/26 13:25:17 roberto Exp roberto $
** Basic library
** See Copyright Notice in lua.h
*/
@@ -12,6 +12,7 @@
#include <string.h>
#define lbaselib_c
+#define LUA_LIB
#include "lua.h"
@@ -235,28 +236,29 @@ static int luaB_next (lua_State *L) {
static int luaB_pairs (lua_State *L) {
luaL_checktype(L, 1, LUA_TTABLE);
- lua_getglobal(L, "next"); /* return generator, */
+ lua_pushvalue(L, lua_upvalueindex(1)); /* return generator, */
lua_pushvalue(L, 1); /* state, */
lua_pushnil(L); /* and initial value */
return 3;
}
+static int ipairsaux (lua_State *L) {
+ int i = luaL_checkint(L, 2);
+ luaL_checktype(L, 1, LUA_TTABLE);
+ i++; /* next value */
+ lua_pushinteger(L, i);
+ lua_rawgeti(L, 1, i);
+ return (lua_isnil(L, -1)) ? 0 : 2;
+}
+
+
static int luaB_ipairs (lua_State *L) {
- int i = (int)lua_tointeger(L, 2);
luaL_checktype(L, 1, LUA_TTABLE);
- if (i == 0 && lua_isnone(L, 2)) { /* `for' start? */
- lua_getglobal(L, "ipairs"); /* return generator, */
- lua_pushvalue(L, 1); /* state, */
- lua_pushinteger(L, 0); /* and initial value */
- return 3;
- }
- else { /* `for' step */
- i++; /* next value */
- lua_pushinteger(L, i);
- lua_rawgeti(L, 1, i);
- return (lua_isnil(L, -1)) ? 0 : 2;
- }
+ lua_pushvalue(L, lua_upvalueindex(1)); /* return generator, */
+ lua_pushvalue(L, 1); /* state, */
+ lua_pushinteger(L, 0); /* and initial value */
+ return 3;
}
@@ -458,25 +460,6 @@ static int luaB_newproxy (lua_State *L) {
*/
-/* name of global that holds table with loaded packages */
-#define REQTAB "_LOADED"
-
-/* name of global that holds the search path for packages */
-#define LUA_PATH "LUA_PATH"
-
-#ifndef LUA_PATH_SEP
-#define LUA_PATH_SEP ';'
-#endif
-
-#ifndef LUA_PATH_MARK
-#define LUA_PATH_MARK '?'
-#endif
-
-#ifndef LUA_PATH_DEFAULT
-#define LUA_PATH_DEFAULT "?;?.lua"
-#endif
-
-
static const char *getpath (lua_State *L) {
const char *path;
lua_getglobal(L, LUA_PATH); /* try global variable */
@@ -576,8 +559,6 @@ static const luaL_reg base_funcs[] = {
{"getfenv", luaB_getfenv},
{"setfenv", luaB_setfenv},
{"next", luaB_next},
- {"ipairs", luaB_ipairs},
- {"pairs", luaB_pairs},
{"print", luaB_print},
{"tonumber", luaB_tonumber},
{"tostring", luaB_tostring},
@@ -708,12 +689,22 @@ static const luaL_reg co_funcs[] = {
/* }====================================================== */
+static void auxopen (lua_State *L, const char *name,
+ lua_CFunction f, lua_CFunction u) {
+ lua_pushcfunction(L, u);
+ lua_pushcclosure(L, f, 1);
+ lua_setfield(L, -2, name);
+}
+
static void base_open (lua_State *L) {
lua_pushvalue(L, LUA_GLOBALSINDEX);
luaL_openlib(L, NULL, base_funcs, 0); /* open lib into global table */
lua_pushliteral(L, LUA_VERSION);
lua_setfield(L, -2, "_VERSION"); /* set global _VERSION */
+ /* `ipairs' and `pairs' need auxiliary functions as upvalues */
+ auxopen(L, "ipairs", luaB_ipairs, ipairsaux);
+ auxopen(L, "pairs", luaB_pairs, luaB_next);
/* `newproxy' needs a weaktable as upvalue */
lua_newtable(L); /* new table `w' */
lua_pushvalue(L, -1); /* `w' will be its own metatable */
diff --git a/lcode.c b/lcode.c
@@ -1,5 +1,5 @@
/*
-** $Id: lcode.c,v 1.121 2003/12/09 16:56:11 roberto Exp roberto $
+** $Id: lcode.c,v 2.1 2003/12/10 12:13:36 roberto Exp roberto $
** Code generator for Lua
** See Copyright Notice in lua.h
*/
@@ -8,6 +8,7 @@
#include <stdlib.h>
#define lcode_c
+#define LUA_CORE
#include "lua.h"
diff --git a/ldblib.c b/ldblib.c
@@ -1,5 +1,5 @@
/*
-** $Id: ldblib.c,v 1.83 2003/10/10 12:57:55 roberto Exp roberto $
+** $Id: ldblib.c,v 1.84 2003/11/05 11:59:14 roberto Exp roberto $
** Interface from Lua to its debug API
** See Copyright Notice in lua.h
*/
@@ -10,6 +10,7 @@
#include <string.h>
#define ldblib_c
+#define LUA_LIB
#include "lua.h"
diff --git a/ldebug.c b/ldebug.c
@@ -1,5 +1,5 @@
/*
-** $Id: ldebug.c,v 2.2 2004/02/20 16:01:05 roberto Exp roberto $
+** $Id: ldebug.c,v 2.3 2004/03/23 13:10:16 roberto Exp roberto $
** Debug Interface
** See Copyright Notice in lua.h
*/
@@ -11,6 +11,7 @@
#define ldebug_c
+#define LUA_CORE
#include "lua.h"
diff --git a/ldo.c b/ldo.c
@@ -1,15 +1,15 @@
/*
-** $Id: ldo.c,v 2.1 2003/12/10 12:13:36 roberto Exp roberto $
+** $Id: ldo.c,v 2.2 2004/03/23 17:02:58 roberto Exp roberto $
** Stack and Call structure of Lua
** See Copyright Notice in lua.h
*/
-#include <setjmp.h>
#include <stdlib.h>
#include <string.h>
#define ldo_c
+#define LUA_CORE
#include "lua.h"
@@ -34,29 +34,15 @@
/*
** {======================================================
-** Error-recovery functions (based on long jumps)
+** Error-recovery functions
** =======================================================
*/
-#ifndef LUA_USEEXCEPTIONS
-
-#define L_THROW(c) longjmp((c)->b, 1)
-#define L_TRY(c,a) if (setjmp((c)->b) == 0) { a }
-
-#else
-
-#define L_THROW(c) throw(c)
-#define L_TRY(c,a) try { a } catch(...) \
- { if ((c)->status == 0) (c)->status = -1; }
-
-#endif
-
-
/* chain list of long jump buffers */
struct lua_longjmp {
struct lua_longjmp *previous;
- jmp_buf b;
+ l_jmpbuf b;
volatile int status; /* error code */
};
diff --git a/ldump.c b/ldump.c
@@ -1,5 +1,5 @@
/*
-** $Id: ldump.c,v 1.6 2003/08/15 13:48:53 roberto Exp roberto $
+** $Id: ldump.c,v 2.1 2003/12/10 12:13:36 roberto Exp roberto $
** save bytecodes
** See Copyright Notice in lua.h
*/
@@ -7,6 +7,7 @@
#include <stddef.h>
#define ldump_c
+#define LUA_CORE
#include "lua.h"
diff --git a/lfunc.c b/lfunc.c
@@ -1,5 +1,5 @@
/*
-** $Id: lfunc.c,v 2.2 2004/02/16 19:09:52 roberto Exp roberto $
+** $Id: lfunc.c,v 2.3 2004/03/15 21:04:33 roberto Exp roberto $
** Auxiliary functions to manipulate prototypes and closures
** See Copyright Notice in lua.h
*/
@@ -8,6 +8,7 @@
#include <stddef.h>
#define lfunc_c
+#define LUA_CORE
#include "lua.h"
diff --git a/lgc.c b/lgc.c
@@ -1,5 +1,5 @@
/*
-** $Id: lgc.c,v 2.5 2004/03/15 21:04:33 roberto Exp roberto $
+** $Id: lgc.c,v 2.6 2004/03/23 12:57:12 roberto Exp roberto $
** Garbage Collector
** See Copyright Notice in lua.h
*/
@@ -7,6 +7,7 @@
#include <string.h>
#define lgc_c
+#define LUA_CORE
#include "lua.h"
diff --git a/liolib.c b/liolib.c
@@ -1,5 +1,5 @@
/*
-** $Id: liolib.c,v 2.48 2003/10/10 12:57:55 roberto Exp roberto $
+** $Id: liolib.c,v 2.49 2003/10/10 13:29:28 roberto Exp roberto $
** Standard I/O (and system) library
** See Copyright Notice in lua.h
*/
@@ -13,6 +13,7 @@
#include <time.h>
#define liolib_c
+#define LUA_LIB
#include "lua.h"
@@ -21,31 +22,6 @@
-/*
-** by default, gcc does not get `tmpname'
-*/
-#ifndef USE_TMPNAME
-#ifdef __GNUC__
-#define USE_TMPNAME 0
-#else
-#define USE_TMPNAME 1
-#endif
-#endif
-
-
-/*
-** by default, posix systems get `popen'
-*/
-#ifndef USE_POPEN
-#if defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 2
-#define USE_POPEN 1
-#else
-#define USE_POPEN 0
-#endif
-#endif
-
-
-
/*
** {======================================================
diff --git a/llex.c b/llex.c
@@ -1,5 +1,5 @@
/*
-** $Id: llex.c,v 2.1 2003/12/10 12:13:36 roberto Exp roberto $
+** $Id: llex.c,v 2.2 2004/03/12 19:53:56 roberto Exp roberto $
** Lexical Analyzer
** See Copyright Notice in lua.h
*/
@@ -9,6 +9,7 @@
#include <string.h>
#define llex_c
+#define LUA_CORE
#include "lua.h"
diff --git a/llimits.h b/llimits.h
@@ -1,5 +1,5 @@
/*
-** $Id: llimits.h,v 1.56 2003/07/29 19:26:34 roberto Exp roberto $
+** $Id: llimits.h,v 1.57 2003/12/01 16:33:30 roberto Exp roberto $
** Limits, basic types, and some other `installation-dependent' definitions
** See Copyright Notice in lua.h
*/
@@ -15,48 +15,9 @@
#include "lua.h"
-/*
-** try to find number of bits in an integer
-*/
-#ifndef BITS_INT
-/* avoid overflows in comparison */
-#if INT_MAX-20 < 32760
-#define BITS_INT 16
-#elif INT_MAX > 2147483640L
-/* machine has at least 32 bits */
-#define BITS_INT 32
-#else
-#error "you must define BITS_INT with number of bits in an integer"
-#endif
-#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
-** `large long' (64 bits). The current definitions should work in
-** any machine, but may not be optimal.
-*/
-
-
-/*
-** an unsigned integer with at least 32 bits
-*/
-#ifndef LUA_UINT32
-#define LUA_UINT32 unsigned long
-#endif
typedef LUA_UINT32 lu_int32;
-
-/*
-** a signed integer with at least 32 bits
-*/
-#ifndef LUA_INT32
-#define LUA_INT32 long
-#define LUA_MAXINT32 LONG_MAX
-#endif
-
typedef LUA_INT32 l_int32;
@@ -95,19 +56,11 @@ typedef unsigned char lu_byte;
/* type to ensure maximum alignment */
-#ifndef LUSER_ALIGNMENT_T
-typedef union { double u; void *s; long l; } L_Umaxalign;
-#else
typedef LUSER_ALIGNMENT_T L_Umaxalign;
-#endif
-/* result of `usual argument conversion' over lua_Number */
-#ifndef LUA_UACNUMBER
-typedef double l_uacNumber;
-#else
+/* result of a `usual argument conversion' over lua_Number */
typedef LUA_UACNUMBER l_uacNumber;
-#endif
#ifndef lua_assert
@@ -138,43 +91,11 @@ typedef LUA_UACNUMBER l_uacNumber;
typedef lu_int32 Instruction;
-/* maximum depth for calls (unsigned short) */
-#ifndef LUA_MAXCALLS
-#define LUA_MAXCALLS 4096
-#endif
-
-
-/*
-** maximum depth for C calls (unsigned short): Not too big, or may
-** overflow the C stack...
-*/
-
-#ifndef LUA_MAXCCALLS
-#define LUA_MAXCCALLS 200
-#endif
-
-
-/* maximum size for the virtual stack of a C function */
-#ifndef LUA_MAXCSTACK
-#define LUA_MAXCSTACK 2048
-#endif
-
/* maximum stack for a Lua function */
#define MAXSTACK 250
-/* maximum number of variables declared in a function */
-#ifndef MAXVARS
-#define MAXVARS 200 /* <MAXSTACK */
-#endif
-
-
-/* maximum number of upvalues per function */
-#ifndef MAXUPVALUES
-#define MAXUPVALUES 32 /* <MAXSTACK */
-#endif
-
/* minimum size for the string table (must be power of 2) */
#ifndef MINSTRTABSIZE
@@ -188,13 +109,4 @@ typedef lu_int32 Instruction;
#endif
-/*
-** maximum number of syntactical nested non-terminals: Not too big,
-** or may overflow the C stack...
-*/
-#ifndef LUA_MAXPARSERLEVEL
-#define LUA_MAXPARSERLEVEL 200
-#endif
-
-
#endif
diff --git a/lmathlib.c b/lmathlib.c
@@ -1,5 +1,5 @@
/*
-** $Id: lmathlib.c,v 1.58 2003/10/10 12:57:55 roberto Exp roberto $
+** $Id: lmathlib.c,v 1.59 2003/11/05 11:59:14 roberto Exp roberto $
** Standard mathematical library
** See Copyright Notice in lua.h
*/
@@ -9,6 +9,7 @@
#include <math.h>
#define lmathlib_c
+#define LUA_LIB
#include "lua.h"
diff --git a/lmem.c b/lmem.c
@@ -1,5 +1,5 @@
/*
-** $Id: lmem.c,v 1.62 2003/10/02 20:31:17 roberto Exp roberto $
+** $Id: lmem.c,v 1.63 2003/11/27 18:18:37 roberto Exp roberto $
** Interface to Memory Manager
** See Copyright Notice in lua.h
*/
@@ -8,6 +8,7 @@
#include <stddef.h>
#define lmem_c
+#define LUA_CORE
#include "lua.h"
diff --git a/loadlib.c b/loadlib.c
@@ -1,5 +1,5 @@
/*
-** $Id: loadlib.c,v 1.4 2003/04/07 20:11:53 roberto Exp roberto $
+** $Id: loadlib.c,v 1.5 2003/05/14 21:01:53 roberto Exp roberto $
** Dynamic library loader for Lua
** See Copyright Notice in lua.h
*
@@ -26,6 +26,9 @@
*
*/
+#define loadlib_c
+#define LUA_LIB
+
#include "lua.h"
#include "lauxlib.h"
#include "lualib.h"
diff --git a/lobject.c b/lobject.c
@@ -1,5 +1,5 @@
/*
-** $Id: lobject.c,v 1.99 2003/06/10 12:36:26 roberto Exp roberto $
+** $Id: lobject.c,v 2.1 2003/12/10 12:13:36 roberto Exp roberto $
** Some generic functions over Lua objects
** See Copyright Notice in lua.h
*/
@@ -10,6 +10,7 @@
#include <string.h>
#define lobject_c
+#define LUA_CORE
#include "lua.h"
@@ -21,11 +22,6 @@
#include "lvm.h"
-/* function to convert a string to a lua_Number */
-#ifndef lua_str2number
-#define lua_str2number(s,p) strtod((s), (p))
-#endif
-
const TValue luaO_nilobject = {LUA_TNIL, {NULL}};
diff --git a/lopcodes.c b/lopcodes.c
@@ -1,10 +1,11 @@
/*
-** $Id: lopcodes.c,v 1.24 2003/05/14 12:09:12 roberto Exp roberto $
+** $Id: lopcodes.c,v 1.25 2003/05/14 21:09:53 roberto Exp roberto $
** See Copyright Notice in lua.h
*/
#define lopcodes_c
+#define LUA_CORE
#include "lua.h"
diff --git a/lopcodes.h b/lopcodes.h
@@ -1,5 +1,5 @@
/*
-** $Id: lopcodes.h,v 1.105 2003/05/14 21:09:53 roberto Exp roberto $
+** $Id: lopcodes.h,v 1.106 2003/05/15 19:46:03 roberto Exp roberto $
** Opcodes for Lua virtual machine
** See Copyright Notice in lua.h
*/
@@ -50,9 +50,9 @@ enum OpMode {iABC, iABx, iAsBx}; /* basic instruction format */
/*
** limits for opcode arguments.
** we use (signed) int to manipulate most arguments,
-** so they must fit in BITS_INT-1 bits (-1 for sign)
+** so they must fit in LUA_BITSINT-1 bits (-1 for sign)
*/
-#if SIZE_Bx < BITS_INT-1
+#if SIZE_Bx < LUA_BITSINT-1
#define MAXARG_Bx ((1<<SIZE_Bx)-1)
#define MAXARG_sBx (MAXARG_Bx>>1) /* `sBx' is signed */
#else
diff --git a/lparser.c b/lparser.c
@@ -1,5 +1,5 @@
/*
-** $Id: lparser.c,v 2.2 2004/03/12 19:53:56 roberto Exp roberto $
+** $Id: lparser.c,v 2.3 2004/03/26 14:02:41 roberto Exp roberto $
** Lua Parser
** See Copyright Notice in lua.h
*/
@@ -8,6 +8,7 @@
#include <string.h>
#define lparser_c
+#define LUA_CORE
#include "lua.h"
@@ -977,12 +978,6 @@ static int cond (LexState *ls) {
** after its body (and thus avoiding one jump in the loop).
*/
-/*
-** maximum size of expressions for optimizing `while' code
-*/
-#ifndef MAXEXPWHILE
-#define MAXEXPWHILE 100
-#endif
/*
** the call `luaK_goiffalse' may grow the size of an expression by
diff --git a/lstate.c b/lstate.c
@@ -1,5 +1,5 @@
/*
-** $Id: lstate.c,v 2.4 2004/03/15 21:04:33 roberto Exp roberto $
+** $Id: lstate.c,v 2.5 2004/03/23 12:57:12 roberto Exp roberto $
** Global State
** See Copyright Notice in lua.h
*/
@@ -8,6 +8,7 @@
#include <stddef.h>
#define lstate_c
+#define LUA_CORE
#include "lua.h"
diff --git a/lstring.c b/lstring.c
@@ -1,5 +1,5 @@
/*
-** $Id: lstring.c,v 1.85 2003/12/09 16:56:11 roberto Exp roberto $
+** $Id: lstring.c,v 2.1 2003/12/10 12:13:36 roberto Exp roberto $
** String table (keeps all strings handled by Lua)
** See Copyright Notice in lua.h
*/
@@ -8,6 +8,7 @@
#include <string.h>
#define lstring_c
+#define LUA_CORE
#include "lua.h"
diff --git a/lstrlib.c b/lstrlib.c
@@ -1,5 +1,5 @@
/*
-** $Id: lstrlib.c,v 1.100 2003/10/07 20:13:41 roberto Exp roberto $
+** $Id: lstrlib.c,v 1.101 2004/01/02 11:54:14 roberto Exp roberto $
** Standard library for string operations and pattern-matching
** See Copyright Notice in lua.h
*/
@@ -12,6 +12,7 @@
#include <string.h>
#define lstrlib_c
+#define LUA_LIB
#include "lua.h"
@@ -20,9 +21,7 @@
/* macro to `unsign' a character */
-#ifndef uchar
#define uchar(c) ((unsigned char)(c))
-#endif
typedef lua_Integer sint32; /* a signed version for size_t */
@@ -156,10 +155,6 @@ static int str_dump (lua_State *L) {
** =======================================================
*/
-#ifndef MAX_CAPTURES
-#define MAX_CAPTURES 32 /* arbitrary limit */
-#endif
-
#define CAP_UNFINISHED (-1)
#define CAP_POSITION (-2)
diff --git a/ltable.c b/ltable.c
@@ -1,5 +1,5 @@
/*
-** $Id: ltable.c,v 2.1 2003/12/10 12:13:36 roberto Exp roberto $
+** $Id: ltable.c,v 2.2 2004/03/26 14:02:41 roberto Exp roberto $
** Lua tables (hash)
** See Copyright Notice in lua.h
*/
@@ -21,6 +21,7 @@
#include <string.h>
#define ltable_c
+#define LUA_CORE
#include "lua.h"
@@ -36,19 +37,14 @@
/*
** max size of array part is 2^MAXBITS
*/
-#if BITS_INT > 26
+#if LUA_BITSINT > 26
#define MAXBITS 24
#else
-#define MAXBITS (BITS_INT-2)
+#define MAXBITS (LUA_BITSINT-2)
#endif
#define MAXASIZE (1 << MAXBITS)
-/* function to convert a lua_Number to int (with any rounding method) */
-#ifndef lua_number2int
-#define lua_number2int(i,n) ((i)=(int)(n))
-#endif
-
#define hashpow2(t,n) (gnode(t, lmod((n), sizenode(t))))
@@ -349,26 +345,6 @@ void luaH_free (lua_State *L, Table *t) {
}
-#if 0
-/*
-** try to remove an element from a hash table; cannot move any element
-** (because gc can call `remove' during a table traversal)
-*/
-void luaH_remove (Table *t, Node *e) {
- Node *mp = luaH_mainposition(t, gkey(e));
- if (e != mp) { /* element not in its main position? */
- while (mp->next != e) mp = mp->next; /* find previous */
- mp->next = e->next; /* remove `e' from its list */
- }
- else {
- if (e->next != NULL) ??
- }
- lua_assert(ttisnil(gval(node)));
- setnilvalue(gkey(e)); /* clear node `e' */
- e->next = NULL;
-}
-#endif
-
/*
** inserts a new key into a hash table; first, check whether key's main
diff --git a/ltablib.c b/ltablib.c
@@ -1,5 +1,5 @@
/*
-** $Id: ltablib.c,v 1.21 2003/04/03 13:35:34 roberto Exp roberto $
+** $Id: ltablib.c,v 1.22 2003/10/07 20:13:41 roberto Exp roberto $
** Library for Table Manipulation
** See Copyright Notice in lua.h
*/
@@ -8,6 +8,7 @@
#include <stddef.h>
#define ltablib_c
+#define LUA_LIB
#include "lua.h"
diff --git a/ltests.c b/ltests.c
@@ -1,5 +1,5 @@
/*
-** $Id: ltests.c,v 2.3 2004/03/15 21:04:54 roberto Exp roberto $
+** $Id: ltests.c,v 2.4 2004/03/23 17:07:53 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 ltests_c
+#define LUA_CORE
#include "lua.h"
@@ -443,7 +444,7 @@ static int listlocals (lua_State *L) {
static int get_limits (lua_State *L) {
lua_createtable(L, 0, 5);
- setnameval(L, "BITS_INT", BITS_INT);
+ setnameval(L, "BITS_INT", LUA_BITSINT);
setnameval(L, "LFPF", LFIELDS_PER_FLUSH);
setnameval(L, "MAXVARS", MAXVARS);
setnameval(L, "MAXSTACK", MAXSTACK);
@@ -961,7 +962,7 @@ static int testC (lua_State *L) {
lua_pop(L, 1);
}
else if EQ("throw") {
-#ifdef _cplusplus
+#ifdef __cplusplus
static struct X { int x; } x;
throw x;
#else
diff --git a/ltests.h b/ltests.h
@@ -1,5 +1,5 @@
/*
-** $Id: ltests.h,v 2.2 2004/02/16 19:09:52 roberto Exp roberto $
+** $Id: ltests.h,v 2.3 2004/03/15 21:04:54 roberto Exp roberto $
** Internal Header for Debugging of the Lua Implementation
** See Copyright Notice in lua.h
*/
@@ -19,6 +19,8 @@
#include <assert.h>
#define lua_assert(c) assert(c)
#define check_exp(c,e) (lua_assert(c), (e))
+#undef api_check
+#define api_check(L, o) lua_assert(o)
/* to avoid warnings, and to make sure value is really unused */
@@ -63,7 +65,9 @@ extern int islocked;
int luaB_opentests (lua_State *L);
-#define LUA_EXTRALIBS { "tests", luaB_opentests },
+#undef LUA_EXTRALIBS
+#define LUA_EXTRALIBS { "tests", luaB_opentests },
+
/* real main will be defined at `ltests.c' */
diff --git a/ltm.c b/ltm.c
@@ -1,5 +1,5 @@
/*
-** $Id: ltm.c,v 2.1 2003/12/10 12:13:36 roberto Exp roberto $
+** $Id: ltm.c,v 2.2 2004/02/16 19:09:52 roberto Exp roberto $
** Tag methods
** See Copyright Notice in lua.h
*/
@@ -8,6 +8,7 @@
#include <string.h>
#define ltm_c
+#define LUA_CORE
#include "lua.h"
diff --git a/lua.c b/lua.c
@@ -1,5 +1,5 @@
/*
-** $Id: lua.c,v 1.123 2003/05/07 16:02:16 roberto Exp roberto $
+** $Id: lua.c,v 1.124 2003/10/23 18:06:22 roberto Exp roberto $
** Lua stand-alone interpreter
** See Copyright Notice in lua.h
*/
@@ -26,39 +26,6 @@
#endif
-/*
-** definition of `isatty'
-*/
-#ifdef _POSIX_C_SOURCE
-#include <unistd.h>
-#define stdin_is_tty() isatty(0)
-#else
-#define stdin_is_tty() 1 /* assume stdin is a tty */
-#endif
-
-
-
-#ifndef PROMPT
-#define PROMPT "> "
-#endif
-
-
-#ifndef PROMPT2
-#define PROMPT2 ">> "
-#endif
-
-#ifndef PROGNAME
-#define PROGNAME "lua"
-#endif
-
-#ifndef lua_userinit
-#define lua_userinit(L) openstdlibs(L)
-#endif
-
-
-#ifndef LUA_EXTRALIBS
-#define LUA_EXTRALIBS /* empty */
-#endif
static lua_State *L = NULL;
@@ -187,14 +154,6 @@ static int load_file (const char *name) {
}
-/*
-** this macro can be used by some `history' system to save lines
-** read in manual input
-*/
-#ifndef lua_saveline
-#define lua_saveline(L,line) /* empty */
-#endif
-
/*
** this macro defines a function to show the prompt and reads the
@@ -291,8 +250,11 @@ static void manual_input (void) {
}
+#define clearinteractive(i) (*i &= 2)
+
static int handle_argv (char *argv[], int *interactive) {
- if (argv[1] == NULL) { /* no more arguments? */
+ if (argv[1] == NULL) { /* no arguments? */
+ *interactive = 0;
if (stdin_is_tty()) {
print_version();
manual_input();
@@ -314,19 +276,22 @@ static int handle_argv (char *argv[], int *interactive) {
goto endloop; /* stop handling arguments */
}
case '\0': {
+ clearinteractive(interactive);
file_input(NULL); /* executes stdin as a file */
break;
}
case 'i': {
- *interactive = 1;
+ *interactive = 2; /* force interactive mode after arguments */
break;
}
case 'v': {
+ clearinteractive(interactive);
print_version();
break;
}
case 'e': {
const char *chunk = argv[i] + 2;
+ clearinteractive(interactive);
if (*chunk == '\0') chunk = argv[++i];
if (chunk == NULL) {
print_usage();
@@ -356,6 +321,7 @@ static int handle_argv (char *argv[], int *interactive) {
break;
}
default: {
+ clearinteractive(interactive);
print_usage();
return 1;
}
@@ -364,6 +330,7 @@ static int handle_argv (char *argv[], int *interactive) {
if (argv[i] != NULL) {
const char *filename = argv[i];
getargs(argv, i); /* collect arguments */
+ clearinteractive(interactive);
lua_setglobal(L, "arg");
return file_input(filename); /* stop scanning arguments */
}
@@ -401,7 +368,7 @@ struct Smain {
static int pmain (lua_State *l) {
struct Smain *s = (struct Smain *)lua_touserdata(l, 1);
int status;
- int interactive = 0;
+ int interactive = 1;
if (s->argv[0] && s->argv[0][0]) progname = s->argv[0];
L = l;
lua_userinit(l); /* open libraries */
diff --git a/lua.h b/lua.h
@@ -1,5 +1,5 @@
/*
-** $Id: lua.h,v 1.187 2004/03/09 17:34:35 roberto Exp roberto $
+** $Id: lua.h,v 1.188 2004/03/24 13:55:46 roberto Exp roberto $
** Lua - An Extensible Extension Language
** Tecgraf: Computer Graphics Technology Group, PUC-Rio, Brazil
** http://www.lua.org mailto:info@lua.org
@@ -14,6 +14,9 @@
#include <stddef.h>
+#include "luaconf.h"
+
+
#define LUA_VERSION "Lua 5.1 (work)"
#define LUA_COPYRIGHT "Copyright (C) 1994-2004 Tecgraf, PUC-Rio"
#define LUA_AUTHORS "R. Ierusalimschy, L. H. de Figueiredo & W. Celes"
@@ -91,26 +94,13 @@ typedef void * (*lua_Alloc) (void *ud, void *ptr, size_t osize, size_t nsize);
/* type of numbers in Lua */
-#ifndef LUA_NUMBER
-typedef double lua_Number;
-#else
typedef LUA_NUMBER lua_Number;
-#endif
/* type for integer functions */
-#ifndef LUA_INTEGER
-typedef long lua_Integer;
-#else
typedef LUA_INTEGER lua_Integer;
-#endif
-/* mark for all API functions */
-#ifndef LUA_API
-#define LUA_API extern
-#endif
-
/*
** state manipulation
@@ -310,22 +300,6 @@ LUA_API lua_Alloc lua_getallocf (lua_State *L, void **ud);
-/*
-** {======================================================================
-** useful definitions for Lua kernel and libraries
-** =======================================================================
-*/
-
-/* formats for Lua numbers */
-#ifndef LUA_NUMBER_SCAN
-#define LUA_NUMBER_SCAN "%lf"
-#endif
-
-#ifndef LUA_NUMBER_FMT
-#define LUA_NUMBER_FMT "%.14g"
-#endif
-
-/* }====================================================================== */
/*
diff --git a/lundump.c b/lundump.c
@@ -1,10 +1,11 @@
/*
-** $Id: lundump.c,v 1.64 2003/08/27 21:01:44 roberto Exp roberto $
+** $Id: lundump.c,v 2.1 2003/12/10 12:13:36 roberto Exp roberto $
** load pre-compiled Lua chunks
** See Copyright Notice in lua.h
*/
#define lundump_c
+#define LUA_CORE
#include "lua.h"
diff --git a/lvm.c b/lvm.c
@@ -1,5 +1,5 @@
/*
-** $Id: lvm.c,v 2.2 2004/03/16 12:31:40 roberto Exp roberto $
+** $Id: lvm.c,v 2.3 2004/03/26 14:02:41 roberto Exp roberto $
** Lua virtual machine
** See Copyright Notice in lua.h
*/
@@ -8,10 +8,8 @@
#include <stdlib.h>
#include <string.h>
-/* needed only when `lua_number2str' uses `sprintf' */
-#include <stdio.h>
-
#define lvm_c
+#define LUA_CORE
#include "lua.h"
@@ -29,12 +27,6 @@
-/* function to convert a lua_Number to a string */
-#ifndef lua_number2str
-#define lua_number2str(s,n) sprintf((s), LUA_NUMBER_FMT, (n))
-#endif
-
-
/* limit for table tag-method chains (to avoid loops) */
#define MAXTAGLOOP 100
diff --git a/lzio.c b/lzio.c
@@ -1,5 +1,5 @@
/*
-** $Id: lzio.c,v 1.27 2003/08/27 20:57:52 roberto Exp roberto $
+** $Id: lzio.c,v 1.28 2003/11/18 10:44:53 roberto Exp roberto $
** a generic input stream interface
** See Copyright Notice in lua.h
*/
@@ -8,6 +8,7 @@
#include <string.h>
#define lzio_c
+#define LUA_CORE
#include "lua.h"
diff --git a/makefile b/makefile
@@ -1,5 +1,5 @@
#
-## $Id: makefile,v 1.41 2003/04/07 20:11:53 roberto Exp roberto $
+## $Id: makefile,v 2.1 2003/12/10 12:13:36 roberto Exp roberto $
## Makefile
## See Copyright Notice in lua.h
#
@@ -10,11 +10,11 @@
# -DEXTERNMEMCHECK -DHARDSTACKTESTS
DEBUG = -g -DLUA_USER_H='"ltests.h"'
OPTIMIZE = -O2 \
- -D'lua_number2int(i,d)=__asm__("fldl %1\nfistpl %0":"=m"(i):"m"(d))' \
# -fomit-frame-pointer
-CONFIG = $(DEBUG) $(OPTIMIZE) -DLUA_COMPATUPSYNTAX -DUSE_TMPNAME -DUSE_DLOPEN
+# -DUSE_TMPNAME??
+CONFIG = $(DEBUG) $(OPTIMIZE) -DLUA_COMPATUPSYNTAX -DUSE_DLOPEN
# Compilation parameters
@@ -103,54 +103,58 @@ clear :
co $(CO_OPTIONS) $@
-lapi.o: lapi.c lua.h lapi.h lobject.h llimits.h ldebug.h lstate.h ltm.h \
- lzio.h lmem.h ldo.h lfunc.h lgc.h lstring.h ltable.h lundump.h lvm.h
-lauxlib.o: lauxlib.c lua.h lauxlib.h
-lbaselib.o: lbaselib.c lua.h lauxlib.h lualib.h
-lcode.o: lcode.c lua.h lcode.h llex.h lobject.h llimits.h lzio.h lmem.h \
- lopcodes.h lparser.h ltable.h ldebug.h lstate.h ltm.h ldo.h lgc.h
-ldblib.o: ldblib.c lua.h lauxlib.h lualib.h
-ldebug.o: ldebug.c lua.h lapi.h lobject.h llimits.h lcode.h llex.h lzio.h \
- lmem.h lopcodes.h lparser.h ltable.h ldebug.h lstate.h ltm.h ldo.h \
- lfunc.h lstring.h lgc.h lvm.h
-ldo.o: ldo.c lua.h ldebug.h lstate.h lobject.h llimits.h ltm.h lzio.h \
- lmem.h ldo.h lfunc.h lgc.h lopcodes.h lparser.h ltable.h lstring.h \
+lapi.o: lapi.c lua.h luaconf.h lapi.h lobject.h llimits.h ldebug.h \
+ lstate.h ltm.h lzio.h lmem.h ldo.h lfunc.h lgc.h lstring.h ltable.h \
lundump.h lvm.h
-ldump.o: ldump.c lua.h lobject.h llimits.h lopcodes.h lstate.h ltm.h \
- lzio.h lmem.h lundump.h
-lfunc.o: lfunc.c lua.h lfunc.h lobject.h llimits.h lgc.h lmem.h lstate.h \
- ltm.h lzio.h
-lgc.o: lgc.c lua.h ldebug.h lstate.h lobject.h llimits.h ltm.h lzio.h \
- lmem.h ldo.h lfunc.h lgc.h lstring.h ltable.h
-liolib.o: liolib.c lua.h lauxlib.h lualib.h
-llex.o: llex.c lua.h ldo.h lobject.h llimits.h lstate.h ltm.h lzio.h \
- lmem.h llex.h lparser.h ltable.h lstring.h lgc.h
-lmathlib.o: lmathlib.c lua.h lauxlib.h lualib.h
-lmem.o: lmem.c lua.h ldebug.h lstate.h lobject.h llimits.h ltm.h lzio.h \
- lmem.h ldo.h
-loadlib.o: loadlib.c lua.h lauxlib.h lualib.h
-lobject.o: lobject.c lua.h ldo.h lobject.h llimits.h lstate.h ltm.h \
- lzio.h lmem.h lstring.h lgc.h lvm.h
-lopcodes.o: lopcodes.c lua.h lobject.h llimits.h lopcodes.h
-lparser.o: lparser.c lua.h lcode.h llex.h lobject.h llimits.h lzio.h \
- lmem.h lopcodes.h lparser.h ltable.h ldebug.h lstate.h ltm.h ldo.h \
- lfunc.h lstring.h lgc.h
-lstate.o: lstate.c lua.h ldebug.h lstate.h lobject.h llimits.h ltm.h \
- lzio.h lmem.h ldo.h lfunc.h lgc.h llex.h lstring.h ltable.h
-lstring.o: lstring.c lua.h lmem.h llimits.h lobject.h lstate.h ltm.h \
- lzio.h lstring.h lgc.h
-lstrlib.o: lstrlib.c lua.h lauxlib.h lualib.h
-ltable.o: ltable.c lua.h ldebug.h lstate.h lobject.h llimits.h ltm.h \
- lzio.h lmem.h ldo.h lgc.h ltable.h
-ltablib.o: ltablib.c lua.h lauxlib.h lualib.h
-ltests.o: ltests.c lua.h lapi.h lobject.h llimits.h lauxlib.h lcode.h \
+lauxlib.o: lauxlib.c lua.h luaconf.h lauxlib.h
+lbaselib.o: lbaselib.c lua.h luaconf.h lauxlib.h lualib.h
+lcode.o: lcode.c lua.h luaconf.h lcode.h llex.h lobject.h llimits.h \
+ lzio.h lmem.h lopcodes.h lparser.h ltable.h ldebug.h lstate.h ltm.h \
+ ldo.h lgc.h
+ldblib.o: ldblib.c lua.h luaconf.h lauxlib.h lualib.h
+ldebug.o: ldebug.c lua.h luaconf.h lapi.h lobject.h llimits.h lcode.h \
llex.h lzio.h lmem.h lopcodes.h lparser.h ltable.h ldebug.h lstate.h \
- ltm.h ldo.h lfunc.h lstring.h lgc.h lualib.h
-ltm.o: ltm.c lua.h lobject.h llimits.h lstate.h ltm.h lzio.h lmem.h \
- lstring.h lgc.h ltable.h
-lua.o: lua.c lua.h lauxlib.h lualib.h
-lundump.o: lundump.c lua.h ldebug.h lstate.h lobject.h llimits.h ltm.h \
- lzio.h lmem.h ldo.h lfunc.h lopcodes.h lstring.h lgc.h lundump.h
-lvm.o: lvm.c lua.h ldebug.h lstate.h lobject.h llimits.h ltm.h lzio.h \
- lmem.h ldo.h lfunc.h lgc.h lopcodes.h lstring.h ltable.h lvm.h
-lzio.o: lzio.c lua.h llimits.h lmem.h lstate.h lobject.h ltm.h lzio.h
+ ltm.h ldo.h lfunc.h lstring.h lgc.h lvm.h
+ldo.o: ldo.c lua.h luaconf.h ldebug.h lstate.h lobject.h llimits.h ltm.h \
+ lzio.h lmem.h ldo.h lfunc.h lgc.h lopcodes.h lparser.h ltable.h \
+ lstring.h lundump.h lvm.h
+ldump.o: ldump.c lua.h luaconf.h lobject.h llimits.h lopcodes.h lstate.h \
+ ltm.h lzio.h lmem.h lundump.h
+lfunc.o: lfunc.c lua.h luaconf.h lfunc.h lobject.h llimits.h lgc.h lmem.h \
+ lstate.h ltm.h lzio.h
+lgc.o: lgc.c lua.h luaconf.h ldebug.h lstate.h lobject.h llimits.h ltm.h \
+ lzio.h lmem.h ldo.h lfunc.h lgc.h lstring.h ltable.h
+liolib.o: liolib.c lua.h luaconf.h lauxlib.h lualib.h
+llex.o: llex.c lua.h luaconf.h ldo.h lobject.h llimits.h lstate.h ltm.h \
+ lzio.h lmem.h llex.h lparser.h ltable.h lstring.h lgc.h
+lmathlib.o: lmathlib.c lua.h luaconf.h lauxlib.h lualib.h
+lmem.o: lmem.c lua.h luaconf.h ldebug.h lstate.h lobject.h llimits.h \
+ ltm.h lzio.h lmem.h ldo.h
+loadlib.o: loadlib.c lua.h luaconf.h lauxlib.h lualib.h
+lobject.o: lobject.c lua.h luaconf.h ldo.h lobject.h llimits.h lstate.h \
+ ltm.h lzio.h lmem.h lstring.h lgc.h lvm.h
+lopcodes.o: lopcodes.c lua.h luaconf.h lobject.h llimits.h lopcodes.h
+lparser.o: lparser.c lua.h luaconf.h lcode.h llex.h lobject.h llimits.h \
+ lzio.h lmem.h lopcodes.h lparser.h ltable.h ldebug.h lstate.h ltm.h \
+ ldo.h lfunc.h lstring.h lgc.h
+lstate.o: lstate.c lua.h luaconf.h ldebug.h lstate.h lobject.h llimits.h \
+ ltm.h lzio.h lmem.h ldo.h lfunc.h lgc.h llex.h lstring.h ltable.h
+lstring.o: lstring.c lua.h luaconf.h lmem.h llimits.h lobject.h lstate.h \
+ ltm.h lzio.h lstring.h lgc.h
+lstrlib.o: lstrlib.c lua.h luaconf.h lauxlib.h lualib.h
+ltable.o: ltable.c lua.h luaconf.h ldebug.h lstate.h lobject.h llimits.h \
+ ltm.h lzio.h lmem.h ldo.h lgc.h ltable.h
+ltablib.o: ltablib.c lua.h luaconf.h lauxlib.h lualib.h
+ltests.o: ltests.c lua.h luaconf.h lapi.h lobject.h llimits.h lauxlib.h \
+ lcode.h llex.h lzio.h lmem.h lopcodes.h lparser.h ltable.h ldebug.h \
+ lstate.h ltm.h ldo.h lfunc.h lstring.h lgc.h lualib.h
+ltm.o: ltm.c lua.h luaconf.h lobject.h llimits.h lstate.h ltm.h lzio.h \
+ lmem.h lstring.h lgc.h ltable.h
+lua.o: lua.c lua.h luaconf.h lauxlib.h lualib.h
+lundump.o: lundump.c lua.h luaconf.h ldebug.h lstate.h lobject.h \
+ llimits.h ltm.h lzio.h lmem.h ldo.h lfunc.h lopcodes.h lstring.h lgc.h \
+ lundump.h
+lvm.o: lvm.c lua.h luaconf.h ldebug.h lstate.h lobject.h llimits.h ltm.h \
+ lzio.h lmem.h ldo.h lfunc.h lgc.h lopcodes.h lstring.h ltable.h lvm.h
+lzio.o: lzio.c lua.h luaconf.h llimits.h lmem.h lstate.h lobject.h ltm.h \
+ lzio.h