summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lapi.c14
-rw-r--r--lauxlib.c7
-rw-r--r--lbaselib.c63
-rw-r--r--lcode.c3
-rw-r--r--ldblib.c3
-rw-r--r--ldebug.c3
-rw-r--r--ldo.c22
-rw-r--r--ldump.c3
-rw-r--r--lfunc.c3
-rw-r--r--lgc.c3
-rw-r--r--liolib.c28
-rw-r--r--llex.c3
-rw-r--r--llimits.h92
-rw-r--r--lmathlib.c3
-rw-r--r--lmem.c3
-rw-r--r--loadlib.c5
-rw-r--r--lobject.c8
-rw-r--r--lopcodes.c3
-rw-r--r--lopcodes.h6
-rw-r--r--lparser.c9
-rw-r--r--lstate.c3
-rw-r--r--lstring.c3
-rw-r--r--lstrlib.c9
-rw-r--r--ltable.c32
-rw-r--r--ltablib.c3
-rw-r--r--ltests.c7
-rw-r--r--ltests.h8
-rw-r--r--ltm.c3
-rw-r--r--lua.c57
-rw-r--r--lua.h34
-rw-r--r--lundump.c3
-rw-r--r--lvm.c12
-rw-r--r--lzio.c3
-rw-r--r--makefile108
34 files changed, 175 insertions, 394 deletions
diff --git a/lapi.c b/lapi.c
index 37e9ce6b..4078bf02 100644
--- a/lapi.c
+++ b/lapi.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lapi.c,v 2.5 2004/03/23 17:07:34 roberto Exp roberto $ 2** $Id: lapi.c,v 2.6 2004/04/05 14:43:17 roberto Exp roberto $
3** Lua API 3** Lua API
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -10,6 +10,7 @@
10#include <string.h> 10#include <string.h>
11 11
12#define lapi_c 12#define lapi_c
13#define LUA_CORE
13 14
14#include "lua.h" 15#include "lua.h"
15 16
@@ -28,11 +29,6 @@
28#include "lvm.h" 29#include "lvm.h"
29 30
30 31
31/* function to convert a lua_Number to lua_Integer (with any rounding method) */
32#ifndef lua_number2integer
33#define lua_number2integer(i,n) ((i)=(lua_Integer)(n))
34#endif
35
36 32
37const char lua_ident[] = 33const char lua_ident[] =
38 "$Lua: " LUA_VERSION " " LUA_COPYRIGHT " $\n" 34 "$Lua: " LUA_VERSION " " LUA_COPYRIGHT " $\n"
@@ -41,10 +37,6 @@ const char lua_ident[] =
41 37
42 38
43 39
44#ifndef api_check
45#define api_check(L, o) lua_assert(o)
46#endif
47
48#define api_checknelems(L, n) api_check(L, (n) <= (L->top - L->base)) 40#define api_checknelems(L, n) api_check(L, (n) <= (L->top - L->base))
49 41
50#define api_checkvalidindex(L, i) api_check(L, (i) != &luaO_nilobject) 42#define api_checkvalidindex(L, i) api_check(L, (i) != &luaO_nilobject)
@@ -87,7 +79,7 @@ void luaA_pushobject (lua_State *L, const TValue *o) {
87LUA_API int lua_checkstack (lua_State *L, int size) { 79LUA_API int lua_checkstack (lua_State *L, int size) {
88 int res; 80 int res;
89 lua_lock(L); 81 lua_lock(L);
90 if ((L->top - L->base + size) > LUA_MAXCSTACK) 82 if ((L->top - L->base + size) > MAXCSTACK)
91 res = 0; /* stack overflow */ 83 res = 0; /* stack overflow */
92 else { 84 else {
93 luaD_checkstack(L, size); 85 luaD_checkstack(L, size);
diff --git a/lauxlib.c b/lauxlib.c
index e80fa157..9a8fe02b 100644
--- a/lauxlib.c
+++ b/lauxlib.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lauxlib.c,v 1.109 2004/02/18 13:40:03 roberto Exp roberto $ 2** $Id: lauxlib.c,v 1.110 2004/03/23 16:38:43 roberto Exp roberto $
3** Auxiliary functions for building Lua libraries 3** Auxiliary functions for building Lua libraries
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -18,6 +18,7 @@
18*/ 18*/
19 19
20#define lauxlib_c 20#define lauxlib_c
21#define LUA_LIB
21 22
22#include "lua.h" 23#include "lua.h"
23 24
@@ -288,7 +289,7 @@ static void getsizes (lua_State *L) {
288} 289}
289 290
290 291
291void luaL_setn (lua_State *L, int t, int n) { 292LUALIB_API void luaL_setn (lua_State *L, int t, int n) {
292 t = abs_index(L, t); 293 t = abs_index(L, t);
293 getsizes(L); 294 getsizes(L);
294 lua_pushvalue(L, t); 295 lua_pushvalue(L, t);
@@ -298,7 +299,7 @@ void luaL_setn (lua_State *L, int t, int n) {
298} 299}
299 300
300 301
301int luaL_getn (lua_State *L, int t) { 302LUALIB_API int luaL_getn (lua_State *L, int t) {
302 int n; 303 int n;
303 t = abs_index(L, t); 304 t = abs_index(L, t);
304 getsizes(L); /* try sizes[t] */ 305 getsizes(L); /* try sizes[t] */
diff --git a/lbaselib.c b/lbaselib.c
index 563d3136..06c38da8 100644
--- a/lbaselib.c
+++ b/lbaselib.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lbaselib.c,v 1.140 2004/03/09 17:34:35 roberto Exp roberto $ 2** $Id: lbaselib.c,v 1.141 2004/03/26 13:25:17 roberto Exp roberto $
3** Basic library 3** Basic library
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -12,6 +12,7 @@
12#include <string.h> 12#include <string.h>
13 13
14#define lbaselib_c 14#define lbaselib_c
15#define LUA_LIB
15 16
16#include "lua.h" 17#include "lua.h"
17 18
@@ -235,28 +236,29 @@ static int luaB_next (lua_State *L) {
235 236
236static int luaB_pairs (lua_State *L) { 237static int luaB_pairs (lua_State *L) {
237 luaL_checktype(L, 1, LUA_TTABLE); 238 luaL_checktype(L, 1, LUA_TTABLE);
238 lua_getglobal(L, "next"); /* return generator, */ 239 lua_pushvalue(L, lua_upvalueindex(1)); /* return generator, */
239 lua_pushvalue(L, 1); /* state, */ 240 lua_pushvalue(L, 1); /* state, */
240 lua_pushnil(L); /* and initial value */ 241 lua_pushnil(L); /* and initial value */
241 return 3; 242 return 3;
242} 243}
243 244
244 245
246static int ipairsaux (lua_State *L) {
247 int i = luaL_checkint(L, 2);
248 luaL_checktype(L, 1, LUA_TTABLE);
249 i++; /* next value */
250 lua_pushinteger(L, i);
251 lua_rawgeti(L, 1, i);
252 return (lua_isnil(L, -1)) ? 0 : 2;
253}
254
255
245static int luaB_ipairs (lua_State *L) { 256static int luaB_ipairs (lua_State *L) {
246 int i = (int)lua_tointeger(L, 2);
247 luaL_checktype(L, 1, LUA_TTABLE); 257 luaL_checktype(L, 1, LUA_TTABLE);
248 if (i == 0 && lua_isnone(L, 2)) { /* `for' start? */ 258 lua_pushvalue(L, lua_upvalueindex(1)); /* return generator, */
249 lua_getglobal(L, "ipairs"); /* return generator, */ 259 lua_pushvalue(L, 1); /* state, */
250 lua_pushvalue(L, 1); /* state, */ 260 lua_pushinteger(L, 0); /* and initial value */
251 lua_pushinteger(L, 0); /* and initial value */ 261 return 3;
252 return 3;
253 }
254 else { /* `for' step */
255 i++; /* next value */
256 lua_pushinteger(L, i);
257 lua_rawgeti(L, 1, i);
258 return (lua_isnil(L, -1)) ? 0 : 2;
259 }
260} 262}
261 263
262 264
@@ -458,25 +460,6 @@ static int luaB_newproxy (lua_State *L) {
458*/ 460*/
459 461
460 462
461/* name of global that holds table with loaded packages */
462#define REQTAB "_LOADED"
463
464/* name of global that holds the search path for packages */
465#define LUA_PATH "LUA_PATH"
466
467#ifndef LUA_PATH_SEP
468#define LUA_PATH_SEP ';'
469#endif
470
471#ifndef LUA_PATH_MARK
472#define LUA_PATH_MARK '?'
473#endif
474
475#ifndef LUA_PATH_DEFAULT
476#define LUA_PATH_DEFAULT "?;?.lua"
477#endif
478
479
480static const char *getpath (lua_State *L) { 463static const char *getpath (lua_State *L) {
481 const char *path; 464 const char *path;
482 lua_getglobal(L, LUA_PATH); /* try global variable */ 465 lua_getglobal(L, LUA_PATH); /* try global variable */
@@ -576,8 +559,6 @@ static const luaL_reg base_funcs[] = {
576 {"getfenv", luaB_getfenv}, 559 {"getfenv", luaB_getfenv},
577 {"setfenv", luaB_setfenv}, 560 {"setfenv", luaB_setfenv},
578 {"next", luaB_next}, 561 {"next", luaB_next},
579 {"ipairs", luaB_ipairs},
580 {"pairs", luaB_pairs},
581 {"print", luaB_print}, 562 {"print", luaB_print},
582 {"tonumber", luaB_tonumber}, 563 {"tonumber", luaB_tonumber},
583 {"tostring", luaB_tostring}, 564 {"tostring", luaB_tostring},
@@ -708,12 +689,22 @@ static const luaL_reg co_funcs[] = {
708/* }====================================================== */ 689/* }====================================================== */
709 690
710 691
692static void auxopen (lua_State *L, const char *name,
693 lua_CFunction f, lua_CFunction u) {
694 lua_pushcfunction(L, u);
695 lua_pushcclosure(L, f, 1);
696 lua_setfield(L, -2, name);
697}
698
711 699
712static void base_open (lua_State *L) { 700static void base_open (lua_State *L) {
713 lua_pushvalue(L, LUA_GLOBALSINDEX); 701 lua_pushvalue(L, LUA_GLOBALSINDEX);
714 luaL_openlib(L, NULL, base_funcs, 0); /* open lib into global table */ 702 luaL_openlib(L, NULL, base_funcs, 0); /* open lib into global table */
715 lua_pushliteral(L, LUA_VERSION); 703 lua_pushliteral(L, LUA_VERSION);
716 lua_setfield(L, -2, "_VERSION"); /* set global _VERSION */ 704 lua_setfield(L, -2, "_VERSION"); /* set global _VERSION */
705 /* `ipairs' and `pairs' need auxiliary functions as upvalues */
706 auxopen(L, "ipairs", luaB_ipairs, ipairsaux);
707 auxopen(L, "pairs", luaB_pairs, luaB_next);
717 /* `newproxy' needs a weaktable as upvalue */ 708 /* `newproxy' needs a weaktable as upvalue */
718 lua_newtable(L); /* new table `w' */ 709 lua_newtable(L); /* new table `w' */
719 lua_pushvalue(L, -1); /* `w' will be its own metatable */ 710 lua_pushvalue(L, -1); /* `w' will be its own metatable */
diff --git a/lcode.c b/lcode.c
index 63f48292..e9bcb5f1 100644
--- a/lcode.c
+++ b/lcode.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lcode.c,v 1.121 2003/12/09 16:56:11 roberto Exp roberto $ 2** $Id: lcode.c,v 2.1 2003/12/10 12:13:36 roberto Exp roberto $
3** Code generator for Lua 3** Code generator for Lua
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -8,6 +8,7 @@
8#include <stdlib.h> 8#include <stdlib.h>
9 9
10#define lcode_c 10#define lcode_c
11#define LUA_CORE
11 12
12#include "lua.h" 13#include "lua.h"
13 14
diff --git a/ldblib.c b/ldblib.c
index fb2ebd6d..2e121aa9 100644
--- a/ldblib.c
+++ b/ldblib.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ldblib.c,v 1.83 2003/10/10 12:57:55 roberto Exp roberto $ 2** $Id: ldblib.c,v 1.84 2003/11/05 11:59:14 roberto Exp roberto $
3** Interface from Lua to its debug API 3** Interface from Lua to its debug API
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -10,6 +10,7 @@
10#include <string.h> 10#include <string.h>
11 11
12#define ldblib_c 12#define ldblib_c
13#define LUA_LIB
13 14
14#include "lua.h" 15#include "lua.h"
15 16
diff --git a/ldebug.c b/ldebug.c
index e693f105..3a1509f0 100644
--- a/ldebug.c
+++ b/ldebug.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ldebug.c,v 2.2 2004/02/20 16:01:05 roberto Exp roberto $ 2** $Id: ldebug.c,v 2.3 2004/03/23 13:10:16 roberto Exp roberto $
3** Debug Interface 3** Debug Interface
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -11,6 +11,7 @@
11 11
12 12
13#define ldebug_c 13#define ldebug_c
14#define LUA_CORE
14 15
15#include "lua.h" 16#include "lua.h"
16 17
diff --git a/ldo.c b/ldo.c
index e0474a10..e13eec5a 100644
--- a/ldo.c
+++ b/ldo.c
@@ -1,15 +1,15 @@
1/* 1/*
2** $Id: ldo.c,v 2.1 2003/12/10 12:13:36 roberto Exp roberto $ 2** $Id: ldo.c,v 2.2 2004/03/23 17:02:58 roberto Exp roberto $
3** Stack and Call structure of Lua 3** Stack and Call structure of Lua
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
6 6
7 7
8#include <setjmp.h>
9#include <stdlib.h> 8#include <stdlib.h>
10#include <string.h> 9#include <string.h>
11 10
12#define ldo_c 11#define ldo_c
12#define LUA_CORE
13 13
14#include "lua.h" 14#include "lua.h"
15 15
@@ -34,29 +34,15 @@
34 34
35/* 35/*
36** {====================================================== 36** {======================================================
37** Error-recovery functions (based on long jumps) 37** Error-recovery functions
38** ======================================================= 38** =======================================================
39*/ 39*/
40 40
41 41
42#ifndef LUA_USEEXCEPTIONS
43
44#define L_THROW(c) longjmp((c)->b, 1)
45#define L_TRY(c,a) if (setjmp((c)->b) == 0) { a }
46
47#else
48
49#define L_THROW(c) throw(c)
50#define L_TRY(c,a) try { a } catch(...) \
51 { if ((c)->status == 0) (c)->status = -1; }
52
53#endif
54
55
56/* chain list of long jump buffers */ 42/* chain list of long jump buffers */
57struct lua_longjmp { 43struct lua_longjmp {
58 struct lua_longjmp *previous; 44 struct lua_longjmp *previous;
59 jmp_buf b; 45 l_jmpbuf b;
60 volatile int status; /* error code */ 46 volatile int status; /* error code */
61}; 47};
62 48
diff --git a/ldump.c b/ldump.c
index 24367891..d41082bd 100644
--- a/ldump.c
+++ b/ldump.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ldump.c,v 1.6 2003/08/15 13:48:53 roberto Exp roberto $ 2** $Id: ldump.c,v 2.1 2003/12/10 12:13:36 roberto Exp roberto $
3** save bytecodes 3** save bytecodes
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -7,6 +7,7 @@
7#include <stddef.h> 7#include <stddef.h>
8 8
9#define ldump_c 9#define ldump_c
10#define LUA_CORE
10 11
11#include "lua.h" 12#include "lua.h"
12 13
diff --git a/lfunc.c b/lfunc.c
index 04dfca60..c088cfa0 100644
--- a/lfunc.c
+++ b/lfunc.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lfunc.c,v 2.2 2004/02/16 19:09:52 roberto Exp roberto $ 2** $Id: lfunc.c,v 2.3 2004/03/15 21:04:33 roberto Exp roberto $
3** Auxiliary functions to manipulate prototypes and closures 3** Auxiliary functions to manipulate prototypes and closures
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -8,6 +8,7 @@
8#include <stddef.h> 8#include <stddef.h>
9 9
10#define lfunc_c 10#define lfunc_c
11#define LUA_CORE
11 12
12#include "lua.h" 13#include "lua.h"
13 14
diff --git a/lgc.c b/lgc.c
index cd8bf720..636fd59a 100644
--- a/lgc.c
+++ b/lgc.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lgc.c,v 2.5 2004/03/15 21:04:33 roberto Exp roberto $ 2** $Id: lgc.c,v 2.6 2004/03/23 12:57:12 roberto Exp roberto $
3** Garbage Collector 3** Garbage Collector
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -7,6 +7,7 @@
7#include <string.h> 7#include <string.h>
8 8
9#define lgc_c 9#define lgc_c
10#define LUA_CORE
10 11
11#include "lua.h" 12#include "lua.h"
12 13
diff --git a/liolib.c b/liolib.c
index a2e22c4d..11ddf8f4 100644
--- a/liolib.c
+++ b/liolib.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: liolib.c,v 2.48 2003/10/10 12:57:55 roberto Exp roberto $ 2** $Id: liolib.c,v 2.49 2003/10/10 13:29:28 roberto Exp roberto $
3** Standard I/O (and system) library 3** Standard I/O (and system) library
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -13,6 +13,7 @@
13#include <time.h> 13#include <time.h>
14 14
15#define liolib_c 15#define liolib_c
16#define LUA_LIB
16 17
17#include "lua.h" 18#include "lua.h"
18 19
@@ -21,31 +22,6 @@
21 22
22 23
23 24
24/*
25** by default, gcc does not get `tmpname'
26*/
27#ifndef USE_TMPNAME
28#ifdef __GNUC__
29#define USE_TMPNAME 0
30#else
31#define USE_TMPNAME 1
32#endif
33#endif
34
35
36/*
37** by default, posix systems get `popen'
38*/
39#ifndef USE_POPEN
40#if defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 2
41#define USE_POPEN 1
42#else
43#define USE_POPEN 0
44#endif
45#endif
46
47
48
49 25
50/* 26/*
51** {====================================================== 27** {======================================================
diff --git a/llex.c b/llex.c
index 1d26858c..61490f9b 100644
--- a/llex.c
+++ b/llex.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: llex.c,v 2.1 2003/12/10 12:13:36 roberto Exp roberto $ 2** $Id: llex.c,v 2.2 2004/03/12 19:53:56 roberto Exp roberto $
3** Lexical Analyzer 3** Lexical Analyzer
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -9,6 +9,7 @@
9#include <string.h> 9#include <string.h>
10 10
11#define llex_c 11#define llex_c
12#define LUA_CORE
12 13
13#include "lua.h" 14#include "lua.h"
14 15
diff --git a/llimits.h b/llimits.h
index 7c634f67..50a44651 100644
--- a/llimits.h
+++ b/llimits.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: llimits.h,v 1.56 2003/07/29 19:26:34 roberto Exp roberto $ 2** $Id: llimits.h,v 1.57 2003/12/01 16:33:30 roberto Exp roberto $
3** Limits, basic types, and some other `installation-dependent' definitions 3** Limits, basic types, and some other `installation-dependent' definitions
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -15,48 +15,9 @@
15#include "lua.h" 15#include "lua.h"
16 16
17 17
18/*
19** try to find number of bits in an integer
20*/
21#ifndef BITS_INT
22/* avoid overflows in comparison */
23#if INT_MAX-20 < 32760
24#define BITS_INT 16
25#elif INT_MAX > 2147483640L
26/* machine has at least 32 bits */
27#define BITS_INT 32
28#else
29#error "you must define BITS_INT with number of bits in an integer"
30#endif
31#endif
32
33
34/*
35** the following types define integer types for values that may not
36** fit in a `small int' (16 bits), but may waste space in a
37** `large long' (64 bits). The current definitions should work in
38** any machine, but may not be optimal.
39*/
40
41
42/*
43** an unsigned integer with at least 32 bits
44*/
45#ifndef LUA_UINT32
46#define LUA_UINT32 unsigned long
47#endif
48 18
49typedef LUA_UINT32 lu_int32; 19typedef LUA_UINT32 lu_int32;
50 20
51
52/*
53** a signed integer with at least 32 bits
54*/
55#ifndef LUA_INT32
56#define LUA_INT32 long
57#define LUA_MAXINT32 LONG_MAX
58#endif
59
60typedef LUA_INT32 l_int32; 21typedef LUA_INT32 l_int32;
61 22
62 23
@@ -95,19 +56,11 @@ typedef unsigned char lu_byte;
95 56
96 57
97/* type to ensure maximum alignment */ 58/* type to ensure maximum alignment */
98#ifndef LUSER_ALIGNMENT_T
99typedef union { double u; void *s; long l; } L_Umaxalign;
100#else
101typedef LUSER_ALIGNMENT_T L_Umaxalign; 59typedef LUSER_ALIGNMENT_T L_Umaxalign;
102#endif
103 60
104 61
105/* result of `usual argument conversion' over lua_Number */ 62/* result of a `usual argument conversion' over lua_Number */
106#ifndef LUA_UACNUMBER
107typedef double l_uacNumber;
108#else
109typedef LUA_UACNUMBER l_uacNumber; 63typedef LUA_UACNUMBER l_uacNumber;
110#endif
111 64
112 65
113#ifndef lua_assert 66#ifndef lua_assert
@@ -138,43 +91,11 @@ typedef LUA_UACNUMBER l_uacNumber;
138typedef lu_int32 Instruction; 91typedef lu_int32 Instruction;
139 92
140 93
141/* maximum depth for calls (unsigned short) */
142#ifndef LUA_MAXCALLS
143#define LUA_MAXCALLS 4096
144#endif
145
146
147/*
148** maximum depth for C calls (unsigned short): Not too big, or may
149** overflow the C stack...
150*/
151
152#ifndef LUA_MAXCCALLS
153#define LUA_MAXCCALLS 200
154#endif
155
156
157/* maximum size for the virtual stack of a C function */
158#ifndef LUA_MAXCSTACK
159#define LUA_MAXCSTACK 2048
160#endif
161
162 94
163/* maximum stack for a Lua function */ 95/* maximum stack for a Lua function */
164#define MAXSTACK 250 96#define MAXSTACK 250
165 97
166 98
167/* maximum number of variables declared in a function */
168#ifndef MAXVARS
169#define MAXVARS 200 /* <MAXSTACK */
170#endif
171
172
173/* maximum number of upvalues per function */
174#ifndef MAXUPVALUES
175#define MAXUPVALUES 32 /* <MAXSTACK */
176#endif
177
178 99
179/* minimum size for the string table (must be power of 2) */ 100/* minimum size for the string table (must be power of 2) */
180#ifndef MINSTRTABSIZE 101#ifndef MINSTRTABSIZE
@@ -188,13 +109,4 @@ typedef lu_int32 Instruction;
188#endif 109#endif
189 110
190 111
191/*
192** maximum number of syntactical nested non-terminals: Not too big,
193** or may overflow the C stack...
194*/
195#ifndef LUA_MAXPARSERLEVEL
196#define LUA_MAXPARSERLEVEL 200
197#endif
198
199
200#endif 112#endif
diff --git a/lmathlib.c b/lmathlib.c
index 5c060218..76809b53 100644
--- a/lmathlib.c
+++ b/lmathlib.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lmathlib.c,v 1.58 2003/10/10 12:57:55 roberto Exp roberto $ 2** $Id: lmathlib.c,v 1.59 2003/11/05 11:59:14 roberto Exp roberto $
3** Standard mathematical library 3** Standard mathematical library
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -9,6 +9,7 @@
9#include <math.h> 9#include <math.h>
10 10
11#define lmathlib_c 11#define lmathlib_c
12#define LUA_LIB
12 13
13#include "lua.h" 14#include "lua.h"
14 15
diff --git a/lmem.c b/lmem.c
index cd0766a6..538951f9 100644
--- a/lmem.c
+++ b/lmem.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lmem.c,v 1.62 2003/10/02 20:31:17 roberto Exp roberto $ 2** $Id: lmem.c,v 1.63 2003/11/27 18:18:37 roberto Exp roberto $
3** Interface to Memory Manager 3** Interface to Memory Manager
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -8,6 +8,7 @@
8#include <stddef.h> 8#include <stddef.h>
9 9
10#define lmem_c 10#define lmem_c
11#define LUA_CORE
11 12
12#include "lua.h" 13#include "lua.h"
13 14
diff --git a/loadlib.c b/loadlib.c
index 961eeab5..095b4eaf 100644
--- a/loadlib.c
+++ b/loadlib.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: loadlib.c,v 1.4 2003/04/07 20:11:53 roberto Exp roberto $ 2** $Id: loadlib.c,v 1.5 2003/05/14 21:01:53 roberto Exp roberto $
3** Dynamic library loader for Lua 3** Dynamic library loader for Lua
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5* 5*
@@ -26,6 +26,9 @@
26* 26*
27*/ 27*/
28 28
29#define loadlib_c
30#define LUA_LIB
31
29#include "lua.h" 32#include "lua.h"
30#include "lauxlib.h" 33#include "lauxlib.h"
31#include "lualib.h" 34#include "lualib.h"
diff --git a/lobject.c b/lobject.c
index cce60d92..27e9b03a 100644
--- a/lobject.c
+++ b/lobject.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lobject.c,v 1.99 2003/06/10 12:36:26 roberto Exp roberto $ 2** $Id: lobject.c,v 2.1 2003/12/10 12:13:36 roberto Exp roberto $
3** Some generic functions over Lua objects 3** Some generic functions over Lua objects
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -10,6 +10,7 @@
10#include <string.h> 10#include <string.h>
11 11
12#define lobject_c 12#define lobject_c
13#define LUA_CORE
13 14
14#include "lua.h" 15#include "lua.h"
15 16
@@ -21,11 +22,6 @@
21#include "lvm.h" 22#include "lvm.h"
22 23
23 24
24/* function to convert a string to a lua_Number */
25#ifndef lua_str2number
26#define lua_str2number(s,p) strtod((s), (p))
27#endif
28
29 25
30const TValue luaO_nilobject = {LUA_TNIL, {NULL}}; 26const TValue luaO_nilobject = {LUA_TNIL, {NULL}};
31 27
diff --git a/lopcodes.c b/lopcodes.c
index ad903c10..d84f402e 100644
--- a/lopcodes.c
+++ b/lopcodes.c
@@ -1,10 +1,11 @@
1/* 1/*
2** $Id: lopcodes.c,v 1.24 2003/05/14 12:09:12 roberto Exp roberto $ 2** $Id: lopcodes.c,v 1.25 2003/05/14 21:09:53 roberto Exp roberto $
3** See Copyright Notice in lua.h 3** See Copyright Notice in lua.h
4*/ 4*/
5 5
6 6
7#define lopcodes_c 7#define lopcodes_c
8#define LUA_CORE
8 9
9#include "lua.h" 10#include "lua.h"
10 11
diff --git a/lopcodes.h b/lopcodes.h
index 8d90b475..ca848835 100644
--- a/lopcodes.h
+++ b/lopcodes.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lopcodes.h,v 1.105 2003/05/14 21:09:53 roberto Exp roberto $ 2** $Id: lopcodes.h,v 1.106 2003/05/15 19:46:03 roberto Exp roberto $
3** Opcodes for Lua virtual machine 3** Opcodes for Lua virtual machine
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -50,9 +50,9 @@ enum OpMode {iABC, iABx, iAsBx}; /* basic instruction format */
50/* 50/*
51** limits for opcode arguments. 51** limits for opcode arguments.
52** we use (signed) int to manipulate most arguments, 52** we use (signed) int to manipulate most arguments,
53** so they must fit in BITS_INT-1 bits (-1 for sign) 53** so they must fit in LUA_BITSINT-1 bits (-1 for sign)
54*/ 54*/
55#if SIZE_Bx < BITS_INT-1 55#if SIZE_Bx < LUA_BITSINT-1
56#define MAXARG_Bx ((1<<SIZE_Bx)-1) 56#define MAXARG_Bx ((1<<SIZE_Bx)-1)
57#define MAXARG_sBx (MAXARG_Bx>>1) /* `sBx' is signed */ 57#define MAXARG_sBx (MAXARG_Bx>>1) /* `sBx' is signed */
58#else 58#else
diff --git a/lparser.c b/lparser.c
index b8e1b2a7..d9f6cbd4 100644
--- a/lparser.c
+++ b/lparser.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lparser.c,v 2.2 2004/03/12 19:53:56 roberto Exp roberto $ 2** $Id: lparser.c,v 2.3 2004/03/26 14:02:41 roberto Exp roberto $
3** Lua Parser 3** Lua Parser
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -8,6 +8,7 @@
8#include <string.h> 8#include <string.h>
9 9
10#define lparser_c 10#define lparser_c
11#define LUA_CORE
11 12
12#include "lua.h" 13#include "lua.h"
13 14
@@ -977,12 +978,6 @@ static int cond (LexState *ls) {
977** after its body (and thus avoiding one jump in the loop). 978** after its body (and thus avoiding one jump in the loop).
978*/ 979*/
979 980
980/*
981** maximum size of expressions for optimizing `while' code
982*/
983#ifndef MAXEXPWHILE
984#define MAXEXPWHILE 100
985#endif
986 981
987/* 982/*
988** the call `luaK_goiffalse' may grow the size of an expression by 983** the call `luaK_goiffalse' may grow the size of an expression by
diff --git a/lstate.c b/lstate.c
index a65c9d85..4ee1c743 100644
--- a/lstate.c
+++ b/lstate.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lstate.c,v 2.4 2004/03/15 21:04:33 roberto Exp roberto $ 2** $Id: lstate.c,v 2.5 2004/03/23 12:57:12 roberto Exp roberto $
3** Global State 3** Global State
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -8,6 +8,7 @@
8#include <stddef.h> 8#include <stddef.h>
9 9
10#define lstate_c 10#define lstate_c
11#define LUA_CORE
11 12
12#include "lua.h" 13#include "lua.h"
13 14
diff --git a/lstring.c b/lstring.c
index 8de7d2b3..8ecfb44e 100644
--- a/lstring.c
+++ b/lstring.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lstring.c,v 1.85 2003/12/09 16:56:11 roberto Exp roberto $ 2** $Id: lstring.c,v 2.1 2003/12/10 12:13:36 roberto Exp roberto $
3** String table (keeps all strings handled by Lua) 3** String table (keeps all strings handled by Lua)
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -8,6 +8,7 @@
8#include <string.h> 8#include <string.h>
9 9
10#define lstring_c 10#define lstring_c
11#define LUA_CORE
11 12
12#include "lua.h" 13#include "lua.h"
13 14
diff --git a/lstrlib.c b/lstrlib.c
index 5a3c8ea4..815b530c 100644
--- a/lstrlib.c
+++ b/lstrlib.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lstrlib.c,v 1.100 2003/10/07 20:13:41 roberto Exp roberto $ 2** $Id: lstrlib.c,v 1.101 2004/01/02 11:54:14 roberto Exp roberto $
3** Standard library for string operations and pattern-matching 3** Standard library for string operations and pattern-matching
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -12,6 +12,7 @@
12#include <string.h> 12#include <string.h>
13 13
14#define lstrlib_c 14#define lstrlib_c
15#define LUA_LIB
15 16
16#include "lua.h" 17#include "lua.h"
17 18
@@ -20,9 +21,7 @@
20 21
21 22
22/* macro to `unsign' a character */ 23/* macro to `unsign' a character */
23#ifndef uchar
24#define uchar(c) ((unsigned char)(c)) 24#define uchar(c) ((unsigned char)(c))
25#endif
26 25
27 26
28typedef lua_Integer sint32; /* a signed version for size_t */ 27typedef lua_Integer sint32; /* a signed version for size_t */
@@ -156,10 +155,6 @@ static int str_dump (lua_State *L) {
156** ======================================================= 155** =======================================================
157*/ 156*/
158 157
159#ifndef MAX_CAPTURES
160#define MAX_CAPTURES 32 /* arbitrary limit */
161#endif
162
163 158
164#define CAP_UNFINISHED (-1) 159#define CAP_UNFINISHED (-1)
165#define CAP_POSITION (-2) 160#define CAP_POSITION (-2)
diff --git a/ltable.c b/ltable.c
index fff4716d..0d149e9f 100644
--- a/ltable.c
+++ b/ltable.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ltable.c,v 2.1 2003/12/10 12:13:36 roberto Exp roberto $ 2** $Id: ltable.c,v 2.2 2004/03/26 14:02:41 roberto Exp roberto $
3** Lua tables (hash) 3** Lua tables (hash)
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -21,6 +21,7 @@
21#include <string.h> 21#include <string.h>
22 22
23#define ltable_c 23#define ltable_c
24#define LUA_CORE
24 25
25#include "lua.h" 26#include "lua.h"
26 27
@@ -36,19 +37,14 @@
36/* 37/*
37** max size of array part is 2^MAXBITS 38** max size of array part is 2^MAXBITS
38*/ 39*/
39#if BITS_INT > 26 40#if LUA_BITSINT > 26
40#define MAXBITS 24 41#define MAXBITS 24
41#else 42#else
42#define MAXBITS (BITS_INT-2) 43#define MAXBITS (LUA_BITSINT-2)
43#endif 44#endif
44 45
45#define MAXASIZE (1 << MAXBITS) 46#define MAXASIZE (1 << MAXBITS)
46 47
47/* function to convert a lua_Number to int (with any rounding method) */
48#ifndef lua_number2int
49#define lua_number2int(i,n) ((i)=(int)(n))
50#endif
51
52 48
53#define hashpow2(t,n) (gnode(t, lmod((n), sizenode(t)))) 49#define hashpow2(t,n) (gnode(t, lmod((n), sizenode(t))))
54 50
@@ -349,26 +345,6 @@ void luaH_free (lua_State *L, Table *t) {
349} 345}
350 346
351 347
352#if 0
353/*
354** try to remove an element from a hash table; cannot move any element
355** (because gc can call `remove' during a table traversal)
356*/
357void luaH_remove (Table *t, Node *e) {
358 Node *mp = luaH_mainposition(t, gkey(e));
359 if (e != mp) { /* element not in its main position? */
360 while (mp->next != e) mp = mp->next; /* find previous */
361 mp->next = e->next; /* remove `e' from its list */
362 }
363 else {
364 if (e->next != NULL) ??
365 }
366 lua_assert(ttisnil(gval(node)));
367 setnilvalue(gkey(e)); /* clear node `e' */
368 e->next = NULL;
369}
370#endif
371
372 348
373/* 349/*
374** inserts a new key into a hash table; first, check whether key's main 350** inserts a new key into a hash table; first, check whether key's main
diff --git a/ltablib.c b/ltablib.c
index 601e0df7..3ad650fe 100644
--- a/ltablib.c
+++ b/ltablib.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ltablib.c,v 1.21 2003/04/03 13:35:34 roberto Exp roberto $ 2** $Id: ltablib.c,v 1.22 2003/10/07 20:13:41 roberto Exp roberto $
3** Library for Table Manipulation 3** Library for Table Manipulation
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -8,6 +8,7 @@
8#include <stddef.h> 8#include <stddef.h>
9 9
10#define ltablib_c 10#define ltablib_c
11#define LUA_LIB
11 12
12#include "lua.h" 13#include "lua.h"
13 14
diff --git a/ltests.c b/ltests.c
index 84286123..b69d55ee 100644
--- a/ltests.c
+++ b/ltests.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ltests.c,v 2.3 2004/03/15 21:04:54 roberto Exp roberto $ 2** $Id: ltests.c,v 2.4 2004/03/23 17:07:53 roberto Exp roberto $
3** Internal Module for Debugging of the Lua Implementation 3** Internal Module for Debugging of the Lua Implementation
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -12,6 +12,7 @@
12#include <string.h> 12#include <string.h>
13 13
14#define ltests_c 14#define ltests_c
15#define LUA_CORE
15 16
16#include "lua.h" 17#include "lua.h"
17 18
@@ -443,7 +444,7 @@ static int listlocals (lua_State *L) {
443 444
444static int get_limits (lua_State *L) { 445static int get_limits (lua_State *L) {
445 lua_createtable(L, 0, 5); 446 lua_createtable(L, 0, 5);
446 setnameval(L, "BITS_INT", BITS_INT); 447 setnameval(L, "BITS_INT", LUA_BITSINT);
447 setnameval(L, "LFPF", LFIELDS_PER_FLUSH); 448 setnameval(L, "LFPF", LFIELDS_PER_FLUSH);
448 setnameval(L, "MAXVARS", MAXVARS); 449 setnameval(L, "MAXVARS", MAXVARS);
449 setnameval(L, "MAXSTACK", MAXSTACK); 450 setnameval(L, "MAXSTACK", MAXSTACK);
@@ -961,7 +962,7 @@ static int testC (lua_State *L) {
961 lua_pop(L, 1); 962 lua_pop(L, 1);
962 } 963 }
963 else if EQ("throw") { 964 else if EQ("throw") {
964#ifdef _cplusplus 965#ifdef __cplusplus
965static struct X { int x; } x; 966static struct X { int x; } x;
966 throw x; 967 throw x;
967#else 968#else
diff --git a/ltests.h b/ltests.h
index 934aad47..c1f58d8d 100644
--- a/ltests.h
+++ b/ltests.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ltests.h,v 2.2 2004/02/16 19:09:52 roberto Exp roberto $ 2** $Id: ltests.h,v 2.3 2004/03/15 21:04:54 roberto Exp roberto $
3** Internal Header for Debugging of the Lua Implementation 3** Internal Header for Debugging of the Lua Implementation
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -19,6 +19,8 @@
19#include <assert.h> 19#include <assert.h>
20#define lua_assert(c) assert(c) 20#define lua_assert(c) assert(c)
21#define check_exp(c,e) (lua_assert(c), (e)) 21#define check_exp(c,e) (lua_assert(c), (e))
22#undef api_check
23#define api_check(L, o) lua_assert(o)
22 24
23 25
24/* to avoid warnings, and to make sure value is really unused */ 26/* to avoid warnings, and to make sure value is really unused */
@@ -63,7 +65,9 @@ extern int islocked;
63 65
64int luaB_opentests (lua_State *L); 66int luaB_opentests (lua_State *L);
65 67
66#define LUA_EXTRALIBS { "tests", luaB_opentests }, 68#undef LUA_EXTRALIBS
69#define LUA_EXTRALIBS { "tests", luaB_opentests },
70
67 71
68 72
69/* real main will be defined at `ltests.c' */ 73/* real main will be defined at `ltests.c' */
diff --git a/ltm.c b/ltm.c
index 389cd7c4..1364d8e6 100644
--- a/ltm.c
+++ b/ltm.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ltm.c,v 2.1 2003/12/10 12:13:36 roberto Exp roberto $ 2** $Id: ltm.c,v 2.2 2004/02/16 19:09:52 roberto Exp roberto $
3** Tag methods 3** Tag methods
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -8,6 +8,7 @@
8#include <string.h> 8#include <string.h>
9 9
10#define ltm_c 10#define ltm_c
11#define LUA_CORE
11 12
12#include "lua.h" 13#include "lua.h"
13 14
diff --git a/lua.c b/lua.c
index 7f0fc4ba..05ffc88e 100644
--- a/lua.c
+++ b/lua.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lua.c,v 1.123 2003/05/07 16:02:16 roberto Exp roberto $ 2** $Id: lua.c,v 1.124 2003/10/23 18:06:22 roberto Exp roberto $
3** Lua stand-alone interpreter 3** Lua stand-alone interpreter
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -26,39 +26,6 @@
26#endif 26#endif
27 27
28 28
29/*
30** definition of `isatty'
31*/
32#ifdef _POSIX_C_SOURCE
33#include <unistd.h>
34#define stdin_is_tty() isatty(0)
35#else
36#define stdin_is_tty() 1 /* assume stdin is a tty */
37#endif
38
39
40
41#ifndef PROMPT
42#define PROMPT "> "
43#endif
44
45
46#ifndef PROMPT2
47#define PROMPT2 ">> "
48#endif
49
50#ifndef PROGNAME
51#define PROGNAME "lua"
52#endif
53
54#ifndef lua_userinit
55#define lua_userinit(L) openstdlibs(L)
56#endif
57
58
59#ifndef LUA_EXTRALIBS
60#define LUA_EXTRALIBS /* empty */
61#endif
62 29
63 30
64static lua_State *L = NULL; 31static lua_State *L = NULL;
@@ -187,14 +154,6 @@ static int load_file (const char *name) {
187} 154}
188 155
189 156
190/*
191** this macro can be used by some `history' system to save lines
192** read in manual input
193*/
194#ifndef lua_saveline
195#define lua_saveline(L,line) /* empty */
196#endif
197
198 157
199/* 158/*
200** this macro defines a function to show the prompt and reads the 159** this macro defines a function to show the prompt and reads the
@@ -291,8 +250,11 @@ static void manual_input (void) {
291} 250}
292 251
293 252
253#define clearinteractive(i) (*i &= 2)
254
294static int handle_argv (char *argv[], int *interactive) { 255static int handle_argv (char *argv[], int *interactive) {
295 if (argv[1] == NULL) { /* no more arguments? */ 256 if (argv[1] == NULL) { /* no arguments? */
257 *interactive = 0;
296 if (stdin_is_tty()) { 258 if (stdin_is_tty()) {
297 print_version(); 259 print_version();
298 manual_input(); 260 manual_input();
@@ -314,19 +276,22 @@ static int handle_argv (char *argv[], int *interactive) {
314 goto endloop; /* stop handling arguments */ 276 goto endloop; /* stop handling arguments */
315 } 277 }
316 case '\0': { 278 case '\0': {
279 clearinteractive(interactive);
317 file_input(NULL); /* executes stdin as a file */ 280 file_input(NULL); /* executes stdin as a file */
318 break; 281 break;
319 } 282 }
320 case 'i': { 283 case 'i': {
321 *interactive = 1; 284 *interactive = 2; /* force interactive mode after arguments */
322 break; 285 break;
323 } 286 }
324 case 'v': { 287 case 'v': {
288 clearinteractive(interactive);
325 print_version(); 289 print_version();
326 break; 290 break;
327 } 291 }
328 case 'e': { 292 case 'e': {
329 const char *chunk = argv[i] + 2; 293 const char *chunk = argv[i] + 2;
294 clearinteractive(interactive);
330 if (*chunk == '\0') chunk = argv[++i]; 295 if (*chunk == '\0') chunk = argv[++i];
331 if (chunk == NULL) { 296 if (chunk == NULL) {
332 print_usage(); 297 print_usage();
@@ -356,6 +321,7 @@ static int handle_argv (char *argv[], int *interactive) {
356 break; 321 break;
357 } 322 }
358 default: { 323 default: {
324 clearinteractive(interactive);
359 print_usage(); 325 print_usage();
360 return 1; 326 return 1;
361 } 327 }
@@ -364,6 +330,7 @@ static int handle_argv (char *argv[], int *interactive) {
364 if (argv[i] != NULL) { 330 if (argv[i] != NULL) {
365 const char *filename = argv[i]; 331 const char *filename = argv[i];
366 getargs(argv, i); /* collect arguments */ 332 getargs(argv, i); /* collect arguments */
333 clearinteractive(interactive);
367 lua_setglobal(L, "arg"); 334 lua_setglobal(L, "arg");
368 return file_input(filename); /* stop scanning arguments */ 335 return file_input(filename); /* stop scanning arguments */
369 } 336 }
@@ -401,7 +368,7 @@ struct Smain {
401static int pmain (lua_State *l) { 368static int pmain (lua_State *l) {
402 struct Smain *s = (struct Smain *)lua_touserdata(l, 1); 369 struct Smain *s = (struct Smain *)lua_touserdata(l, 1);
403 int status; 370 int status;
404 int interactive = 0; 371 int interactive = 1;
405 if (s->argv[0] && s->argv[0][0]) progname = s->argv[0]; 372 if (s->argv[0] && s->argv[0][0]) progname = s->argv[0];
406 L = l; 373 L = l;
407 lua_userinit(l); /* open libraries */ 374 lua_userinit(l); /* open libraries */
diff --git a/lua.h b/lua.h
index 937e7e6d..7317bc47 100644
--- a/lua.h
+++ b/lua.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lua.h,v 1.187 2004/03/09 17:34:35 roberto Exp roberto $ 2** $Id: lua.h,v 1.188 2004/03/24 13:55:46 roberto Exp roberto $
3** Lua - An Extensible Extension Language 3** Lua - An Extensible Extension Language
4** Tecgraf: Computer Graphics Technology Group, PUC-Rio, Brazil 4** Tecgraf: Computer Graphics Technology Group, PUC-Rio, Brazil
5** http://www.lua.org mailto:info@lua.org 5** http://www.lua.org mailto:info@lua.org
@@ -14,6 +14,9 @@
14#include <stddef.h> 14#include <stddef.h>
15 15
16 16
17#include "luaconf.h"
18
19
17#define LUA_VERSION "Lua 5.1 (work)" 20#define LUA_VERSION "Lua 5.1 (work)"
18#define LUA_COPYRIGHT "Copyright (C) 1994-2004 Tecgraf, PUC-Rio" 21#define LUA_COPYRIGHT "Copyright (C) 1994-2004 Tecgraf, PUC-Rio"
19#define LUA_AUTHORS "R. Ierusalimschy, L. H. de Figueiredo & W. Celes" 22#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);
91 94
92 95
93/* type of numbers in Lua */ 96/* type of numbers in Lua */
94#ifndef LUA_NUMBER
95typedef double lua_Number;
96#else
97typedef LUA_NUMBER lua_Number; 97typedef LUA_NUMBER lua_Number;
98#endif
99 98
100 99
101/* type for integer functions */ 100/* type for integer functions */
102#ifndef LUA_INTEGER
103typedef long lua_Integer;
104#else
105typedef LUA_INTEGER lua_Integer; 101typedef LUA_INTEGER lua_Integer;
106#endif
107 102
108 103
109/* mark for all API functions */
110#ifndef LUA_API
111#define LUA_API extern
112#endif
113
114 104
115/* 105/*
116** state manipulation 106** state manipulation
@@ -310,22 +300,6 @@ LUA_API lua_Alloc lua_getallocf (lua_State *L, void **ud);
310 300
311 301
312 302
313/*
314** {======================================================================
315** useful definitions for Lua kernel and libraries
316** =======================================================================
317*/
318
319/* formats for Lua numbers */
320#ifndef LUA_NUMBER_SCAN
321#define LUA_NUMBER_SCAN "%lf"
322#endif
323
324#ifndef LUA_NUMBER_FMT
325#define LUA_NUMBER_FMT "%.14g"
326#endif
327
328/* }====================================================================== */
329 303
330 304
331/* 305/*
diff --git a/lundump.c b/lundump.c
index 10508ed4..8375a964 100644
--- a/lundump.c
+++ b/lundump.c
@@ -1,10 +1,11 @@
1/* 1/*
2** $Id: lundump.c,v 1.64 2003/08/27 21:01:44 roberto Exp roberto $ 2** $Id: lundump.c,v 2.1 2003/12/10 12:13:36 roberto Exp roberto $
3** load pre-compiled Lua chunks 3** load pre-compiled Lua chunks
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
6 6
7#define lundump_c 7#define lundump_c
8#define LUA_CORE
8 9
9#include "lua.h" 10#include "lua.h"
10 11
diff --git a/lvm.c b/lvm.c
index 779245f2..4f176ca1 100644
--- a/lvm.c
+++ b/lvm.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lvm.c,v 2.2 2004/03/16 12:31:40 roberto Exp roberto $ 2** $Id: lvm.c,v 2.3 2004/03/26 14:02:41 roberto Exp roberto $
3** Lua virtual machine 3** Lua virtual machine
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -8,10 +8,8 @@
8#include <stdlib.h> 8#include <stdlib.h>
9#include <string.h> 9#include <string.h>
10 10
11/* needed only when `lua_number2str' uses `sprintf' */
12#include <stdio.h>
13
14#define lvm_c 11#define lvm_c
12#define LUA_CORE
15 13
16#include "lua.h" 14#include "lua.h"
17 15
@@ -29,12 +27,6 @@
29 27
30 28
31 29
32/* function to convert a lua_Number to a string */
33#ifndef lua_number2str
34#define lua_number2str(s,n) sprintf((s), LUA_NUMBER_FMT, (n))
35#endif
36
37
38/* limit for table tag-method chains (to avoid loops) */ 30/* limit for table tag-method chains (to avoid loops) */
39#define MAXTAGLOOP 100 31#define MAXTAGLOOP 100
40 32
diff --git a/lzio.c b/lzio.c
index b55a2f0a..0ead005a 100644
--- a/lzio.c
+++ b/lzio.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lzio.c,v 1.27 2003/08/27 20:57:52 roberto Exp roberto $ 2** $Id: lzio.c,v 1.28 2003/11/18 10:44:53 roberto Exp roberto $
3** a generic input stream interface 3** a generic input stream interface
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -8,6 +8,7 @@
8#include <string.h> 8#include <string.h>
9 9
10#define lzio_c 10#define lzio_c
11#define LUA_CORE
11 12
12#include "lua.h" 13#include "lua.h"
13 14
diff --git a/makefile b/makefile
index 6a9c0d91..1f0cfa51 100644
--- a/makefile
+++ b/makefile
@@ -1,5 +1,5 @@
1# 1#
2## $Id: makefile,v 1.41 2003/04/07 20:11:53 roberto Exp roberto $ 2## $Id: makefile,v 2.1 2003/12/10 12:13:36 roberto Exp roberto $
3## Makefile 3## Makefile
4## See Copyright Notice in lua.h 4## See Copyright Notice in lua.h
5# 5#
@@ -10,11 +10,11 @@
10# -DEXTERNMEMCHECK -DHARDSTACKTESTS 10# -DEXTERNMEMCHECK -DHARDSTACKTESTS
11DEBUG = -g -DLUA_USER_H='"ltests.h"' 11DEBUG = -g -DLUA_USER_H='"ltests.h"'
12OPTIMIZE = -O2 \ 12OPTIMIZE = -O2 \
13 -D'lua_number2int(i,d)=__asm__("fldl %1\nfistpl %0":"=m"(i):"m"(d))' \
14# -fomit-frame-pointer 13# -fomit-frame-pointer
15 14
16 15
17CONFIG = $(DEBUG) $(OPTIMIZE) -DLUA_COMPATUPSYNTAX -DUSE_TMPNAME -DUSE_DLOPEN 16# -DUSE_TMPNAME??
17CONFIG = $(DEBUG) $(OPTIMIZE) -DLUA_COMPATUPSYNTAX -DUSE_DLOPEN
18 18
19 19
20# Compilation parameters 20# Compilation parameters
@@ -103,54 +103,58 @@ clear :
103 co $(CO_OPTIONS) $@ 103 co $(CO_OPTIONS) $@
104 104
105 105
106lapi.o: lapi.c lua.h lapi.h lobject.h llimits.h ldebug.h lstate.h ltm.h \ 106lapi.o: lapi.c lua.h luaconf.h lapi.h lobject.h llimits.h ldebug.h \
107 lzio.h lmem.h ldo.h lfunc.h lgc.h lstring.h ltable.h lundump.h lvm.h 107 lstate.h ltm.h lzio.h lmem.h ldo.h lfunc.h lgc.h lstring.h ltable.h \
108lauxlib.o: lauxlib.c lua.h lauxlib.h
109lbaselib.o: lbaselib.c lua.h lauxlib.h lualib.h
110lcode.o: lcode.c lua.h lcode.h llex.h lobject.h llimits.h lzio.h lmem.h \
111 lopcodes.h lparser.h ltable.h ldebug.h lstate.h ltm.h ldo.h lgc.h
112ldblib.o: ldblib.c lua.h lauxlib.h lualib.h
113ldebug.o: ldebug.c lua.h lapi.h lobject.h llimits.h lcode.h llex.h lzio.h \
114 lmem.h lopcodes.h lparser.h ltable.h ldebug.h lstate.h ltm.h ldo.h \
115 lfunc.h lstring.h lgc.h lvm.h
116ldo.o: ldo.c lua.h ldebug.h lstate.h lobject.h llimits.h ltm.h lzio.h \
117 lmem.h ldo.h lfunc.h lgc.h lopcodes.h lparser.h ltable.h lstring.h \
118 lundump.h lvm.h 108 lundump.h lvm.h
119ldump.o: ldump.c lua.h lobject.h llimits.h lopcodes.h lstate.h ltm.h \ 109lauxlib.o: lauxlib.c lua.h luaconf.h lauxlib.h
120 lzio.h lmem.h lundump.h 110lbaselib.o: lbaselib.c lua.h luaconf.h lauxlib.h lualib.h
121lfunc.o: lfunc.c lua.h lfunc.h lobject.h llimits.h lgc.h lmem.h lstate.h \ 111lcode.o: lcode.c lua.h luaconf.h lcode.h llex.h lobject.h llimits.h \
122 ltm.h lzio.h 112 lzio.h lmem.h lopcodes.h lparser.h ltable.h ldebug.h lstate.h ltm.h \
123lgc.o: lgc.c lua.h ldebug.h lstate.h lobject.h llimits.h ltm.h lzio.h \ 113 ldo.h lgc.h
124 lmem.h ldo.h lfunc.h lgc.h lstring.h ltable.h 114ldblib.o: ldblib.c lua.h luaconf.h lauxlib.h lualib.h
125liolib.o: liolib.c lua.h lauxlib.h lualib.h 115ldebug.o: ldebug.c lua.h luaconf.h lapi.h lobject.h llimits.h lcode.h \
126llex.o: llex.c lua.h ldo.h lobject.h llimits.h lstate.h ltm.h lzio.h \
127 lmem.h llex.h lparser.h ltable.h lstring.h lgc.h
128lmathlib.o: lmathlib.c lua.h lauxlib.h lualib.h
129lmem.o: lmem.c lua.h ldebug.h lstate.h lobject.h llimits.h ltm.h lzio.h \
130 lmem.h ldo.h
131loadlib.o: loadlib.c lua.h lauxlib.h lualib.h
132lobject.o: lobject.c lua.h ldo.h lobject.h llimits.h lstate.h ltm.h \
133 lzio.h lmem.h lstring.h lgc.h lvm.h
134lopcodes.o: lopcodes.c lua.h lobject.h llimits.h lopcodes.h
135lparser.o: lparser.c lua.h lcode.h llex.h lobject.h llimits.h lzio.h \
136 lmem.h lopcodes.h lparser.h ltable.h ldebug.h lstate.h ltm.h ldo.h \
137 lfunc.h lstring.h lgc.h
138lstate.o: lstate.c lua.h ldebug.h lstate.h lobject.h llimits.h ltm.h \
139 lzio.h lmem.h ldo.h lfunc.h lgc.h llex.h lstring.h ltable.h
140lstring.o: lstring.c lua.h lmem.h llimits.h lobject.h lstate.h ltm.h \
141 lzio.h lstring.h lgc.h
142lstrlib.o: lstrlib.c lua.h lauxlib.h lualib.h
143ltable.o: ltable.c lua.h ldebug.h lstate.h lobject.h llimits.h ltm.h \
144 lzio.h lmem.h ldo.h lgc.h ltable.h
145ltablib.o: ltablib.c lua.h lauxlib.h lualib.h
146ltests.o: ltests.c lua.h lapi.h lobject.h llimits.h lauxlib.h lcode.h \
147 llex.h lzio.h lmem.h lopcodes.h lparser.h ltable.h ldebug.h lstate.h \ 116 llex.h lzio.h lmem.h lopcodes.h lparser.h ltable.h ldebug.h lstate.h \
148 ltm.h ldo.h lfunc.h lstring.h lgc.h lualib.h 117 ltm.h ldo.h lfunc.h lstring.h lgc.h lvm.h
149ltm.o: ltm.c lua.h lobject.h llimits.h lstate.h ltm.h lzio.h lmem.h \ 118ldo.o: ldo.c lua.h luaconf.h ldebug.h lstate.h lobject.h llimits.h ltm.h \
150 lstring.h lgc.h ltable.h 119 lzio.h lmem.h ldo.h lfunc.h lgc.h lopcodes.h lparser.h ltable.h \
151lua.o: lua.c lua.h lauxlib.h lualib.h 120 lstring.h lundump.h lvm.h
152lundump.o: lundump.c lua.h ldebug.h lstate.h lobject.h llimits.h ltm.h \ 121ldump.o: ldump.c lua.h luaconf.h lobject.h llimits.h lopcodes.h lstate.h \
153 lzio.h lmem.h ldo.h lfunc.h lopcodes.h lstring.h lgc.h lundump.h 122 ltm.h lzio.h lmem.h lundump.h
154lvm.o: lvm.c lua.h ldebug.h lstate.h lobject.h llimits.h ltm.h lzio.h \ 123lfunc.o: lfunc.c lua.h luaconf.h lfunc.h lobject.h llimits.h lgc.h lmem.h \
155 lmem.h ldo.h lfunc.h lgc.h lopcodes.h lstring.h ltable.h lvm.h 124 lstate.h ltm.h lzio.h
156lzio.o: lzio.c lua.h llimits.h lmem.h lstate.h lobject.h ltm.h lzio.h 125lgc.o: lgc.c lua.h luaconf.h ldebug.h lstate.h lobject.h llimits.h ltm.h \
126 lzio.h lmem.h ldo.h lfunc.h lgc.h lstring.h ltable.h
127liolib.o: liolib.c lua.h luaconf.h lauxlib.h lualib.h
128llex.o: llex.c lua.h luaconf.h ldo.h lobject.h llimits.h lstate.h ltm.h \
129 lzio.h lmem.h llex.h lparser.h ltable.h lstring.h lgc.h
130lmathlib.o: lmathlib.c lua.h luaconf.h lauxlib.h lualib.h
131lmem.o: lmem.c lua.h luaconf.h ldebug.h lstate.h lobject.h llimits.h \
132 ltm.h lzio.h lmem.h ldo.h
133loadlib.o: loadlib.c lua.h luaconf.h lauxlib.h lualib.h
134lobject.o: lobject.c lua.h luaconf.h ldo.h lobject.h llimits.h lstate.h \
135 ltm.h lzio.h lmem.h lstring.h lgc.h lvm.h
136lopcodes.o: lopcodes.c lua.h luaconf.h lobject.h llimits.h lopcodes.h
137lparser.o: lparser.c lua.h luaconf.h lcode.h llex.h lobject.h llimits.h \
138 lzio.h lmem.h lopcodes.h lparser.h ltable.h ldebug.h lstate.h ltm.h \
139 ldo.h lfunc.h lstring.h lgc.h
140lstate.o: lstate.c lua.h luaconf.h ldebug.h lstate.h lobject.h llimits.h \
141 ltm.h lzio.h lmem.h ldo.h lfunc.h lgc.h llex.h lstring.h ltable.h
142lstring.o: lstring.c lua.h luaconf.h lmem.h llimits.h lobject.h lstate.h \
143 ltm.h lzio.h lstring.h lgc.h
144lstrlib.o: lstrlib.c lua.h luaconf.h lauxlib.h lualib.h
145ltable.o: ltable.c lua.h luaconf.h ldebug.h lstate.h lobject.h llimits.h \
146 ltm.h lzio.h lmem.h ldo.h lgc.h ltable.h
147ltablib.o: ltablib.c lua.h luaconf.h lauxlib.h lualib.h
148ltests.o: ltests.c lua.h luaconf.h lapi.h lobject.h llimits.h lauxlib.h \
149 lcode.h llex.h lzio.h lmem.h lopcodes.h lparser.h ltable.h ldebug.h \
150 lstate.h ltm.h ldo.h lfunc.h lstring.h lgc.h lualib.h
151ltm.o: ltm.c lua.h luaconf.h lobject.h llimits.h lstate.h ltm.h lzio.h \
152 lmem.h lstring.h lgc.h ltable.h
153lua.o: lua.c lua.h luaconf.h lauxlib.h lualib.h
154lundump.o: lundump.c lua.h luaconf.h ldebug.h lstate.h lobject.h \
155 llimits.h ltm.h lzio.h lmem.h ldo.h lfunc.h lopcodes.h lstring.h lgc.h \
156 lundump.h
157lvm.o: lvm.c lua.h luaconf.h ldebug.h lstate.h lobject.h llimits.h ltm.h \
158 lzio.h lmem.h ldo.h lfunc.h lgc.h lopcodes.h lstring.h ltable.h lvm.h
159lzio.o: lzio.c lua.h luaconf.h llimits.h lmem.h lstate.h lobject.h ltm.h \
160 lzio.h