diff options
-rw-r--r-- | lapi.c | 4 | ||||
-rw-r--r-- | lauxlib.c | 4 | ||||
-rw-r--r-- | lauxlib.h | 4 | ||||
-rw-r--r-- | ldo.c | 4 | ||||
-rw-r--r-- | llex.c | 318 | ||||
-rw-r--r-- | lstate.h | 12 | ||||
-rw-r--r-- | lstring.c | 4 | ||||
-rw-r--r-- | ltable.c | 4 | ||||
-rw-r--r-- | lua.c | 4 | ||||
-rw-r--r-- | lua.stx | 4 | ||||
-rw-r--r-- | lvm.c | 210 | ||||
-rw-r--r-- | lzio.c | 14 | ||||
-rw-r--r-- | lzio.h | 10 |
13 files changed, 301 insertions, 295 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lapi.c,v 1.5 1997/11/19 17:29:23 roberto Exp roberto $ | 2 | ** $Id: lapi.c,v 1.6 1997/11/19 18:16:33 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 | */ |
@@ -270,7 +270,7 @@ int lua_isfunction (lua_Object o) | |||
270 | real lua_getnumber (lua_Object object) | 270 | real lua_getnumber (lua_Object object) |
271 | { | 271 | { |
272 | if (object == LUA_NOOBJECT) return 0.0; | 272 | if (object == LUA_NOOBJECT) return 0.0; |
273 | if (tonumber (Address(object))) return 0.0; | 273 | if (tonumber(Address(object))) return 0.0; |
274 | else return (nvalue(Address(object))); | 274 | else return (nvalue(Address(object))); |
275 | } | 275 | } |
276 | 276 | ||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lauxlib.c,v 1.2 1997/09/26 15:02:26 roberto Exp roberto $ | 2 | ** $Id: lauxlib.c,v 1.3 1997/11/04 15:27:53 roberto Exp roberto $ |
3 | ** Auxiliar functions for building Lua libraries | 3 | ** Auxiliar functions for building Lua libraries |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -15,7 +15,7 @@ | |||
15 | 15 | ||
16 | 16 | ||
17 | 17 | ||
18 | void luaL_arg_check(int cond, int numarg, char *extramsg) | 18 | void luaL_arg_check (int cond, int numarg, char *extramsg) |
19 | { | 19 | { |
20 | if (!cond) { | 20 | if (!cond) { |
21 | char *funcname; | 21 | char *funcname; |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lauxlib.h,v 1.1 1997/09/16 19:25:59 roberto Exp roberto $ | 2 | ** $Id: lauxlib.h,v 1.2 1997/09/26 15:02:26 roberto Exp roberto $ |
3 | ** Auxiliar functions for building Lua libraries | 3 | ** Auxiliar functions for building Lua libraries |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -18,7 +18,7 @@ struct luaL_reg { | |||
18 | }; | 18 | }; |
19 | 19 | ||
20 | void luaL_openlib (struct luaL_reg *l, int n); | 20 | void luaL_openlib (struct luaL_reg *l, int n); |
21 | void luaL_arg_check(int cond, int numarg, char *extramsg); | 21 | void luaL_arg_check (int cond, int numarg, char *extramsg); |
22 | char *luaL_check_string (int numArg); | 22 | char *luaL_check_string (int numArg); |
23 | char *luaL_opt_string (int numArg, char *def); | 23 | char *luaL_opt_string (int numArg, char *def); |
24 | double luaL_check_number (int numArg); | 24 | double luaL_check_number (int numArg); |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ldo.c,v 1.8 1997/11/07 15:09:49 roberto Exp roberto $ | 2 | ** $Id: ldo.c,v 1.9 1997/11/19 17:29:23 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 | */ |
@@ -224,7 +224,7 @@ void luaD_travstack (int (*fn)(TObject *)) | |||
224 | { | 224 | { |
225 | StkId i; | 225 | StkId i; |
226 | for (i = (L->stack.top-1)-L->stack.stack; i>=0; i--) | 226 | for (i = (L->stack.top-1)-L->stack.stack; i>=0; i--) |
227 | fn (L->stack.stack+i); | 227 | fn(L->stack.stack+i); |
228 | } | 228 | } |
229 | 229 | ||
230 | 230 | ||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: llex.c,v 1.6 1997/11/19 17:29:23 roberto Exp roberto $ | 2 | ** $Id: llex.c,v 1.7 1997/11/19 17:35:47 roberto Exp roberto $ |
3 | ** Lexical Analizer | 3 | ** Lexical Analizer |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -23,7 +23,7 @@ | |||
23 | int lua_debug=0; | 23 | int lua_debug=0; |
24 | 24 | ||
25 | 25 | ||
26 | #define next(LL) (LL->current = zgetc(LL->lex_z)) | 26 | #define next(LS) (LS->current = zgetc(LS->lex_z)) |
27 | 27 | ||
28 | 28 | ||
29 | static struct { | 29 | static struct { |
@@ -46,29 +46,29 @@ void luaX_init (void) | |||
46 | } | 46 | } |
47 | 47 | ||
48 | 48 | ||
49 | static void firstline (LexState *LL) | 49 | static void firstline (LexState *LS) |
50 | { | 50 | { |
51 | int c = zgetc(LL->lex_z); | 51 | int c = zgetc(LS->lex_z); |
52 | if (c == '#') | 52 | if (c == '#') |
53 | while((c=zgetc(LL->lex_z)) != '\n' && c != EOZ) /* skip first line */; | 53 | while ((c=zgetc(LS->lex_z)) != '\n' && c != EOZ) /* skip first line */; |
54 | zungetc(LL->lex_z); | 54 | zungetc(LS->lex_z); |
55 | } | 55 | } |
56 | 56 | ||
57 | 57 | ||
58 | void luaX_setinput (ZIO *z) | 58 | void luaX_setinput (ZIO *z) |
59 | { | 59 | { |
60 | LexState *LL = L->lexstate; | 60 | LexState *LS = L->lexstate; |
61 | LL->current = '\n'; | 61 | LS->current = '\n'; |
62 | LL->linelasttoken = 0; | 62 | LS->linelasttoken = 0; |
63 | LL->lastline = 0; | 63 | LS->lastline = 0; |
64 | LL->linenumber = 0; | 64 | LS->linenumber = 0; |
65 | LL->iflevel = 0; | 65 | LS->iflevel = 0; |
66 | LL->ifstate[0].skip = 0; | 66 | LS->ifstate[0].skip = 0; |
67 | LL->ifstate[0].elsepart = 1; /* to avoid a free $else */ | 67 | LS->ifstate[0].elsepart = 1; /* to avoid a free $else */ |
68 | LL->lex_z = z; | 68 | LS->lex_z = z; |
69 | firstline(LL); | 69 | firstline(LS); |
70 | LL->textbuff.buffsize = 20; | 70 | LS->textbuff.buffsize = 20; |
71 | LL->textbuff.text = luaM_buffer(LL->textbuff.buffsize); | 71 | LS->textbuff.text = luaM_buffer(LS->textbuff.buffsize); |
72 | } | 72 | } |
73 | 73 | ||
74 | 74 | ||
@@ -81,10 +81,10 @@ void luaX_setinput (ZIO *z) | |||
81 | 81 | ||
82 | #define PRAGMASIZE 20 | 82 | #define PRAGMASIZE 20 |
83 | 83 | ||
84 | static void skipspace (LexState *LL) | 84 | static void skipspace (LexState *LS) |
85 | { | 85 | { |
86 | while (LL->current == ' ' || LL->current == '\t' || LL->current == '\r') | 86 | while (LS->current == ' ' || LS->current == '\t' || LS->current == '\r') |
87 | next(LL); | 87 | next(LS); |
88 | } | 88 | } |
89 | 89 | ||
90 | 90 | ||
@@ -102,49 +102,49 @@ static int checkcond (char *buff) | |||
102 | } | 102 | } |
103 | 103 | ||
104 | 104 | ||
105 | static void readname (LexState *LL, char *buff) | 105 | static void readname (LexState *LS, char *buff) |
106 | { | 106 | { |
107 | int i = 0; | 107 | int i = 0; |
108 | skipspace(LL); | 108 | skipspace(LS); |
109 | while (isalnum(LL->current) || LL->current == '_') { | 109 | while (isalnum(LS->current) || LS->current == '_') { |
110 | if (i >= PRAGMASIZE) { | 110 | if (i >= PRAGMASIZE) { |
111 | buff[PRAGMASIZE] = 0; | 111 | buff[PRAGMASIZE] = 0; |
112 | luaY_syntaxerror("pragma too long", buff); | 112 | luaY_syntaxerror("pragma too long", buff); |
113 | } | 113 | } |
114 | buff[i++] = LL->current; | 114 | buff[i++] = LS->current; |
115 | next(LL); | 115 | next(LS); |
116 | } | 116 | } |
117 | buff[i] = 0; | 117 | buff[i] = 0; |
118 | } | 118 | } |
119 | 119 | ||
120 | 120 | ||
121 | static void inclinenumber (LexState *LL); | 121 | static void inclinenumber (LexState *LS); |
122 | 122 | ||
123 | 123 | ||
124 | static void ifskip (LexState *LL) | 124 | static void ifskip (LexState *LS) |
125 | { | 125 | { |
126 | while (LL->ifstate[LL->iflevel].skip) { | 126 | while (LS->ifstate[LS->iflevel].skip) { |
127 | if (LL->current == '\n') | 127 | if (LS->current == '\n') |
128 | inclinenumber(LL); | 128 | inclinenumber(LS); |
129 | else if (LL->current == EOZ) | 129 | else if (LS->current == EOZ) |
130 | luaY_syntaxerror("input ends inside a $if", ""); | 130 | luaY_syntaxerror("input ends inside a $if", ""); |
131 | else next(LL); | 131 | else next(LS); |
132 | } | 132 | } |
133 | } | 133 | } |
134 | 134 | ||
135 | 135 | ||
136 | static void inclinenumber (LexState *LL) | 136 | static void inclinenumber (LexState *LS) |
137 | { | 137 | { |
138 | static char *pragmas [] = | 138 | static char *pragmas [] = |
139 | {"debug", "nodebug", "endinput", "end", "ifnot", "if", "else", NULL}; | 139 | {"debug", "nodebug", "endinput", "end", "ifnot", "if", "else", NULL}; |
140 | next(LL); /* skip '\n' */ | 140 | next(LS); /* skip '\n' */ |
141 | ++LL->linenumber; | 141 | ++LS->linenumber; |
142 | if (LL->current == '$') { /* is a pragma? */ | 142 | if (LS->current == '$') { /* is a pragma? */ |
143 | char buff[PRAGMASIZE+1]; | 143 | char buff[PRAGMASIZE+1]; |
144 | int ifnot = 0; | 144 | int ifnot = 0; |
145 | int skip = LL->ifstate[LL->iflevel].skip; | 145 | int skip = LS->ifstate[LS->iflevel].skip; |
146 | next(LL); /* skip $ */ | 146 | next(LS); /* skip $ */ |
147 | readname(LL, buff); | 147 | readname(LS, buff); |
148 | switch (luaO_findstring(buff, pragmas)) { | 148 | switch (luaO_findstring(buff, pragmas)) { |
149 | case 0: /* debug */ | 149 | case 0: /* debug */ |
150 | if (!skip) lua_debug = 1; | 150 | if (!skip) lua_debug = 1; |
@@ -154,42 +154,42 @@ static void inclinenumber (LexState *LL) | |||
154 | break; | 154 | break; |
155 | case 2: /* endinput */ | 155 | case 2: /* endinput */ |
156 | if (!skip) { | 156 | if (!skip) { |
157 | LL->current = EOZ; | 157 | LS->current = EOZ; |
158 | LL->iflevel = 0; /* to allow $endinput inside a $if */ | 158 | LS->iflevel = 0; /* to allow $endinput inside a $if */ |
159 | } | 159 | } |
160 | break; | 160 | break; |
161 | case 3: /* end */ | 161 | case 3: /* end */ |
162 | if (LL->iflevel-- == 0) | 162 | if (LS->iflevel-- == 0) |
163 | luaY_syntaxerror("unmatched $end", "$end"); | 163 | luaY_syntaxerror("unmatched $end", "$end"); |
164 | break; | 164 | break; |
165 | case 4: /* ifnot */ | 165 | case 4: /* ifnot */ |
166 | ifnot = 1; | 166 | ifnot = 1; |
167 | /* go through */ | 167 | /* go through */ |
168 | case 5: /* if */ | 168 | case 5: /* if */ |
169 | if (LL->iflevel == MAX_IFS-1) | 169 | if (LS->iflevel == MAX_IFS-1) |
170 | luaY_syntaxerror("too many nested `$ifs'", "$if"); | 170 | luaY_syntaxerror("too many nested `$ifs'", "$if"); |
171 | readname(LL, buff); | 171 | readname(LS, buff); |
172 | LL->iflevel++; | 172 | LS->iflevel++; |
173 | LL->ifstate[LL->iflevel].elsepart = 0; | 173 | LS->ifstate[LS->iflevel].elsepart = 0; |
174 | LL->ifstate[LL->iflevel].condition = checkcond(buff) ? !ifnot : ifnot; | 174 | LS->ifstate[LS->iflevel].condition = checkcond(buff) ? !ifnot : ifnot; |
175 | LL->ifstate[LL->iflevel].skip = skip || !LL->ifstate[LL->iflevel].condition; | 175 | LS->ifstate[LS->iflevel].skip = skip || !LS->ifstate[LS->iflevel].condition; |
176 | break; | 176 | break; |
177 | case 6: /* else */ | 177 | case 6: /* else */ |
178 | if (LL->ifstate[LL->iflevel].elsepart) | 178 | if (LS->ifstate[LS->iflevel].elsepart) |
179 | luaY_syntaxerror("unmatched $else", "$else"); | 179 | luaY_syntaxerror("unmatched $else", "$else"); |
180 | LL->ifstate[LL->iflevel].elsepart = 1; | 180 | LS->ifstate[LS->iflevel].elsepart = 1; |
181 | LL->ifstate[LL->iflevel].skip = LL->ifstate[LL->iflevel-1].skip || | 181 | LS->ifstate[LS->iflevel].skip = LS->ifstate[LS->iflevel-1].skip || |
182 | LL->ifstate[LL->iflevel].condition; | 182 | LS->ifstate[LS->iflevel].condition; |
183 | break; | 183 | break; |
184 | default: | 184 | default: |
185 | luaY_syntaxerror("invalid pragma", buff); | 185 | luaY_syntaxerror("invalid pragma", buff); |
186 | } | 186 | } |
187 | skipspace(LL); | 187 | skipspace(LS); |
188 | if (LL->current == '\n') /* pragma must end with a '\n' ... */ | 188 | if (LS->current == '\n') /* pragma must end with a '\n' ... */ |
189 | inclinenumber(LL); | 189 | inclinenumber(LS); |
190 | else if (LL->current != EOZ) /* or eof */ | 190 | else if (LS->current != EOZ) /* or eof */ |
191 | luaY_syntaxerror("invalid pragma format", buff); | 191 | luaY_syntaxerror("invalid pragma format", buff); |
192 | ifskip(LL); | 192 | ifskip(LS); |
193 | } | 193 | } |
194 | } | 194 | } |
195 | 195 | ||
@@ -202,11 +202,11 @@ static void inclinenumber (LexState *LL) | |||
202 | 202 | ||
203 | 203 | ||
204 | 204 | ||
205 | static void save (LexState *LL, int c) | 205 | static void save (LexState *LS, int c) |
206 | { | 206 | { |
207 | if (LL->textbuff.tokensize >= LL->textbuff.buffsize) | 207 | if (LS->textbuff.tokensize >= LS->textbuff.buffsize) |
208 | LL->textbuff.text = luaM_buffer(LL->textbuff.buffsize *= 2); | 208 | LS->textbuff.text = luaM_buffer(LS->textbuff.buffsize *= 2); |
209 | LL->textbuff.text[LL->textbuff.tokensize++] = c; | 209 | LS->textbuff.text[LS->textbuff.tokensize++] = c; |
210 | } | 210 | } |
211 | 211 | ||
212 | 212 | ||
@@ -217,44 +217,44 @@ char *luaX_lasttoken (void) | |||
217 | } | 217 | } |
218 | 218 | ||
219 | 219 | ||
220 | #define save_and_next(LL) (save(LL, LL->current), next(LL)) | 220 | #define save_and_next(LS) (save(LS, LS->current), next(LS)) |
221 | 221 | ||
222 | 222 | ||
223 | static int read_long_string (LexState *LL, YYSTYPE *l) | 223 | static int read_long_string (LexState *LS, YYSTYPE *l) |
224 | { | 224 | { |
225 | int cont = 0; | 225 | int cont = 0; |
226 | while (1) { | 226 | while (1) { |
227 | switch (LL->current) { | 227 | switch (LS->current) { |
228 | case EOZ: | 228 | case EOZ: |
229 | save(LL, 0); | 229 | save(LS, 0); |
230 | return WRONGTOKEN; | 230 | return WRONGTOKEN; |
231 | case '[': | 231 | case '[': |
232 | save_and_next(LL); | 232 | save_and_next(LS); |
233 | if (LL->current == '[') { | 233 | if (LS->current == '[') { |
234 | cont++; | 234 | cont++; |
235 | save_and_next(LL); | 235 | save_and_next(LS); |
236 | } | 236 | } |
237 | continue; | 237 | continue; |
238 | case ']': | 238 | case ']': |
239 | save_and_next(LL); | 239 | save_and_next(LS); |
240 | if (LL->current == ']') { | 240 | if (LS->current == ']') { |
241 | if (cont == 0) goto endloop; | 241 | if (cont == 0) goto endloop; |
242 | cont--; | 242 | cont--; |
243 | save_and_next(LL); | 243 | save_and_next(LS); |
244 | } | 244 | } |
245 | continue; | 245 | continue; |
246 | case '\n': | 246 | case '\n': |
247 | save(LL, '\n'); | 247 | save(LS, '\n'); |
248 | inclinenumber(LL); | 248 | inclinenumber(LS); |
249 | continue; | 249 | continue; |
250 | default: | 250 | default: |
251 | save_and_next(LL); | 251 | save_and_next(LS); |
252 | } | 252 | } |
253 | } endloop: | 253 | } endloop: |
254 | save_and_next(LL); /* pass the second ']' */ | 254 | save_and_next(LS); /* pass the second ']' */ |
255 | LL->textbuff.text[LL->textbuff.tokensize-2] = 0; /* erases ']]' */ | 255 | LS->textbuff.text[LS->textbuff.tokensize-2] = 0; /* erases ']]' */ |
256 | l->pTStr = luaS_new(LL->textbuff.text+2); | 256 | l->pTStr = luaS_new(LS->textbuff.text+2); |
257 | LL->textbuff.text[LL->textbuff.tokensize-2] = ']'; /* restores ']]' */ | 257 | LS->textbuff.text[LS->textbuff.tokensize-2] = ']'; /* restores ']]' */ |
258 | return STRING; | 258 | return STRING; |
259 | } | 259 | } |
260 | 260 | ||
@@ -266,103 +266,103 @@ static int read_long_string (LexState *LL, YYSTYPE *l) | |||
266 | int luaY_lex (YYSTYPE *l); | 266 | int luaY_lex (YYSTYPE *l); |
267 | int luaY_lex (YYSTYPE *l) | 267 | int luaY_lex (YYSTYPE *l) |
268 | { | 268 | { |
269 | LexState *LL = L->lexstate; | 269 | LexState *LS = L->lexstate; |
270 | double a; | 270 | double a; |
271 | LL->textbuff.tokensize = 0; | 271 | LS->textbuff.tokensize = 0; |
272 | if (lua_debug) | 272 | if (lua_debug) |
273 | luaY_codedebugline(LL->linelasttoken); | 273 | luaY_codedebugline(LS->linelasttoken); |
274 | LL->linelasttoken = LL->linenumber; | 274 | LS->linelasttoken = LS->linenumber; |
275 | while (1) { | 275 | while (1) { |
276 | switch (LL->current) { | 276 | switch (LS->current) { |
277 | case '\n': | 277 | case '\n': |
278 | inclinenumber(LL); | 278 | inclinenumber(LS); |
279 | LL->linelasttoken = LL->linenumber; | 279 | LS->linelasttoken = LS->linenumber; |
280 | continue; | 280 | continue; |
281 | 281 | ||
282 | case ' ': case '\t': case '\r': /* CR: to avoid problems with DOS */ | 282 | case ' ': case '\t': case '\r': /* CR: to avoid problems with DOS */ |
283 | next(LL); | 283 | next(LS); |
284 | continue; | 284 | continue; |
285 | 285 | ||
286 | case '-': | 286 | case '-': |
287 | save_and_next(LL); | 287 | save_and_next(LS); |
288 | if (LL->current != '-') return '-'; | 288 | if (LS->current != '-') return '-'; |
289 | do { next(LL); } while (LL->current != '\n' && LL->current != EOZ); | 289 | do { next(LS); } while (LS->current != '\n' && LS->current != EOZ); |
290 | LL->textbuff.tokensize = 0; | 290 | LS->textbuff.tokensize = 0; |
291 | continue; | 291 | continue; |
292 | 292 | ||
293 | case '[': | 293 | case '[': |
294 | save_and_next(LL); | 294 | save_and_next(LS); |
295 | if (LL->current != '[') return '['; | 295 | if (LS->current != '[') return '['; |
296 | else { | 296 | else { |
297 | save_and_next(LL); /* pass the second '[' */ | 297 | save_and_next(LS); /* pass the second '[' */ |
298 | return read_long_string(LL, l); | 298 | return read_long_string(LS, l); |
299 | } | 299 | } |
300 | 300 | ||
301 | case '=': | 301 | case '=': |
302 | save_and_next(LL); | 302 | save_and_next(LS); |
303 | if (LL->current != '=') return '='; | 303 | if (LS->current != '=') return '='; |
304 | else { save_and_next(LL); return EQ; } | 304 | else { save_and_next(LS); return EQ; } |
305 | 305 | ||
306 | case '<': | 306 | case '<': |
307 | save_and_next(LL); | 307 | save_and_next(LS); |
308 | if (LL->current != '=') return '<'; | 308 | if (LS->current != '=') return '<'; |
309 | else { save_and_next(LL); return LE; } | 309 | else { save_and_next(LS); return LE; } |
310 | 310 | ||
311 | case '>': | 311 | case '>': |
312 | save_and_next(LL); | 312 | save_and_next(LS); |
313 | if (LL->current != '=') return '>'; | 313 | if (LS->current != '=') return '>'; |
314 | else { save_and_next(LL); return GE; } | 314 | else { save_and_next(LS); return GE; } |
315 | 315 | ||
316 | case '~': | 316 | case '~': |
317 | save_and_next(LL); | 317 | save_and_next(LS); |
318 | if (LL->current != '=') return '~'; | 318 | if (LS->current != '=') return '~'; |
319 | else { save_and_next(LL); return NE; } | 319 | else { save_and_next(LS); return NE; } |
320 | 320 | ||
321 | case '"': | 321 | case '"': |
322 | case '\'': { | 322 | case '\'': { |
323 | int del = LL->current; | 323 | int del = LS->current; |
324 | save_and_next(LL); | 324 | save_and_next(LS); |
325 | while (LL->current != del) { | 325 | while (LS->current != del) { |
326 | switch (LL->current) { | 326 | switch (LS->current) { |
327 | case EOZ: | 327 | case EOZ: |
328 | case '\n': | 328 | case '\n': |
329 | save(LL, 0); | 329 | save(LS, 0); |
330 | return WRONGTOKEN; | 330 | return WRONGTOKEN; |
331 | case '\\': | 331 | case '\\': |
332 | next(LL); /* do not save the '\' */ | 332 | next(LS); /* do not save the '\' */ |
333 | switch (LL->current) { | 333 | switch (LS->current) { |
334 | case 'n': save(LL, '\n'); next(LL); break; | 334 | case 'n': save(LS, '\n'); next(LS); break; |
335 | case 't': save(LL, '\t'); next(LL); break; | 335 | case 't': save(LS, '\t'); next(LS); break; |
336 | case 'r': save(LL, '\r'); next(LL); break; | 336 | case 'r': save(LS, '\r'); next(LS); break; |
337 | case '\n': save(LL, '\n'); inclinenumber(LL); break; | 337 | case '\n': save(LS, '\n'); inclinenumber(LS); break; |
338 | default : save_and_next(LL); break; | 338 | default : save_and_next(LS); break; |
339 | } | 339 | } |
340 | break; | 340 | break; |
341 | default: | 341 | default: |
342 | save_and_next(LL); | 342 | save_and_next(LS); |
343 | } | 343 | } |
344 | } | 344 | } |
345 | next(LL); /* skip delimiter */ | 345 | next(LS); /* skip delimiter */ |
346 | save(LL, 0); | 346 | save(LS, 0); |
347 | l->pTStr = luaS_new(LL->textbuff.text+1); | 347 | l->pTStr = luaS_new(LS->textbuff.text+1); |
348 | LL->textbuff.text[LL->textbuff.tokensize-1] = del; /* restore delimiter */ | 348 | LS->textbuff.text[LS->textbuff.tokensize-1] = del; /* restore delimiter */ |
349 | return STRING; | 349 | return STRING; |
350 | } | 350 | } |
351 | 351 | ||
352 | case '.': | 352 | case '.': |
353 | save_and_next(LL); | 353 | save_and_next(LS); |
354 | if (LL->current == '.') | 354 | if (LS->current == '.') |
355 | { | 355 | { |
356 | save_and_next(LL); | 356 | save_and_next(LS); |
357 | if (LL->current == '.') | 357 | if (LS->current == '.') |
358 | { | 358 | { |
359 | save_and_next(LL); | 359 | save_and_next(LS); |
360 | return DOTS; /* ... */ | 360 | return DOTS; /* ... */ |
361 | } | 361 | } |
362 | else return CONC; /* .. */ | 362 | else return CONC; /* .. */ |
363 | } | 363 | } |
364 | else if (!isdigit(LL->current)) return '.'; | 364 | else if (!isdigit(LS->current)) return '.'; |
365 | /* LL->current is a digit: goes through to number */ | 365 | /* LS->current is a digit: goes through to number */ |
366 | a=0.0; | 366 | a=0.0; |
367 | goto fraction; | 367 | goto fraction; |
368 | 368 | ||
@@ -370,38 +370,38 @@ int luaY_lex (YYSTYPE *l) | |||
370 | case '5': case '6': case '7': case '8': case '9': | 370 | case '5': case '6': case '7': case '8': case '9': |
371 | a=0.0; | 371 | a=0.0; |
372 | do { | 372 | do { |
373 | a=10.0*a+(LL->current-'0'); | 373 | a=10.0*a+(LS->current-'0'); |
374 | save_and_next(LL); | 374 | save_and_next(LS); |
375 | } while (isdigit(LL->current)); | 375 | } while (isdigit(LS->current)); |
376 | if (LL->current == '.') { | 376 | if (LS->current == '.') { |
377 | save_and_next(LL); | 377 | save_and_next(LS); |
378 | if (LL->current == '.') { | 378 | if (LS->current == '.') { |
379 | save(LL, 0); | 379 | save(LS, 0); |
380 | luaY_error( | 380 | luaY_error( |
381 | "ambiguous syntax (decimal point x string concatenation)"); | 381 | "ambiguous syntax (decimal point x string concatenation)"); |
382 | } | 382 | } |
383 | } | 383 | } |
384 | fraction: | 384 | fraction: |
385 | { double da=0.1; | 385 | { double da=0.1; |
386 | while (isdigit(LL->current)) | 386 | while (isdigit(LS->current)) |
387 | { | 387 | { |
388 | a+=(LL->current-'0')*da; | 388 | a+=(LS->current-'0')*da; |
389 | da/=10.0; | 389 | da/=10.0; |
390 | save_and_next(LL); | 390 | save_and_next(LS); |
391 | } | 391 | } |
392 | if (toupper(LL->current) == 'E') { | 392 | if (toupper(LS->current) == 'E') { |
393 | int e=0; | 393 | int e=0; |
394 | int neg; | 394 | int neg; |
395 | double ea; | 395 | double ea; |
396 | save_and_next(LL); | 396 | save_and_next(LS); |
397 | neg=(LL->current=='-'); | 397 | neg=(LS->current=='-'); |
398 | if (LL->current == '+' || LL->current == '-') save_and_next(LL); | 398 | if (LS->current == '+' || LS->current == '-') save_and_next(LS); |
399 | if (!isdigit(LL->current)) { | 399 | if (!isdigit(LS->current)) { |
400 | save(LL, 0); return WRONGTOKEN; } | 400 | save(LS, 0); return WRONGTOKEN; } |
401 | do { | 401 | do { |
402 | e=10.0*e+(LL->current-'0'); | 402 | e=10.0*e+(LS->current-'0'); |
403 | save_and_next(LL); | 403 | save_and_next(LS); |
404 | } while (isdigit(LL->current)); | 404 | } while (isdigit(LS->current)); |
405 | for (ea=neg?0.1:10.0; e>0; e>>=1) | 405 | for (ea=neg?0.1:10.0; e>0; e>>=1) |
406 | { | 406 | { |
407 | if (e & 1) a*=ea; | 407 | if (e & 1) a*=ea; |
@@ -413,23 +413,23 @@ int luaY_lex (YYSTYPE *l) | |||
413 | } | 413 | } |
414 | 414 | ||
415 | case EOZ: | 415 | case EOZ: |
416 | save(LL, 0); | 416 | save(LS, 0); |
417 | if (LL->iflevel > 0) | 417 | if (LS->iflevel > 0) |
418 | luaY_error("missing $endif"); | 418 | luaY_error("missing $endif"); |
419 | return 0; | 419 | return 0; |
420 | 420 | ||
421 | default: | 421 | default: |
422 | if (LL->current != '_' && !isalpha(LL->current)) { | 422 | if (LS->current != '_' && !isalpha(LS->current)) { |
423 | save_and_next(LL); | 423 | save_and_next(LS); |
424 | return LL->textbuff.text[0]; | 424 | return LS->textbuff.text[0]; |
425 | } | 425 | } |
426 | else { /* identifier or reserved word */ | 426 | else { /* identifier or reserved word */ |
427 | TaggedString *ts; | 427 | TaggedString *ts; |
428 | do { | 428 | do { |
429 | save_and_next(LL); | 429 | save_and_next(LS); |
430 | } while (isalnum(LL->current) || LL->current == '_'); | 430 | } while (isalnum(LS->current) || LS->current == '_'); |
431 | save(LL, 0); | 431 | save(LS, 0); |
432 | ts = luaS_new(LL->textbuff.text); | 432 | ts = luaS_new(LS->textbuff.text); |
433 | if (ts->head.marked > 255) | 433 | if (ts->head.marked > 255) |
434 | return ts->head.marked; /* reserved word */ | 434 | return ts->head.marked; /* reserved word */ |
435 | l->pTStr = ts; | 435 | l->pTStr = ts; |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: $ | 2 | ** $Id: lstate.h,v 1.1 1997/11/19 17:30:36 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 | */ |
@@ -18,9 +18,9 @@ | |||
18 | typedef int StkId; /* index to stack elements */ | 18 | typedef int StkId; /* index to stack elements */ |
19 | 19 | ||
20 | struct Stack { | 20 | struct Stack { |
21 | TObject *last; | ||
22 | TObject *stack; | ||
23 | TObject *top; | 21 | TObject *top; |
22 | TObject *stack; | ||
23 | TObject *last; | ||
24 | }; | 24 | }; |
25 | 25 | ||
26 | struct C_Lua_Stack { | 26 | struct C_Lua_Stack { |
@@ -45,14 +45,14 @@ struct ref { | |||
45 | 45 | ||
46 | 46 | ||
47 | typedef struct LState { | 47 | typedef struct LState { |
48 | struct C_Lua_Stack Cblocks[MAX_C_BLOCKS]; | ||
49 | int numCblocks; /* number of nested Cblocks */ | ||
50 | TObject *functofind; /* auxiliar */ | ||
51 | struct Stack stack; /* Lua stack */ | 48 | struct Stack stack; /* Lua stack */ |
52 | struct C_Lua_Stack Cstack; /* C2lua struct */ | 49 | struct C_Lua_Stack Cstack; /* C2lua struct */ |
53 | int stacklimit; /* limit for stack overflow */ | 50 | int stacklimit; /* limit for stack overflow */ |
54 | void *errorJmp; /* current error recover point */ | 51 | void *errorJmp; /* current error recover point */ |
55 | TObject errorim; /* error tag method */ | 52 | TObject errorim; /* error tag method */ |
53 | struct C_Lua_Stack Cblocks[MAX_C_BLOCKS]; | ||
54 | int numCblocks; /* number of nested Cblocks */ | ||
55 | TObject *functofind; /* auxiliar */ | ||
56 | GCnode rootproto; /* list of all prototypes */ | 56 | GCnode rootproto; /* list of all prototypes */ |
57 | GCnode rootcl; /* list of all closures */ | 57 | GCnode rootcl; /* list of all closures */ |
58 | GCnode roottable; /* list of all tables */ | 58 | GCnode roottable; /* list of all tables */ |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lstring.c,v 1.4 1997/11/04 15:27:53 roberto Exp roberto $ | 2 | ** $Id: lstring.c,v 1.5 1997/11/19 17:29:23 roberto Exp roberto $ |
3 | ** String table (keep all strings handled by Lua) | 3 | ** String table (keep all strings handled by Lua) |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -74,7 +74,7 @@ static void grow (stringtable *tb) | |||
74 | } | 74 | } |
75 | 75 | ||
76 | 76 | ||
77 | static TaggedString *newone(char *buff, int tag, unsigned long h) | 77 | static TaggedString *newone (char *buff, int tag, unsigned long h) |
78 | { | 78 | { |
79 | TaggedString *ts; | 79 | TaggedString *ts; |
80 | if (tag == LUA_T_STRING) { | 80 | if (tag == LUA_T_STRING) { |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ltable.c,v 1.5 1997/10/24 17:17:24 roberto Exp roberto $ | 2 | ** $Id: ltable.c,v 1.6 1997/11/19 17:29:23 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 | */ |
@@ -84,7 +84,7 @@ static Node *hashnodecreate (int nhash) | |||
84 | */ | 84 | */ |
85 | static void hashdelete (Hash *t) | 85 | static void hashdelete (Hash *t) |
86 | { | 86 | { |
87 | luaM_free (nodevector(t)); | 87 | luaM_free(nodevector(t)); |
88 | luaM_free(t); | 88 | luaM_free(t); |
89 | } | 89 | } |
90 | 90 | ||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lua.c,v 1.3 1997/10/16 18:35:59 roberto Exp roberto $ | 2 | ** $Id: lua.c,v 1.4 1997/11/19 17:29:23 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 | */ |
@@ -72,7 +72,7 @@ int main (int argc, char *argv[]) | |||
72 | } | 72 | } |
73 | } | 73 | } |
74 | else { | 74 | else { |
75 | int result = lua_dofile (argv[i]); | 75 | int result = lua_dofile(argv[i]); |
76 | if (result) { | 76 | if (result) { |
77 | if (result == 2) { | 77 | if (result == 2) { |
78 | fprintf(stderr, "lua: cannot execute file "); | 78 | fprintf(stderr, "lua: cannot execute file "); |
@@ -1,6 +1,6 @@ | |||
1 | %{ | 1 | %{ |
2 | /* | 2 | /* |
3 | ** $Id: lua.stx,v 1.17 1997/11/07 15:09:49 roberto Exp roberto $ | 3 | ** $Id: lua.stx,v 1.18 1997/11/19 17:29:23 roberto Exp roberto $ |
4 | ** Syntax analizer and code generator | 4 | ** Syntax analizer and code generator |
5 | ** See Copyright Notice in lua.h | 5 | ** See Copyright Notice in lua.h |
6 | */ | 6 | */ |
@@ -613,7 +613,7 @@ TProtoFunc *luaY_parser (ZIO *z, char *chunkname) | |||
613 | L->lexstate = &lexstate; | 613 | L->lexstate = &lexstate; |
614 | luaX_setinput(z); | 614 | luaX_setinput(z); |
615 | init_state(luaS_new(chunkname)); | 615 | init_state(luaS_new(chunkname)); |
616 | if (luaY_parse ()) lua_error("parse error"); | 616 | if (luaY_parse()) lua_error("parse error"); |
617 | return close_func(); | 617 | return close_func(); |
618 | } | 618 | } |
619 | 619 | ||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lvm.c,v 1.13 1997/10/27 16:14:37 roberto Exp roberto $ | 2 | ** $Id: lvm.c,v 1.14 1997/11/19 17:29:23 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 | */ |
@@ -79,12 +79,13 @@ int luaV_tostring (TObject *obj) | |||
79 | 79 | ||
80 | void luaV_closure (int nelems) | 80 | void luaV_closure (int nelems) |
81 | { | 81 | { |
82 | struct Stack *S = &L->stack; | ||
82 | Closure *c = luaF_newclosure(nelems); | 83 | Closure *c = luaF_newclosure(nelems); |
83 | c->consts[0] = *(L->stack.top-1); | 84 | c->consts[0] = *(S->top-1); |
84 | memcpy(&c->consts[1], L->stack.top-(nelems+1), nelems*sizeof(TObject)); | 85 | memcpy(&c->consts[1], S->top-(nelems+1), nelems*sizeof(TObject)); |
85 | L->stack.top -= nelems; | 86 | S->top -= nelems; |
86 | ttype(L->stack.top-1) = LUA_T_FUNCTION; | 87 | ttype(S->top-1) = LUA_T_FUNCTION; |
87 | (L->stack.top-1)->value.cl = c; | 88 | (S->top-1)->value.cl = c; |
88 | } | 89 | } |
89 | 90 | ||
90 | 91 | ||
@@ -94,23 +95,24 @@ void luaV_closure (int nelems) | |||
94 | */ | 95 | */ |
95 | void luaV_gettable (void) | 96 | void luaV_gettable (void) |
96 | { | 97 | { |
98 | struct Stack *S = &L->stack; | ||
97 | TObject *im; | 99 | TObject *im; |
98 | if (ttype(L->stack.top-2) != LUA_T_ARRAY) /* not a table, get "gettable" method */ | 100 | if (ttype(S->top-2) != LUA_T_ARRAY) /* not a table, get "gettable" method */ |
99 | im = luaT_getimbyObj(L->stack.top-2, IM_GETTABLE); | 101 | im = luaT_getimbyObj(S->top-2, IM_GETTABLE); |
100 | else { /* object is a table... */ | 102 | else { /* object is a table... */ |
101 | int tg = (L->stack.top-2)->value.a->htag; | 103 | int tg = (S->top-2)->value.a->htag; |
102 | im = luaT_getim(tg, IM_GETTABLE); | 104 | im = luaT_getim(tg, IM_GETTABLE); |
103 | if (ttype(im) == LUA_T_NIL) { /* and does not have a "gettable" method */ | 105 | if (ttype(im) == LUA_T_NIL) { /* and does not have a "gettable" method */ |
104 | TObject *h = luaH_get(avalue(L->stack.top-2), L->stack.top-1); | 106 | TObject *h = luaH_get(avalue(S->top-2), S->top-1); |
105 | if (h != NULL && ttype(h) != LUA_T_NIL) { | 107 | if (h != NULL && ttype(h) != LUA_T_NIL) { |
106 | --L->stack.top; | 108 | --S->top; |
107 | *(L->stack.top-1) = *h; | 109 | *(S->top-1) = *h; |
108 | } | 110 | } |
109 | else if (ttype(im=luaT_getim(tg, IM_INDEX)) != LUA_T_NIL) | 111 | else if (ttype(im=luaT_getim(tg, IM_INDEX)) != LUA_T_NIL) |
110 | luaD_callTM(im, 2, 1); | 112 | luaD_callTM(im, 2, 1); |
111 | else { | 113 | else { |
112 | --L->stack.top; | 114 | --S->top; |
113 | ttype(L->stack.top-1) = LUA_T_NIL; | 115 | ttype(S->top-1) = LUA_T_NIL; |
114 | } | 116 | } |
115 | return; | 117 | return; |
116 | } | 118 | } |
@@ -125,26 +127,27 @@ void luaV_gettable (void) | |||
125 | 127 | ||
126 | 128 | ||
127 | /* | 129 | /* |
128 | ** Function to store indexed based on values at the L->stack.top | 130 | ** Function to store indexed based on values at the stack.top |
129 | ** mode = 0: raw store (without internal methods) | 131 | ** mode = 0: raw store (without internal methods) |
130 | ** mode = 1: normal store (with internal methods) | 132 | ** mode = 1: normal store (with internal methods) |
131 | ** mode = 2: "deep L->stack.stack" store (with internal methods) | 133 | ** mode = 2: "deep L->stack.stack" store (with internal methods) |
132 | */ | 134 | */ |
133 | void luaV_settable (TObject *t, int mode) | 135 | void luaV_settable (TObject *t, int mode) |
134 | { | 136 | { |
137 | struct Stack *S = &L->stack; | ||
135 | TObject *im = (mode == 0) ? NULL : luaT_getimbyObj(t, IM_SETTABLE); | 138 | TObject *im = (mode == 0) ? NULL : luaT_getimbyObj(t, IM_SETTABLE); |
136 | if (ttype(t) == LUA_T_ARRAY && (im == NULL || ttype(im) == LUA_T_NIL)) { | 139 | if (ttype(t) == LUA_T_ARRAY && (im == NULL || ttype(im) == LUA_T_NIL)) { |
137 | TObject *h = luaH_set(avalue(t), t+1); | 140 | TObject *h = luaH_set(avalue(t), t+1); |
138 | *h = *(L->stack.top-1); | 141 | *h = *(S->top-1); |
139 | L->stack.top -= (mode == 2) ? 1 : 3; | 142 | S->top -= (mode == 2) ? 1 : 3; |
140 | } | 143 | } |
141 | else { /* object is not a table, and/or has a specific "settable" method */ | 144 | else { /* object is not a table, and/or has a specific "settable" method */ |
142 | if (im && ttype(im) != LUA_T_NIL) { | 145 | if (im && ttype(im) != LUA_T_NIL) { |
143 | if (mode == 2) { | 146 | if (mode == 2) { |
144 | *(L->stack.top+1) = *(L->stack.top-1); | 147 | *(S->top+1) = *(L->stack.top-1); |
145 | *(L->stack.top) = *(t+1); | 148 | *(S->top) = *(t+1); |
146 | *(L->stack.top-1) = *t; | 149 | *(S->top-1) = *t; |
147 | L->stack.top += 2; /* WARNING: caller must assure stack space */ | 150 | S->top += 2; /* WARNING: caller must assure stack space */ |
148 | } | 151 | } |
149 | luaD_callTM(im, 3, 0); | 152 | luaD_callTM(im, 3, 0); |
150 | } | 153 | } |
@@ -163,10 +166,11 @@ void luaV_getglobal (TaggedString *ts) | |||
163 | *L->stack.top++ = *value; | 166 | *L->stack.top++ = *value; |
164 | } | 167 | } |
165 | else { | 168 | else { |
166 | ttype(L->stack.top) = LUA_T_STRING; | 169 | struct Stack *S = &L->stack; |
167 | tsvalue(L->stack.top) = ts; | 170 | ttype(S->top) = LUA_T_STRING; |
168 | L->stack.top++; | 171 | tsvalue(S->top) = ts; |
169 | *L->stack.top++ = *value; | 172 | S->top++; |
173 | *S->top++ = *value; | ||
170 | luaD_callTM(im, 2, 1); | 174 | luaD_callTM(im, 2, 1); |
171 | } | 175 | } |
172 | } | 176 | } |
@@ -180,11 +184,12 @@ void luaV_setglobal (TaggedString *ts) | |||
180 | luaS_rawsetglobal(ts, --L->stack.top); | 184 | luaS_rawsetglobal(ts, --L->stack.top); |
181 | else { | 185 | else { |
182 | /* WARNING: caller must assure stack space */ | 186 | /* WARNING: caller must assure stack space */ |
183 | TObject newvalue = *(L->stack.top-1); | 187 | struct Stack *S = &L->stack; |
184 | ttype(L->stack.top-1) = LUA_T_STRING; | 188 | TObject newvalue = *(S->top-1); |
185 | tsvalue(L->stack.top-1) = ts; | 189 | ttype(S->top-1) = LUA_T_STRING; |
186 | *L->stack.top++ = *oldvalue; | 190 | tsvalue(S->top-1) = ts; |
187 | *L->stack.top++ = newvalue; | 191 | *S->top++ = *oldvalue; |
192 | *S->top++ = newvalue; | ||
188 | luaD_callTM(im, 3, 0); | 193 | luaD_callTM(im, 3, 0); |
189 | } | 194 | } |
190 | } | 195 | } |
@@ -215,8 +220,9 @@ static void call_arith (IMS event) | |||
215 | static void comparison (lua_Type ttype_less, lua_Type ttype_equal, | 220 | static void comparison (lua_Type ttype_less, lua_Type ttype_equal, |
216 | lua_Type ttype_great, IMS op) | 221 | lua_Type ttype_great, IMS op) |
217 | { | 222 | { |
218 | TObject *l = L->stack.top-2; | 223 | struct Stack *S = &L->stack; |
219 | TObject *r = L->stack.top-1; | 224 | TObject *l = S->top-2; |
225 | TObject *r = S->top-1; | ||
220 | int result; | 226 | int result; |
221 | if (ttype(l) == LUA_T_NUMBER && ttype(r) == LUA_T_NUMBER) | 227 | if (ttype(l) == LUA_T_NUMBER && ttype(r) == LUA_T_NUMBER) |
222 | result = (nvalue(l) < nvalue(r)) ? -1 : (nvalue(l) == nvalue(r)) ? 0 : 1; | 228 | result = (nvalue(l) < nvalue(r)) ? -1 : (nvalue(l) == nvalue(r)) ? 0 : 1; |
@@ -226,9 +232,9 @@ static void comparison (lua_Type ttype_less, lua_Type ttype_equal, | |||
226 | call_binTM(op, "unexpected type at comparison"); | 232 | call_binTM(op, "unexpected type at comparison"); |
227 | return; | 233 | return; |
228 | } | 234 | } |
229 | L->stack.top--; | 235 | S->top--; |
230 | nvalue(L->stack.top-1) = 1; | 236 | nvalue(S->top-1) = 1; |
231 | ttype(L->stack.top-1) = (result < 0) ? ttype_less : | 237 | ttype(S->top-1) = (result < 0) ? ttype_less : |
232 | (result == 0) ? ttype_equal : ttype_great; | 238 | (result == 0) ? ttype_equal : ttype_great; |
233 | } | 239 | } |
234 | 240 | ||
@@ -275,7 +281,7 @@ static void adjust_varargs (StkId first_extra_arg) | |||
275 | */ | 281 | */ |
276 | StkId luaV_execute (Closure *cl, StkId base) | 282 | StkId luaV_execute (Closure *cl, StkId base) |
277 | { | 283 | { |
278 | LState *LL = L; /* to optimize */ | 284 | struct Stack *S = &L->stack; /* to optimize */ |
279 | Byte *pc = cl->consts[0].value.tf->code; | 285 | Byte *pc = cl->consts[0].value.tf->code; |
280 | TObject *consts = cl->consts[0].value.tf->consts; | 286 | TObject *consts = cl->consts[0].value.tf->consts; |
281 | if (lua_callhook) | 287 | if (lua_callhook) |
@@ -286,13 +292,13 @@ StkId luaV_execute (Closure *cl, StkId base) | |||
286 | switch ((OpCode)(aux = *pc++)) { | 292 | switch ((OpCode)(aux = *pc++)) { |
287 | 293 | ||
288 | case PUSHNIL0: | 294 | case PUSHNIL0: |
289 | ttype(LL->stack.top++) = LUA_T_NIL; | 295 | ttype(S->top++) = LUA_T_NIL; |
290 | break; | 296 | break; |
291 | 297 | ||
292 | case PUSHNIL: | 298 | case PUSHNIL: |
293 | aux = *pc++; | 299 | aux = *pc++; |
294 | do { | 300 | do { |
295 | ttype(LL->stack.top++) = LUA_T_NIL; | 301 | ttype(S->top++) = LUA_T_NIL; |
296 | } while (aux--); | 302 | } while (aux--); |
297 | break; | 303 | break; |
298 | 304 | ||
@@ -305,9 +311,9 @@ StkId luaV_execute (Closure *cl, StkId base) | |||
305 | case PUSHNUMBER0: case PUSHNUMBER1: case PUSHNUMBER2: | 311 | case PUSHNUMBER0: case PUSHNUMBER1: case PUSHNUMBER2: |
306 | aux -= PUSHNUMBER0; | 312 | aux -= PUSHNUMBER0; |
307 | pushnumber: | 313 | pushnumber: |
308 | ttype(LL->stack.top) = LUA_T_NUMBER; | 314 | ttype(S->top) = LUA_T_NUMBER; |
309 | nvalue(LL->stack.top) = aux; | 315 | nvalue(S->top) = aux; |
310 | LL->stack.top++; | 316 | S->top++; |
311 | break; | 317 | break; |
312 | 318 | ||
313 | case PUSHLOCAL: | 319 | case PUSHLOCAL: |
@@ -317,7 +323,7 @@ StkId luaV_execute (Closure *cl, StkId base) | |||
317 | case PUSHLOCAL4: case PUSHLOCAL5: case PUSHLOCAL6: case PUSHLOCAL7: | 323 | case PUSHLOCAL4: case PUSHLOCAL5: case PUSHLOCAL6: case PUSHLOCAL7: |
318 | aux -= PUSHLOCAL0; | 324 | aux -= PUSHLOCAL0; |
319 | pushlocal: | 325 | pushlocal: |
320 | *LL->stack.top++ = *((LL->stack.stack+base) + aux); | 326 | *S->top++ = *((S->stack+base) + aux); |
321 | break; | 327 | break; |
322 | 328 | ||
323 | case GETGLOBALW: | 329 | case GETGLOBALW: |
@@ -347,7 +353,7 @@ StkId luaV_execute (Closure *cl, StkId base) | |||
347 | case GETDOTTED4: case GETDOTTED5: case GETDOTTED6: case GETDOTTED7: | 353 | case GETDOTTED4: case GETDOTTED5: case GETDOTTED6: case GETDOTTED7: |
348 | aux -= GETDOTTED0; | 354 | aux -= GETDOTTED0; |
349 | getdotted: | 355 | getdotted: |
350 | *LL->stack.top++ = consts[aux]; | 356 | *S->top++ = consts[aux]; |
351 | luaV_gettable(); | 357 | luaV_gettable(); |
352 | break; | 358 | break; |
353 | 359 | ||
@@ -357,10 +363,10 @@ StkId luaV_execute (Closure *cl, StkId base) | |||
357 | case PUSHSELF: | 363 | case PUSHSELF: |
358 | aux = *pc++; | 364 | aux = *pc++; |
359 | pushself: { | 365 | pushself: { |
360 | TObject receiver = *(LL->stack.top-1); | 366 | TObject receiver = *(S->top-1); |
361 | *LL->stack.top++ = consts[aux]; | 367 | *S->top++ = consts[aux]; |
362 | luaV_gettable(); | 368 | luaV_gettable(); |
363 | *LL->stack.top++ = receiver; | 369 | *S->top++ = receiver; |
364 | break; | 370 | break; |
365 | } | 371 | } |
366 | 372 | ||
@@ -375,7 +381,7 @@ StkId luaV_execute (Closure *cl, StkId base) | |||
375 | case PUSHCONSTANT6: case PUSHCONSTANT7: | 381 | case PUSHCONSTANT6: case PUSHCONSTANT7: |
376 | aux -= PUSHCONSTANT0; | 382 | aux -= PUSHCONSTANT0; |
377 | pushconstant: | 383 | pushconstant: |
378 | *LL->stack.top++ = consts[aux]; | 384 | *S->top++ = consts[aux]; |
379 | break; | 385 | break; |
380 | 386 | ||
381 | case PUSHUPVALUE: | 387 | case PUSHUPVALUE: |
@@ -384,7 +390,7 @@ StkId luaV_execute (Closure *cl, StkId base) | |||
384 | case PUSHUPVALUE0: case PUSHUPVALUE1: | 390 | case PUSHUPVALUE0: case PUSHUPVALUE1: |
385 | aux -= PUSHUPVALUE0; | 391 | aux -= PUSHUPVALUE0; |
386 | pushupvalue: | 392 | pushupvalue: |
387 | *LL->stack.top++ = cl->consts[aux+1]; | 393 | *S->top++ = cl->consts[aux+1]; |
388 | break; | 394 | break; |
389 | 395 | ||
390 | case SETLOCAL: | 396 | case SETLOCAL: |
@@ -394,7 +400,7 @@ StkId luaV_execute (Closure *cl, StkId base) | |||
394 | case SETLOCAL4: case SETLOCAL5: case SETLOCAL6: case SETLOCAL7: | 400 | case SETLOCAL4: case SETLOCAL5: case SETLOCAL6: case SETLOCAL7: |
395 | aux -= SETLOCAL0; | 401 | aux -= SETLOCAL0; |
396 | setlocal: | 402 | setlocal: |
397 | *((LL->stack.stack+base) + aux) = *(--LL->stack.top); | 403 | *((S->stack+base) + aux) = *(--S->top); |
398 | break; | 404 | break; |
399 | 405 | ||
400 | case SETGLOBALW: | 406 | case SETGLOBALW: |
@@ -411,11 +417,11 @@ StkId luaV_execute (Closure *cl, StkId base) | |||
411 | break; | 417 | break; |
412 | 418 | ||
413 | case SETTABLE0: | 419 | case SETTABLE0: |
414 | luaV_settable(LL->stack.top-3, 1); | 420 | luaV_settable(S->top-3, 1); |
415 | break; | 421 | break; |
416 | 422 | ||
417 | case SETTABLE: | 423 | case SETTABLE: |
418 | luaV_settable(LL->stack.top-3-(*pc++), 2); | 424 | luaV_settable(S->top-3-(*pc++), 2); |
419 | break; | 425 | break; |
420 | 426 | ||
421 | case SETLISTW: | 427 | case SETLISTW: |
@@ -428,12 +434,12 @@ StkId luaV_execute (Closure *cl, StkId base) | |||
428 | aux = 0; | 434 | aux = 0; |
429 | setlist: { | 435 | setlist: { |
430 | int n = *(pc++); | 436 | int n = *(pc++); |
431 | TObject *arr = LL->stack.top-n-1; | 437 | TObject *arr = S->top-n-1; |
432 | for (; n; n--) { | 438 | for (; n; n--) { |
433 | ttype(LL->stack.top) = LUA_T_NUMBER; | 439 | ttype(S->top) = LUA_T_NUMBER; |
434 | nvalue(LL->stack.top) = n+aux; | 440 | nvalue(S->top) = n+aux; |
435 | *(luaH_set (avalue(arr), LL->stack.top)) = *(LL->stack.top-1); | 441 | *(luaH_set(avalue(arr), S->top)) = *(S->top-1); |
436 | LL->stack.top--; | 442 | S->top--; |
437 | } | 443 | } |
438 | break; | 444 | break; |
439 | } | 445 | } |
@@ -444,10 +450,10 @@ StkId luaV_execute (Closure *cl, StkId base) | |||
444 | case SETMAP: | 450 | case SETMAP: |
445 | aux = *pc++; | 451 | aux = *pc++; |
446 | setmap: { | 452 | setmap: { |
447 | TObject *arr = LL->stack.top-(2*aux)-3; | 453 | TObject *arr = S->top-(2*aux)-3; |
448 | do { | 454 | do { |
449 | *(luaH_set (avalue(arr), LL->stack.top-2)) = *(LL->stack.top-1); | 455 | *(luaH_set(avalue(arr), S->top-2)) = *(S->top-1); |
450 | LL->stack.top-=2; | 456 | S->top-=2; |
451 | } while (aux--); | 457 | } while (aux--); |
452 | break; | 458 | break; |
453 | } | 459 | } |
@@ -458,7 +464,7 @@ StkId luaV_execute (Closure *cl, StkId base) | |||
458 | case POP0: case POP1: | 464 | case POP0: case POP1: |
459 | aux -= POP0; | 465 | aux -= POP0; |
460 | pop: | 466 | pop: |
461 | LL->stack.top -= (aux+1); | 467 | S->top -= (aux+1); |
462 | break; | 468 | break; |
463 | 469 | ||
464 | case ARGS: | 470 | case ARGS: |
@@ -480,17 +486,17 @@ StkId luaV_execute (Closure *cl, StkId base) | |||
480 | aux = *pc++; | 486 | aux = *pc++; |
481 | createarray: | 487 | createarray: |
482 | luaC_checkGC(); | 488 | luaC_checkGC(); |
483 | avalue(LL->stack.top) = luaH_new(aux); | 489 | avalue(S->top) = luaH_new(aux); |
484 | ttype(LL->stack.top) = LUA_T_ARRAY; | 490 | ttype(S->top) = LUA_T_ARRAY; |
485 | LL->stack.top++; | 491 | S->top++; |
486 | break; | 492 | break; |
487 | 493 | ||
488 | case EQOP: case NEQOP: { | 494 | case EQOP: case NEQOP: { |
489 | int res = luaO_equalObj(LL->stack.top-2, LL->stack.top-1); | 495 | int res = luaO_equalObj(S->top-2, S->top-1); |
490 | LL->stack.top--; | 496 | S->top--; |
491 | if (aux == NEQOP) res = !res; | 497 | if (aux == NEQOP) res = !res; |
492 | ttype(LL->stack.top-1) = res ? LUA_T_NUMBER : LUA_T_NIL; | 498 | ttype(S->top-1) = res ? LUA_T_NUMBER : LUA_T_NIL; |
493 | nvalue(LL->stack.top-1) = 1; | 499 | nvalue(S->top-1) = 1; |
494 | break; | 500 | break; |
495 | } | 501 | } |
496 | 502 | ||
@@ -511,49 +517,49 @@ StkId luaV_execute (Closure *cl, StkId base) | |||
511 | break; | 517 | break; |
512 | 518 | ||
513 | case ADDOP: { | 519 | case ADDOP: { |
514 | TObject *l = LL->stack.top-2; | 520 | TObject *l = S->top-2; |
515 | TObject *r = LL->stack.top-1; | 521 | TObject *r = S->top-1; |
516 | if (tonumber(r) || tonumber(l)) | 522 | if (tonumber(r) || tonumber(l)) |
517 | call_arith(IM_ADD); | 523 | call_arith(IM_ADD); |
518 | else { | 524 | else { |
519 | nvalue(l) += nvalue(r); | 525 | nvalue(l) += nvalue(r); |
520 | --LL->stack.top; | 526 | --S->top; |
521 | } | 527 | } |
522 | break; | 528 | break; |
523 | } | 529 | } |
524 | 530 | ||
525 | case SUBOP: { | 531 | case SUBOP: { |
526 | TObject *l = LL->stack.top-2; | 532 | TObject *l = S->top-2; |
527 | TObject *r = LL->stack.top-1; | 533 | TObject *r = S->top-1; |
528 | if (tonumber(r) || tonumber(l)) | 534 | if (tonumber(r) || tonumber(l)) |
529 | call_arith(IM_SUB); | 535 | call_arith(IM_SUB); |
530 | else { | 536 | else { |
531 | nvalue(l) -= nvalue(r); | 537 | nvalue(l) -= nvalue(r); |
532 | --LL->stack.top; | 538 | --S->top; |
533 | } | 539 | } |
534 | break; | 540 | break; |
535 | } | 541 | } |
536 | 542 | ||
537 | case MULTOP: { | 543 | case MULTOP: { |
538 | TObject *l = LL->stack.top-2; | 544 | TObject *l = S->top-2; |
539 | TObject *r = LL->stack.top-1; | 545 | TObject *r = S->top-1; |
540 | if (tonumber(r) || tonumber(l)) | 546 | if (tonumber(r) || tonumber(l)) |
541 | call_arith(IM_MUL); | 547 | call_arith(IM_MUL); |
542 | else { | 548 | else { |
543 | nvalue(l) *= nvalue(r); | 549 | nvalue(l) *= nvalue(r); |
544 | --LL->stack.top; | 550 | --S->top; |
545 | } | 551 | } |
546 | break; | 552 | break; |
547 | } | 553 | } |
548 | 554 | ||
549 | case DIVOP: { | 555 | case DIVOP: { |
550 | TObject *l = LL->stack.top-2; | 556 | TObject *l = S->top-2; |
551 | TObject *r = LL->stack.top-1; | 557 | TObject *r = S->top-1; |
552 | if (tonumber(r) || tonumber(l)) | 558 | if (tonumber(r) || tonumber(l)) |
553 | call_arith(IM_DIV); | 559 | call_arith(IM_DIV); |
554 | else { | 560 | else { |
555 | nvalue(l) /= nvalue(r); | 561 | nvalue(l) /= nvalue(r); |
556 | --LL->stack.top; | 562 | --S->top; |
557 | } | 563 | } |
558 | break; | 564 | break; |
559 | } | 565 | } |
@@ -563,32 +569,32 @@ StkId luaV_execute (Closure *cl, StkId base) | |||
563 | break; | 569 | break; |
564 | 570 | ||
565 | case CONCOP: { | 571 | case CONCOP: { |
566 | TObject *l = LL->stack.top-2; | 572 | TObject *l = S->top-2; |
567 | TObject *r = LL->stack.top-1; | 573 | TObject *r = S->top-1; |
568 | if (tostring(l) || tostring(r)) | 574 | if (tostring(l) || tostring(r)) |
569 | call_binTM(IM_CONCAT, "unexpected type for concatenation"); | 575 | call_binTM(IM_CONCAT, "unexpected type for concatenation"); |
570 | else { | 576 | else { |
571 | tsvalue(l) = strconc(svalue(l), svalue(r)); | 577 | tsvalue(l) = strconc(svalue(l), svalue(r)); |
572 | --LL->stack.top; | 578 | --S->top; |
573 | } | 579 | } |
574 | luaC_checkGC(); | 580 | luaC_checkGC(); |
575 | break; | 581 | break; |
576 | } | 582 | } |
577 | 583 | ||
578 | case MINUSOP: | 584 | case MINUSOP: |
579 | if (tonumber(LL->stack.top-1)) { | 585 | if (tonumber(S->top-1)) { |
580 | ttype(LL->stack.top) = LUA_T_NIL; | 586 | ttype(S->top) = LUA_T_NIL; |
581 | LL->stack.top++; | 587 | S->top++; |
582 | call_arith(IM_UNM); | 588 | call_arith(IM_UNM); |
583 | } | 589 | } |
584 | else | 590 | else |
585 | nvalue(LL->stack.top-1) = - nvalue(LL->stack.top-1); | 591 | nvalue(S->top-1) = - nvalue(S->top-1); |
586 | break; | 592 | break; |
587 | 593 | ||
588 | case NOTOP: | 594 | case NOTOP: |
589 | ttype(LL->stack.top-1) = | 595 | ttype(S->top-1) = |
590 | (ttype(LL->stack.top-1) == LUA_T_NIL) ? LUA_T_NUMBER : LUA_T_NIL; | 596 | (ttype(S->top-1) == LUA_T_NIL) ? LUA_T_NUMBER : LUA_T_NIL; |
591 | nvalue(LL->stack.top-1) = 1; | 597 | nvalue(S->top-1) = 1; |
592 | break; | 598 | break; |
593 | 599 | ||
594 | case ONTJMPW: | 600 | case ONTJMPW: |
@@ -597,8 +603,8 @@ StkId luaV_execute (Closure *cl, StkId base) | |||
597 | case ONTJMP: | 603 | case ONTJMP: |
598 | aux = *pc++; | 604 | aux = *pc++; |
599 | ontjmp: | 605 | ontjmp: |
600 | if (ttype(LL->stack.top-1) != LUA_T_NIL) pc += aux; | 606 | if (ttype(S->top-1) != LUA_T_NIL) pc += aux; |
601 | else LL->stack.top--; | 607 | else S->top--; |
602 | break; | 608 | break; |
603 | 609 | ||
604 | case ONFJMPW: | 610 | case ONFJMPW: |
@@ -607,8 +613,8 @@ StkId luaV_execute (Closure *cl, StkId base) | |||
607 | case ONFJMP: | 613 | case ONFJMP: |
608 | aux = *pc++; | 614 | aux = *pc++; |
609 | onfjmp: | 615 | onfjmp: |
610 | if (ttype(LL->stack.top-1) == LUA_T_NIL) pc += aux; | 616 | if (ttype(S->top-1) == LUA_T_NIL) pc += aux; |
611 | else LL->stack.top--; | 617 | else S->top--; |
612 | break; | 618 | break; |
613 | 619 | ||
614 | case JMPW: | 620 | case JMPW: |
@@ -626,7 +632,7 @@ StkId luaV_execute (Closure *cl, StkId base) | |||
626 | case IFFJMP: | 632 | case IFFJMP: |
627 | aux = *pc++; | 633 | aux = *pc++; |
628 | iffjmp: | 634 | iffjmp: |
629 | if (ttype(--LL->stack.top) == LUA_T_NIL) pc += aux; | 635 | if (ttype(--S->top) == LUA_T_NIL) pc += aux; |
630 | break; | 636 | break; |
631 | 637 | ||
632 | case IFTUPJMPW: | 638 | case IFTUPJMPW: |
@@ -635,7 +641,7 @@ StkId luaV_execute (Closure *cl, StkId base) | |||
635 | case IFTUPJMP: | 641 | case IFTUPJMP: |
636 | aux = *pc++; | 642 | aux = *pc++; |
637 | iftupjmp: | 643 | iftupjmp: |
638 | if (ttype(--LL->stack.top) != LUA_T_NIL) pc -= aux; | 644 | if (ttype(--S->top) != LUA_T_NIL) pc -= aux; |
639 | break; | 645 | break; |
640 | 646 | ||
641 | case IFFUPJMPW: | 647 | case IFFUPJMPW: |
@@ -644,7 +650,7 @@ StkId luaV_execute (Closure *cl, StkId base) | |||
644 | case IFFUPJMP: | 650 | case IFFUPJMP: |
645 | aux = *pc++; | 651 | aux = *pc++; |
646 | iffupjmp: | 652 | iffupjmp: |
647 | if (ttype(--LL->stack.top) == LUA_T_NIL) pc -= aux; | 653 | if (ttype(--S->top) == LUA_T_NIL) pc -= aux; |
648 | break; | 654 | break; |
649 | 655 | ||
650 | case CLOSURE: | 656 | case CLOSURE: |
@@ -663,13 +669,13 @@ StkId luaV_execute (Closure *cl, StkId base) | |||
663 | case CALLFUNC0: case CALLFUNC1: | 669 | case CALLFUNC0: case CALLFUNC1: |
664 | aux -= CALLFUNC0; | 670 | aux -= CALLFUNC0; |
665 | callfunc: { | 671 | callfunc: { |
666 | StkId newBase = (LL->stack.top-LL->stack.stack)-(*pc++); | 672 | StkId newBase = (S->top-S->stack)-(*pc++); |
667 | luaD_call(newBase, aux); | 673 | luaD_call(newBase, aux); |
668 | break; | 674 | break; |
669 | } | 675 | } |
670 | 676 | ||
671 | case ENDCODE: | 677 | case ENDCODE: |
672 | LL->stack.top = LL->stack.stack + base; | 678 | S->top = S->stack + base; |
673 | /* goes through */ | 679 | /* goes through */ |
674 | case RETCODE: | 680 | case RETCODE: |
675 | if (lua_callhook) | 681 | if (lua_callhook) |
@@ -682,13 +688,13 @@ StkId luaV_execute (Closure *cl, StkId base) | |||
682 | case SETLINE: | 688 | case SETLINE: |
683 | aux = *pc++; | 689 | aux = *pc++; |
684 | setline: | 690 | setline: |
685 | if ((LL->stack.stack+base-1)->ttype != LUA_T_LINE) { | 691 | if ((S->stack+base-1)->ttype != LUA_T_LINE) { |
686 | /* open space for LINE value */ | 692 | /* open space for LINE value */ |
687 | luaD_openstack((LL->stack.top-LL->stack.stack)-base); | 693 | luaD_openstack((S->top-S->stack)-base); |
688 | base++; | 694 | base++; |
689 | (LL->stack.stack+base-1)->ttype = LUA_T_LINE; | 695 | (S->stack+base-1)->ttype = LUA_T_LINE; |
690 | } | 696 | } |
691 | (LL->stack.stack+base-1)->value.i = aux; | 697 | (S->stack+base-1)->value.i = aux; |
692 | if (lua_linehook) | 698 | if (lua_linehook) |
693 | luaD_lineHook(aux); | 699 | luaD_lineHook(aux); |
694 | break; | 700 | break; |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: zio.c,v 1.2 1997/06/20 19:25:54 roberto Exp $ | 2 | ** $Id: lzio.c,v 1.1 1997/09/16 19:25:59 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 | */ |
@@ -15,12 +15,12 @@ | |||
15 | 15 | ||
16 | /* ----------------------------------------------------- memory buffers --- */ | 16 | /* ----------------------------------------------------- memory buffers --- */ |
17 | 17 | ||
18 | static int zmfilbuf(ZIO* z) | 18 | static int zmfilbuf (ZIO* z) |
19 | { | 19 | { |
20 | return EOZ; | 20 | return EOZ; |
21 | } | 21 | } |
22 | 22 | ||
23 | ZIO* zmopen(ZIO* z, char* b, int size) | 23 | ZIO* zmopen (ZIO* z, char* b, int size) |
24 | { | 24 | { |
25 | if (b==NULL) return NULL; | 25 | if (b==NULL) return NULL; |
26 | z->n=size; | 26 | z->n=size; |
@@ -32,7 +32,7 @@ ZIO* zmopen(ZIO* z, char* b, int size) | |||
32 | 32 | ||
33 | /* ------------------------------------------------------------ strings --- */ | 33 | /* ------------------------------------------------------------ strings --- */ |
34 | 34 | ||
35 | ZIO* zsopen(ZIO* z, char* s) | 35 | ZIO* zsopen (ZIO* z, char* s) |
36 | { | 36 | { |
37 | if (s==NULL) return NULL; | 37 | if (s==NULL) return NULL; |
38 | return zmopen(z,s,strlen(s)); | 38 | return zmopen(z,s,strlen(s)); |
@@ -40,7 +40,7 @@ ZIO* zsopen(ZIO* z, char* s) | |||
40 | 40 | ||
41 | /* -------------------------------------------------------------- FILEs --- */ | 41 | /* -------------------------------------------------------------- FILEs --- */ |
42 | 42 | ||
43 | static int zffilbuf(ZIO* z) | 43 | static int zffilbuf (ZIO* z) |
44 | { | 44 | { |
45 | int n=fread(z->buffer,1,ZBSIZE,z->u); | 45 | int n=fread(z->buffer,1,ZBSIZE,z->u); |
46 | if (n==0) return EOZ; | 46 | if (n==0) return EOZ; |
@@ -50,7 +50,7 @@ static int zffilbuf(ZIO* z) | |||
50 | } | 50 | } |
51 | 51 | ||
52 | 52 | ||
53 | ZIO* zFopen(ZIO* z, FILE* f) | 53 | ZIO* zFopen (ZIO* z, FILE* f) |
54 | { | 54 | { |
55 | if (f==NULL) return NULL; | 55 | if (f==NULL) return NULL; |
56 | z->n=0; | 56 | z->n=0; |
@@ -62,7 +62,7 @@ ZIO* zFopen(ZIO* z, FILE* f) | |||
62 | 62 | ||
63 | 63 | ||
64 | /* --------------------------------------------------------------- read --- */ | 64 | /* --------------------------------------------------------------- read --- */ |
65 | int zread(ZIO *z, void *b, int n) | 65 | int zread (ZIO *z, void *b, int n) |
66 | { | 66 | { |
67 | while (n) { | 67 | while (n) { |
68 | int m; | 68 | int m; |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: $ | 2 | ** $Id: lzio.h,v 1.1 1997/09/16 19:25:59 roberto Exp roberto $ |
3 | ** Buffered streams | 3 | ** Buffered streams |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -22,11 +22,11 @@ | |||
22 | 22 | ||
23 | typedef struct zio ZIO; | 23 | typedef struct zio ZIO; |
24 | 24 | ||
25 | ZIO* zFopen(ZIO* z, FILE* f); /* open FILEs */ | 25 | ZIO* zFopen (ZIO* z, FILE* f); /* open FILEs */ |
26 | ZIO* zsopen(ZIO* z, char* s); /* string */ | 26 | ZIO* zsopen (ZIO* z, char* s); /* string */ |
27 | ZIO* zmopen(ZIO* z, char* b, int size); /* memory */ | 27 | ZIO* zmopen (ZIO* z, char* b, int size); /* memory */ |
28 | 28 | ||
29 | int zread(ZIO* z, void* b, int n); /* read next n bytes */ | 29 | int zread (ZIO* z, void* b, int n); /* read next n bytes */ |
30 | 30 | ||
31 | #define zgetc(z) (--(z)->n>=0 ? ((int)*(z)->p++): (z)->filbuf(z)) | 31 | #define zgetc(z) (--(z)->n>=0 ? ((int)*(z)->p++): (z)->filbuf(z)) |
32 | #define zungetc(z) (++(z)->n,--(z)->p) | 32 | #define zungetc(z) (++(z)->n,--(z)->p) |