aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2000-12-04 16:33:40 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2000-12-04 16:33:40 -0200
commit4894c2796277b47b0ffc8983e8231d2cc95ee09b (patch)
treedc702c79716a42f22301bc5b9b5798a28173f7c2
parent10ac68c648e0e1d23fe5485bc711df8fc71b6ae3 (diff)
downloadlua-4894c2796277b47b0ffc8983e8231d2cc95ee09b.tar.gz
lua-4894c2796277b47b0ffc8983e8231d2cc95ee09b.tar.bz2
lua-4894c2796277b47b0ffc8983e8231d2cc95ee09b.zip
lua_Number defined in lua.h (1st version)
-rw-r--r--lapi.c8
-rw-r--r--lauxlib.c8
-rw-r--r--lauxlib.h6
-rw-r--r--lcode.c10
-rw-r--r--lcode.h4
-rw-r--r--lfunc.c4
-rw-r--r--liolib.c4
-rw-r--r--llex.h4
-rw-r--r--llimits.h16
-rw-r--r--lmathlib.c12
-rw-r--r--lobject.c6
-rw-r--r--lobject.h8
-rw-r--r--lopcodes.h4
-rw-r--r--lparser.c6
-rw-r--r--ltable.c6
-rw-r--r--ltable.h6
-rw-r--r--lua.h9
-rw-r--r--lundump.c12
-rw-r--r--lvm.c8
19 files changed, 67 insertions, 74 deletions
diff --git a/lapi.c b/lapi.c
index de73b3bb..bb7516e9 100644
--- a/lapi.c
+++ b/lapi.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lapi.c,v 1.110 2000/10/30 12:50:09 roberto Exp roberto $ 2** $Id: lapi.c,v 1.111 2000/11/24 17:39:56 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*/
@@ -154,7 +154,7 @@ LUA_API int lua_lessthan (lua_State *L, int index1, int index2) {
154 154
155 155
156 156
157LUA_API double lua_tonumber (lua_State *L, int index) { 157LUA_API lua_Number lua_tonumber (lua_State *L, int index) {
158 StkId o = luaA_indexAcceptable(L, index); 158 StkId o = luaA_indexAcceptable(L, index);
159 return (o == NULL || tonumber(o)) ? 0 : nvalue(o); 159 return (o == NULL || tonumber(o)) ? 0 : nvalue(o);
160} 160}
@@ -205,7 +205,7 @@ LUA_API void lua_pushnil (lua_State *L) {
205} 205}
206 206
207 207
208LUA_API void lua_pushnumber (lua_State *L, double n) { 208LUA_API void lua_pushnumber (lua_State *L, lua_Number n) {
209 nvalue(L->top) = n; 209 nvalue(L->top) = n;
210 ttype(L->top) = LUA_TNUMBER; 210 ttype(L->top) = LUA_TNUMBER;
211 api_incr_top(L); 211 api_incr_top(L);
@@ -461,7 +461,7 @@ LUA_API int lua_getn (lua_State *L, int index) {
461 if (ttype(value) == LUA_TNUMBER) 461 if (ttype(value) == LUA_TNUMBER)
462 return (int)nvalue(value); 462 return (int)nvalue(value);
463 else { 463 else {
464 Number max = 0; 464 lua_Number max = 0;
465 int i = h->size; 465 int i = h->size;
466 Node *n = h->node; 466 Node *n = h->node;
467 while (i--) { 467 while (i--) {
diff --git a/lauxlib.c b/lauxlib.c
index 5d122ed3..5c9014f5 100644
--- a/lauxlib.c
+++ b/lauxlib.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lauxlib.c,v 1.42 2000/10/30 12:38:50 roberto Exp roberto $ 2** $Id: lauxlib.c,v 1.43 2000/10/30 13:07:48 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*/
@@ -84,15 +84,15 @@ LUALIB_API const char *luaL_opt_lstr (lua_State *L, int narg, const char *def, s
84} 84}
85 85
86 86
87LUALIB_API double luaL_check_number (lua_State *L, int narg) { 87LUALIB_API lua_Number luaL_check_number (lua_State *L, int narg) {
88 double d = lua_tonumber(L, narg); 88 lua_Number d = lua_tonumber(L, narg);
89 if (d == 0 && !lua_isnumber(L, narg)) /* avoid extra test when d is not 0 */ 89 if (d == 0 && !lua_isnumber(L, narg)) /* avoid extra test when d is not 0 */
90 type_error(L, narg, LUA_TNUMBER); 90 type_error(L, narg, LUA_TNUMBER);
91 return d; 91 return d;
92} 92}
93 93
94 94
95LUALIB_API double luaL_opt_number (lua_State *L, int narg, double def) { 95LUALIB_API lua_Number luaL_opt_number (lua_State *L, int narg, lua_Number def) {
96 if (lua_isnull(L, narg)) return def; 96 if (lua_isnull(L, narg)) return def;
97 else return luaL_check_number(L, narg); 97 else return luaL_check_number(L, narg);
98} 98}
diff --git a/lauxlib.h b/lauxlib.h
index 332c34cf..286460ee 100644
--- a/lauxlib.h
+++ b/lauxlib.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lauxlib.h,v 1.29 2000/10/27 16:15:53 roberto Exp roberto $ 2** $Id: lauxlib.h,v 1.30 2000/10/30 12:38:50 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*/
@@ -30,8 +30,8 @@ LUALIB_API void luaL_openlib (lua_State *L, const struct luaL_reg *l, int n);
30LUALIB_API void luaL_argerror (lua_State *L, int numarg, const char *extramsg); 30LUALIB_API void luaL_argerror (lua_State *L, int numarg, const char *extramsg);
31LUALIB_API const char *luaL_check_lstr (lua_State *L, int numArg, size_t *len); 31LUALIB_API const char *luaL_check_lstr (lua_State *L, int numArg, size_t *len);
32LUALIB_API const char *luaL_opt_lstr (lua_State *L, int numArg, const char *def, size_t *len); 32LUALIB_API const char *luaL_opt_lstr (lua_State *L, int numArg, const char *def, size_t *len);
33LUALIB_API double luaL_check_number (lua_State *L, int numArg); 33LUALIB_API lua_Number luaL_check_number (lua_State *L, int numArg);
34LUALIB_API double luaL_opt_number (lua_State *L, int numArg, double def); 34LUALIB_API lua_Number luaL_opt_number (lua_State *L, int nArg, lua_Number def);
35 35
36LUALIB_API void luaL_checkstack (lua_State *L, int space, const char *msg); 36LUALIB_API void luaL_checkstack (lua_State *L, int space, const char *msg);
37LUALIB_API void luaL_checktype (lua_State *L, int narg, int t); 37LUALIB_API void luaL_checktype (lua_State *L, int narg, int t);
diff --git a/lcode.c b/lcode.c
index 3b228ff4..306661c3 100644
--- a/lcode.c
+++ b/lcode.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lcode.c,v 1.51 2000/09/29 12:42:13 roberto Exp roberto $ 2** $Id: lcode.c,v 1.52 2000/11/30 18:50:47 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*/
@@ -99,7 +99,7 @@ void luaK_kstr (LexState *ls, int c) {
99} 99}
100 100
101 101
102static int number_constant (FuncState *fs, Number r) { 102static int number_constant (FuncState *fs, lua_Number r) {
103 /* check whether `r' has appeared within the last LOOKBACKNUMS entries */ 103 /* check whether `r' has appeared within the last LOOKBACKNUMS entries */
104 Proto *f = fs->f; 104 Proto *f = fs->f;
105 int c = f->nknum; 105 int c = f->nknum;
@@ -107,7 +107,7 @@ static int number_constant (FuncState *fs, Number r) {
107 while (--c >= lim) 107 while (--c >= lim)
108 if (f->knum[c] == r) return c; 108 if (f->knum[c] == r) return c;
109 /* not found; create a new entry */ 109 /* not found; create a new entry */
110 luaM_growvector(fs->L, f->knum, f->nknum, 1, Number, 110 luaM_growvector(fs->L, f->knum, f->nknum, 1, lua_Number,
111 "constant table overflow", MAXARG_U); 111 "constant table overflow", MAXARG_U);
112 c = f->nknum++; 112 c = f->nknum++;
113 f->knum[c] = r; 113 f->knum[c] = r;
@@ -115,8 +115,8 @@ static int number_constant (FuncState *fs, Number r) {
115} 115}
116 116
117 117
118void luaK_number (FuncState *fs, Number f) { 118void luaK_number (FuncState *fs, lua_Number f) {
119 if (f <= (Number)MAXARG_S && (Number)(int)f == f) 119 if (f <= (lua_Number)MAXARG_S && (lua_Number)(int)f == f)
120 luaK_code1(fs, OP_PUSHINT, (int)f); /* f has a short integer value */ 120 luaK_code1(fs, OP_PUSHINT, (int)f); /* f has a short integer value */
121 else 121 else
122 luaK_code1(fs, OP_PUSHNUM, number_constant(fs, f)); 122 luaK_code1(fs, OP_PUSHNUM, number_constant(fs, f));
diff --git a/lcode.h b/lcode.h
index bb032267..6090d04e 100644
--- a/lcode.h
+++ b/lcode.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lcode.h,v 1.16 2000/08/09 14:49:13 roberto Exp roberto $ 2** $Id: lcode.h,v 1.17 2000/11/30 18:50:47 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*/
@@ -58,7 +58,7 @@ void luaK_goiftrue (FuncState *fs, expdesc *v, int keepvalue);
58int luaK_getlabel (FuncState *fs); 58int luaK_getlabel (FuncState *fs);
59void luaK_deltastack (FuncState *fs, int delta); 59void luaK_deltastack (FuncState *fs, int delta);
60void luaK_kstr (LexState *ls, int c); 60void luaK_kstr (LexState *ls, int c);
61void luaK_number (FuncState *fs, Number f); 61void luaK_number (FuncState *fs, lua_Number f);
62void luaK_adjuststack (FuncState *fs, int n); 62void luaK_adjuststack (FuncState *fs, int n);
63int luaK_lastisopen (FuncState *fs); 63int luaK_lastisopen (FuncState *fs);
64void luaK_setcallreturns (FuncState *fs, int nresults); 64void luaK_setcallreturns (FuncState *fs, int nresults);
diff --git a/lfunc.c b/lfunc.c
index 2f78a9ed..ad1abfc4 100644
--- a/lfunc.c
+++ b/lfunc.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lfunc.c,v 1.33 2000/10/18 17:19:09 roberto Exp roberto $ 2** $Id: lfunc.c,v 1.34 2000/10/30 12:20:29 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*/
@@ -57,7 +57,7 @@ Proto *luaF_newproto (lua_State *L) {
57 57
58static size_t protosize (Proto *f) { 58static size_t protosize (Proto *f) {
59 return sizeof(Proto) 59 return sizeof(Proto)
60 + f->nknum*sizeof(Number) 60 + f->nknum*sizeof(lua_Number)
61 + f->nkstr*sizeof(TString *) 61 + f->nkstr*sizeof(TString *)
62 + f->nkproto*sizeof(Proto *) 62 + f->nkproto*sizeof(Proto *)
63 + f->ncode*sizeof(Instruction) 63 + f->ncode*sizeof(Instruction)
diff --git a/liolib.c b/liolib.c
index e47ebd81..e08d8ee7 100644
--- a/liolib.c
+++ b/liolib.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: liolib.c,v 1.91 2000/10/31 13:10:24 roberto Exp roberto $ 2** $Id: liolib.c,v 1.92 2000/11/23 13:49:35 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*/
@@ -476,7 +476,7 @@ static int io_getenv (lua_State *L) {
476 476
477 477
478static int io_clock (lua_State *L) { 478static int io_clock (lua_State *L) {
479 lua_pushnumber(L, ((double)clock())/CLOCKS_PER_SEC); 479 lua_pushnumber(L, ((lua_Number)clock())/(lua_Number)CLOCKS_PER_SEC);
480 return 1; 480 return 1;
481} 481}
482 482
diff --git a/llex.h b/llex.h
index f0d0820d..e342f261 100644
--- a/llex.h
+++ b/llex.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: llex.h,v 1.30 2000/06/21 18:13:56 roberto Exp roberto $ 2** $Id: llex.h,v 1.31 2000/09/27 17:41:58 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*/
@@ -36,7 +36,7 @@ enum RESERVED {
36 36
37 37
38typedef union { 38typedef union {
39 Number r; 39 lua_Number r;
40 TString *ts; 40 TString *ts;
41} SemInfo; /* semantics information */ 41} SemInfo; /* semantics information */
42 42
diff --git a/llimits.h b/llimits.h
index 4a53fc7b..e52f9d58 100644
--- a/llimits.h
+++ b/llimits.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: llimits.h,v 1.19 2000/10/26 12:47:05 roberto Exp roberto $ 2** $Id: llimits.h,v 1.20 2000/11/24 17:39:56 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*/
@@ -31,21 +31,11 @@
31#endif 31#endif
32 32
33 33
34/* 34/* function to convert a lua_Number to a string */
35** Define the type `number' of Lua
36** GREP LUA_NUMBER to change that
37*/
38#ifndef LUA_NUM_TYPE
39#define LUA_NUM_TYPE double
40#endif
41
42typedef LUA_NUM_TYPE Number;
43
44/* function to convert a Number to a string */
45#define NUMBER_FMT "%.16g" /* LUA_NUMBER */ 35#define NUMBER_FMT "%.16g" /* LUA_NUMBER */
46#define lua_number2str(s,n) sprintf((s), NUMBER_FMT, (n)) 36#define lua_number2str(s,n) sprintf((s), NUMBER_FMT, (n))
47 37
48/* function to convert a string to a Number */ 38/* function to convert a string to a lua_Number */
49#define lua_str2number(s,p) strtod((s), (p)) 39#define lua_str2number(s,p) strtod((s), (p))
50 40
51 41
diff --git a/lmathlib.c b/lmathlib.c
index 0f08866a..e1c3def8 100644
--- a/lmathlib.c
+++ b/lmathlib.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lmathlib.c,v 1.31 2000/10/27 16:15:53 roberto Exp roberto $ 2** $Id: lmathlib.c,v 1.32 2000/10/31 13:10:24 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*/
@@ -139,10 +139,10 @@ static int math_ldexp (lua_State *L) {
139 139
140static int math_min (lua_State *L) { 140static int math_min (lua_State *L) {
141 int n = lua_gettop(L); /* number of arguments */ 141 int n = lua_gettop(L); /* number of arguments */
142 double dmin = luaL_check_number(L, 1); 142 lua_Number dmin = luaL_check_number(L, 1);
143 int i; 143 int i;
144 for (i=2; i<=n; i++) { 144 for (i=2; i<=n; i++) {
145 double d = luaL_check_number(L, i); 145 lua_Number d = luaL_check_number(L, i);
146 if (d < dmin) 146 if (d < dmin)
147 dmin = d; 147 dmin = d;
148 } 148 }
@@ -153,10 +153,10 @@ static int math_min (lua_State *L) {
153 153
154static int math_max (lua_State *L) { 154static int math_max (lua_State *L) {
155 int n = lua_gettop(L); /* number of arguments */ 155 int n = lua_gettop(L); /* number of arguments */
156 double dmax = luaL_check_number(L, 1); 156 lua_Number dmax = luaL_check_number(L, 1);
157 int i; 157 int i;
158 for (i=2; i<=n; i++) { 158 for (i=2; i<=n; i++) {
159 double d = luaL_check_number(L, i); 159 lua_Number d = luaL_check_number(L, i);
160 if (d > dmax) 160 if (d > dmax)
161 dmax = d; 161 dmax = d;
162 } 162 }
@@ -168,7 +168,7 @@ static int math_max (lua_State *L) {
168static int math_random (lua_State *L) { 168static int math_random (lua_State *L) {
169 /* the '%' avoids the (rare) case of r==1, and is needed also because on 169 /* the '%' avoids the (rare) case of r==1, and is needed also because on
170 some systems (SunOS!) "rand()" may return a value larger than RAND_MAX */ 170 some systems (SunOS!) "rand()" may return a value larger than RAND_MAX */
171 double r = (double)(rand()%RAND_MAX) / (double)RAND_MAX; 171 lua_Number r = (lua_Number)(rand()%RAND_MAX) / (lua_Number)RAND_MAX;
172 switch (lua_gettop(L)) { /* check number of arguments */ 172 switch (lua_gettop(L)) { /* check number of arguments */
173 case 0: { /* no arguments */ 173 case 0: { /* no arguments */
174 lua_pushnumber(L, r); /* Number between 0 and 1 */ 174 lua_pushnumber(L, r); /* Number between 0 and 1 */
diff --git a/lobject.c b/lobject.c
index 9e6504ab..5f9876c0 100644
--- a/lobject.c
+++ b/lobject.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lobject.c,v 1.55 2000/10/20 16:36:32 roberto Exp roberto $ 2** $Id: lobject.c,v 1.56 2000/11/24 17:39:56 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*/
@@ -65,9 +65,9 @@ char *luaO_openspace (lua_State *L, size_t n) {
65} 65}
66 66
67 67
68int luaO_str2d (const char *s, Number *result) { /* LUA_NUMBER */ 68int luaO_str2d (const char *s, lua_Number *result) { /* LUA_NUMBER */
69 char *endptr; 69 char *endptr;
70 Number res = lua_str2number(s, &endptr); 70 lua_Number res = lua_str2number(s, &endptr);
71 if (endptr == s) return 0; /* no conversion */ 71 if (endptr == s) return 0; /* no conversion */
72 while (isspace((unsigned char)*endptr)) endptr++; 72 while (isspace((unsigned char)*endptr)) endptr++;
73 if (*endptr != '\0') return 0; /* invalid trailing characters? */ 73 if (*endptr != '\0') return 0; /* invalid trailing characters? */
diff --git a/lobject.h b/lobject.h
index f0f7de20..916cc4d1 100644
--- a/lobject.h
+++ b/lobject.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lobject.h,v 1.82 2000/10/30 17:49:19 roberto Exp roberto $ 2** $Id: lobject.h,v 1.83 2000/11/24 17:39:56 roberto Exp roberto $
3** Type definitions for Lua objects 3** Type definitions for Lua objects
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -48,7 +48,7 @@ typedef union {
48 struct Closure *cl; /* LUA_TFUNCTION */ 48 struct Closure *cl; /* LUA_TFUNCTION */
49 struct Hash *a; /* LUA_TTABLE */ 49 struct Hash *a; /* LUA_TTABLE */
50 struct CallInfo *i; /* LUA_TLMARK */ 50 struct CallInfo *i; /* LUA_TLMARK */
51 Number n; /* LUA_TNUMBER */ 51 lua_Number n; /* LUA_TNUMBER */
52} Value; 52} Value;
53 53
54 54
@@ -101,7 +101,7 @@ typedef struct TString {
101** Function Prototypes 101** Function Prototypes
102*/ 102*/
103typedef struct Proto { 103typedef struct Proto {
104 Number *knum; /* Number numbers used by the function */ 104 lua_Number *knum; /* numbers used by the function */
105 int nknum; /* size of `knum' */ 105 int nknum; /* size of `knum' */
106 struct TString **kstr; /* strings used by the function */ 106 struct TString **kstr; /* strings used by the function */
107 int nkstr; /* size of `kstr' */ 107 int nkstr; /* size of `kstr' */
@@ -195,7 +195,7 @@ luint32 luaO_power2 (luint32 n);
195char *luaO_openspace (lua_State *L, size_t n); 195char *luaO_openspace (lua_State *L, size_t n);
196 196
197int luaO_equalObj (const TObject *t1, const TObject *t2); 197int luaO_equalObj (const TObject *t1, const TObject *t2);
198int luaO_str2d (const char *s, Number *result); 198int luaO_str2d (const char *s, lua_Number *result);
199 199
200void luaO_verror (lua_State *L, const char *fmt, ...); 200void luaO_verror (lua_State *L, const char *fmt, ...);
201void luaO_chunkid (char *out, const char *source, int len); 201void luaO_chunkid (char *out, const char *source, int len);
diff --git a/lopcodes.h b/lopcodes.h
index 927390d0..5c9ffe59 100644
--- a/lopcodes.h
+++ b/lopcodes.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lopcodes.h,v 1.67 2000/08/29 14:48:16 roberto Exp roberto $ 2** $Id: lopcodes.h,v 1.68 2000/10/24 16:05:59 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*/
@@ -91,7 +91,7 @@ OP_TAILCALL,/* A B v_n-v_1 f(at a) (return) f(v1,...,v_n) */
91OP_PUSHNIL,/* U - nil_1-nil_u */ 91OP_PUSHNIL,/* U - nil_1-nil_u */
92OP_POP,/* U a_u-a_1 - */ 92OP_POP,/* U a_u-a_1 - */
93 93
94OP_PUSHINT,/* S - (Number)s */ 94OP_PUSHINT,/* S - (lua_Number)s */
95OP_PUSHSTRING,/* K - KSTR[k] */ 95OP_PUSHSTRING,/* K - KSTR[k] */
96OP_PUSHNUM,/* N - KNUM[n] */ 96OP_PUSHNUM,/* N - KNUM[n] */
97OP_PUSHNEGNUM,/* N - -KNUM[n] */ 97OP_PUSHNEGNUM,/* N - -KNUM[n] */
diff --git a/lparser.c b/lparser.c
index b07557b9..d5df16d6 100644
--- a/lparser.c
+++ b/lparser.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lparser.c,v 1.117 2000/11/29 11:57:42 roberto Exp roberto $ 2** $Id: lparser.c,v 1.118 2000/11/30 18:50:47 roberto Exp roberto $
3** LL(1) Parser and code generator for Lua 3** LL(1) Parser and code generator for Lua
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -332,7 +332,7 @@ static void close_func (LexState *ls) {
332 luaK_getlabel(fs); /* close eventual list of pending jumps */ 332 luaK_getlabel(fs); /* close eventual list of pending jumps */
333 luaM_reallocvector(L, f->code, fs->pc, Instruction); 333 luaM_reallocvector(L, f->code, fs->pc, Instruction);
334 luaM_reallocvector(L, f->kstr, f->nkstr, TString *); 334 luaM_reallocvector(L, f->kstr, f->nkstr, TString *);
335 luaM_reallocvector(L, f->knum, f->nknum, Number); 335 luaM_reallocvector(L, f->knum, f->nknum, lua_Number);
336 luaM_reallocvector(L, f->kproto, f->nkproto, Proto *); 336 luaM_reallocvector(L, f->kproto, f->nkproto, Proto *);
337 removelocalvars(ls, fs->nactloc); 337 removelocalvars(ls, fs->nactloc);
338 luaM_reallocvector(L, f->locvars, f->nlocvars, LocVar); 338 luaM_reallocvector(L, f->locvars, f->nlocvars, LocVar);
@@ -608,7 +608,7 @@ static void simpleexp (LexState *ls, expdesc *v) {
608 FuncState *fs = ls->fs; 608 FuncState *fs = ls->fs;
609 switch (ls->t.token) { 609 switch (ls->t.token) {
610 case TK_NUMBER: { /* simpleexp -> NUMBER */ 610 case TK_NUMBER: { /* simpleexp -> NUMBER */
611 Number r = ls->t.seminfo.r; 611 lua_Number r = ls->t.seminfo.r;
612 next(ls); 612 next(ls);
613 luaK_number(fs, r); 613 luaK_number(fs, r);
614 break; 614 break;
diff --git a/ltable.c b/ltable.c
index 8782d33e..f9ccdd6c 100644
--- a/ltable.c
+++ b/ltable.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ltable.c,v 1.58 2000/10/26 12:47:05 roberto Exp roberto $ 2** $Id: ltable.c,v 1.59 2000/11/24 17:39:56 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*/
@@ -81,7 +81,7 @@ static const TObject *luaH_getany (lua_State *L, const Hash *t,
81 81
82 82
83/* specialized version for numbers */ 83/* specialized version for numbers */
84const TObject *luaH_getnum (const Hash *t, Number key) { 84const TObject *luaH_getnum (const Hash *t, lua_Number key) {
85 Node *n = &t->node[(luint32)(lint32)key&(t->size-1)]; 85 Node *n = &t->node[(luint32)(lint32)key&(t->size-1)];
86 do { 86 do {
87 if (ttype(&n->key) == LUA_TNUMBER && nvalue(&n->key) == key) 87 if (ttype(&n->key) == LUA_TNUMBER && nvalue(&n->key) == key)
@@ -290,7 +290,7 @@ TObject *luaH_setint (lua_State *L, Hash *t, int key) {
290} 290}
291 291
292 292
293void luaH_setstrnum (lua_State *L, Hash *t, TString *key, Number val) { 293void luaH_setstrnum (lua_State *L, Hash *t, TString *key, lua_Number val) {
294 TObject *value, index; 294 TObject *value, index;
295 ttype(&index) = LUA_TSTRING; 295 ttype(&index) = LUA_TSTRING;
296 tsvalue(&index) = key; 296 tsvalue(&index) = key;
diff --git a/ltable.h b/ltable.h
index be147e41..4027f0da 100644
--- a/ltable.h
+++ b/ltable.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ltable.h,v 1.24 2000/08/31 14:08:27 roberto Exp roberto $ 2** $Id: ltable.h,v 1.25 2000/11/24 17:39:56 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*/
@@ -17,13 +17,13 @@
17Hash *luaH_new (lua_State *L, int nhash); 17Hash *luaH_new (lua_State *L, int nhash);
18void luaH_free (lua_State *L, Hash *t); 18void luaH_free (lua_State *L, Hash *t);
19const TObject *luaH_get (lua_State *L, const Hash *t, const TObject *key); 19const TObject *luaH_get (lua_State *L, const Hash *t, const TObject *key);
20const TObject *luaH_getnum (const Hash *t, Number key); 20const TObject *luaH_getnum (const Hash *t, lua_Number key);
21const TObject *luaH_getstr (const Hash *t, TString *key); 21const TObject *luaH_getstr (const Hash *t, TString *key);
22void luaH_remove (Hash *t, TObject *key); 22void luaH_remove (Hash *t, TObject *key);
23TObject *luaH_set (lua_State *L, Hash *t, const TObject *key); 23TObject *luaH_set (lua_State *L, Hash *t, const TObject *key);
24Node * luaH_next (lua_State *L, const Hash *t, const TObject *r); 24Node * luaH_next (lua_State *L, const Hash *t, const TObject *r);
25TObject *luaH_setint (lua_State *L, Hash *t, int key); 25TObject *luaH_setint (lua_State *L, Hash *t, int key);
26void luaH_setstrnum (lua_State *L, Hash *t, TString *key, Number val); 26void luaH_setstrnum (lua_State *L, Hash *t, TString *key, lua_Number val);
27luint32 luaH_hash (lua_State *L, const TObject *key); 27luint32 luaH_hash (lua_State *L, const TObject *key);
28const TObject *luaH_getglobal (lua_State *L, const char *name); 28const TObject *luaH_getglobal (lua_State *L, const char *name);
29 29
diff --git a/lua.h b/lua.h
index 6fc3c2db..5f3b9af9 100644
--- a/lua.h
+++ b/lua.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lua.h,v 1.78 2000/10/30 12:38:50 roberto Exp roberto $ 2** $Id: lua.h,v 1.79 2000/10/31 12:44:07 roberto Exp roberto $
3** Lua - An Extensible Extension Language 3** Lua - An Extensible Extension Language
4** TeCGraf: Grupo de Tecnologia em Computacao Grafica, PUC-Rio, Brazil 4** TeCGraf: Grupo de Tecnologia em Computacao Grafica, PUC-Rio, Brazil
5** e-mail: lua@tecgraf.puc-rio.br 5** e-mail: lua@tecgraf.puc-rio.br
@@ -57,6 +57,9 @@
57#define LUA_ERRERR 5 57#define LUA_ERRERR 5
58 58
59 59
60/* Lua numerical type */
61typedef double lua_Number;
62
60typedef struct lua_State lua_State; 63typedef struct lua_State lua_State;
61 64
62typedef int (*lua_CFunction) (lua_State *L); 65typedef int (*lua_CFunction) (lua_State *L);
@@ -107,7 +110,7 @@ LUA_API int lua_tag (lua_State *L, int index);
107LUA_API int lua_equal (lua_State *L, int index1, int index2); 110LUA_API int lua_equal (lua_State *L, int index1, int index2);
108LUA_API int lua_lessthan (lua_State *L, int index1, int index2); 111LUA_API int lua_lessthan (lua_State *L, int index1, int index2);
109 112
110LUA_API double lua_tonumber (lua_State *L, int index); 113LUA_API lua_Number lua_tonumber (lua_State *L, int index);
111LUA_API const char *lua_tostring (lua_State *L, int index); 114LUA_API const char *lua_tostring (lua_State *L, int index);
112LUA_API size_t lua_strlen (lua_State *L, int index); 115LUA_API size_t lua_strlen (lua_State *L, int index);
113LUA_API lua_CFunction lua_tocfunction (lua_State *L, int index); 116LUA_API lua_CFunction lua_tocfunction (lua_State *L, int index);
@@ -119,7 +122,7 @@ LUA_API const void *lua_topointer (lua_State *L, int index);
119** push functions (C -> stack) 122** push functions (C -> stack)
120*/ 123*/
121LUA_API void lua_pushnil (lua_State *L); 124LUA_API void lua_pushnil (lua_State *L);
122LUA_API void lua_pushnumber (lua_State *L, double n); 125LUA_API void lua_pushnumber (lua_State *L, lua_Number n);
123LUA_API void lua_pushlstring (lua_State *L, const char *s, size_t len); 126LUA_API void lua_pushlstring (lua_State *L, const char *s, size_t len);
124LUA_API void lua_pushstring (lua_State *L, const char *s); 127LUA_API void lua_pushstring (lua_State *L, const char *s);
125LUA_API void lua_pushcclosure (lua_State *L, lua_CFunction fn, int n); 128LUA_API void lua_pushcclosure (lua_State *L, lua_CFunction fn, int n);
diff --git a/lundump.c b/lundump.c
index a8d06106..b367fe36 100644
--- a/lundump.c
+++ b/lundump.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lundump.c,v 1.33 2000/10/31 16:57:23 lhf Exp $ 2** $Id: lundump.c,v 1.34 2000/11/07 12:44:44 roberto Exp roberto $
3** load bytecodes from files 3** load bytecodes from files
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -82,9 +82,9 @@ static size_t LoadSize (lua_State* L, ZIO* Z, int swap)
82 return x; 82 return x;
83} 83}
84 84
85static Number LoadNumber (lua_State* L, ZIO* Z, int swap) 85static lua_Number LoadNumber (lua_State* L, ZIO* Z, int swap)
86{ 86{
87 Number x; 87 lua_Number x;
88 LoadBlock(L,&x,sizeof(x),Z,swap); 88 LoadBlock(L,&x,sizeof(x),Z,swap);
89 return x; 89 return x;
90} 90}
@@ -142,7 +142,7 @@ static void LoadConstants (lua_State* L, Proto* tf, ZIO* Z, int swap)
142 for (i=0; i<n; i++) 142 for (i=0; i<n; i++)
143 tf->kstr[i]=LoadString(L,Z,swap); 143 tf->kstr[i]=LoadString(L,Z,swap);
144 tf->nknum=n=LoadInt(L,Z,swap); 144 tf->nknum=n=LoadInt(L,Z,swap);
145 tf->knum=luaM_newvector(L,n,Number); 145 tf->knum=luaM_newvector(L,n,lua_Number);
146 LoadVector(L,tf->knum,n,sizeof(*tf->knum),Z,swap); 146 LoadVector(L,tf->knum,n,sizeof(*tf->knum),Z,swap);
147 tf->nkproto=n=LoadInt(L,Z,swap); 147 tf->nkproto=n=LoadInt(L,Z,swap);
148 tf->kproto=luaM_newvector(L,n,Proto*); 148 tf->kproto=luaM_newvector(L,n,Proto*);
@@ -187,7 +187,7 @@ static void TestSize (lua_State* L, int s, const char* what, ZIO* Z)
187static int LoadHeader (lua_State* L, ZIO* Z) 187static int LoadHeader (lua_State* L, ZIO* Z)
188{ 188{
189 int version,swap; 189 int version,swap;
190 Number f=0,tf=TEST_NUMBER; 190 lua_Number f=0,tf=TEST_NUMBER;
191 LoadSignature(L,Z); 191 LoadSignature(L,Z);
192 version=ezgetc(L,Z); 192 version=ezgetc(L,Z);
193 if (version>VERSION) 193 if (version>VERSION)
@@ -205,7 +205,7 @@ static int LoadHeader (lua_State* L, ZIO* Z)
205 TESTSIZE(SIZE_INSTRUCTION); 205 TESTSIZE(SIZE_INSTRUCTION);
206 TESTSIZE(SIZE_OP); 206 TESTSIZE(SIZE_OP);
207 TESTSIZE(SIZE_B); 207 TESTSIZE(SIZE_B);
208 TESTSIZE(sizeof(Number)); 208 TESTSIZE(sizeof(lua_Number));
209 f=LoadNumber(L,Z,swap); 209 f=LoadNumber(L,Z,swap);
210 if ((long)f!=(long)tf) /* disregard errors in last bit of fraction */ 210 if ((long)f!=(long)tf) /* disregard errors in last bit of fraction */
211 luaO_verror(L,"unknown number format in `%.99s':\n" 211 luaO_verror(L,"unknown number format in `%.99s':\n"
diff --git a/lvm.c b/lvm.c
index 8c9407e7..d49ed9e4 100644
--- a/lvm.c
+++ b/lvm.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lvm.c,v 1.146 2000/10/26 12:47:05 roberto Exp roberto $ 2** $Id: lvm.c,v 1.147 2000/11/24 17:39:56 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*/
@@ -402,7 +402,7 @@ StkId luaV_execute (lua_State *L, const Closure *cl, StkId base) {
402 } 402 }
403 case OP_PUSHINT: { 403 case OP_PUSHINT: {
404 ttype(top) = LUA_TNUMBER; 404 ttype(top) = LUA_TNUMBER;
405 nvalue(top) = (Number)GETARG_S(i); 405 nvalue(top) = (lua_Number)GETARG_S(i);
406 top++; 406 top++;
407 break; 407 break;
408 } 408 }
@@ -523,11 +523,11 @@ StkId luaV_execute (lua_State *L, const Closure *cl, StkId base) {
523 case OP_ADDI: { 523 case OP_ADDI: {
524 if (tonumber(top-1)) { 524 if (tonumber(top-1)) {
525 ttype(top) = LUA_TNUMBER; 525 ttype(top) = LUA_TNUMBER;
526 nvalue(top) = (Number)GETARG_S(i); 526 nvalue(top) = (lua_Number)GETARG_S(i);
527 call_arith(L, top+1, TM_ADD); 527 call_arith(L, top+1, TM_ADD);
528 } 528 }
529 else 529 else
530 nvalue(top-1) += (Number)GETARG_S(i); 530 nvalue(top-1) += (lua_Number)GETARG_S(i);
531 break; 531 break;
532 } 532 }
533 case OP_SUB: { 533 case OP_SUB: {