diff options
-rw-r--r-- | lapi.c | 102 | ||||
-rw-r--r-- | lapi.h | 3 | ||||
-rw-r--r-- | lbuiltin.c | 31 | ||||
-rw-r--r-- | ldo.c | 6 | ||||
-rw-r--r-- | ldo.h | 8 | ||||
-rw-r--r-- | lobject.h | 4 | ||||
-rw-r--r-- | lua.h | 10 |
7 files changed, 80 insertions, 84 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lapi.c,v 1.60 1999/11/29 19:31:29 roberto Exp roberto $ | 2 | ** $Id: lapi.c,v 1.61 1999/12/01 19:50:08 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 | */ |
@@ -31,11 +31,6 @@ const char lua_ident[] = "$Lua: " LUA_VERSION " " LUA_COPYRIGHT " $\n" | |||
31 | 31 | ||
32 | 32 | ||
33 | 33 | ||
34 | TObject *luaA_Address (lua_State *L, lua_Object o) { | ||
35 | return (o != LUA_NOOBJECT) ? Address(L, o) : NULL; | ||
36 | } | ||
37 | |||
38 | |||
39 | static lua_Type normalized_type (const TObject *o) { | 34 | static lua_Type normalized_type (const TObject *o) { |
40 | int t = ttype(o); | 35 | int t = ttype(o); |
41 | switch (t) { | 36 | switch (t) { |
@@ -71,14 +66,14 @@ static void checkCparams (lua_State *L, int nParams) { | |||
71 | static lua_Object put_luaObject (lua_State *L, const TObject *o) { | 66 | static lua_Object put_luaObject (lua_State *L, const TObject *o) { |
72 | luaD_openstack(L, L->Cstack.base); | 67 | luaD_openstack(L, L->Cstack.base); |
73 | *L->Cstack.base++ = *o; | 68 | *L->Cstack.base++ = *o; |
74 | return Ref(L, L->Cstack.base-1); | 69 | return L->Cstack.base-1; |
75 | } | 70 | } |
76 | 71 | ||
77 | 72 | ||
78 | lua_Object luaA_putObjectOnTop (lua_State *L) { | 73 | lua_Object luaA_putObjectOnTop (lua_State *L) { |
79 | luaD_openstack(L, L->Cstack.base); | 74 | luaD_openstack(L, L->Cstack.base); |
80 | *L->Cstack.base++ = *(--L->top); | 75 | *L->Cstack.base++ = *(--L->top); |
81 | return Ref(L, L->Cstack.base-1); | 76 | return L->Cstack.base-1; |
82 | } | 77 | } |
83 | 78 | ||
84 | 79 | ||
@@ -102,7 +97,7 @@ lua_Object lua_pop (lua_State *L) { | |||
102 | */ | 97 | */ |
103 | lua_Object lua_lua2C (lua_State *L, int number) { | 98 | lua_Object lua_lua2C (lua_State *L, int number) { |
104 | if (number <= 0 || number > L->Cstack.num) return LUA_NOOBJECT; | 99 | if (number <= 0 || number > L->Cstack.num) return LUA_NOOBJECT; |
105 | return Ref(L, L->Cstack.lua2C+number-1); | 100 | return L->Cstack.lua2C+number-1; |
106 | } | 101 | } |
107 | 102 | ||
108 | 103 | ||
@@ -111,7 +106,7 @@ int lua_callfunction (lua_State *L, lua_Object function) { | |||
111 | return 1; | 106 | return 1; |
112 | else { | 107 | else { |
113 | luaD_openstack(L, L->Cstack.base); | 108 | luaD_openstack(L, L->Cstack.base); |
114 | set_normalized(L->Cstack.base, Address(L, function)); | 109 | set_normalized(L->Cstack.base, function); |
115 | return luaD_protectedrun(L); | 110 | return luaD_protectedrun(L); |
116 | } | 111 | } |
117 | } | 112 | } |
@@ -205,27 +200,33 @@ void lua_rawsetglobal (lua_State *L, const char *name) { | |||
205 | 200 | ||
206 | 201 | ||
207 | const char *lua_type (lua_State *L, lua_Object o) { | 202 | const char *lua_type (lua_State *L, lua_Object o) { |
208 | return (o == LUA_NOOBJECT) ? "NOOBJECT" : luaO_typename(L, Address(L, o)); | 203 | UNUSED(L); |
204 | return (o == LUA_NOOBJECT) ? "NOOBJECT" : luaO_typename(L, o); | ||
209 | } | 205 | } |
210 | 206 | ||
211 | int lua_isnil (lua_State *L, lua_Object o) { | 207 | int lua_isnil (lua_State *L, lua_Object o) { |
212 | return (o != LUA_NOOBJECT) && (ttype(Address(L, o)) == LUA_T_NIL); | 208 | UNUSED(L); |
209 | return (o != LUA_NOOBJECT) && (ttype(o) == LUA_T_NIL); | ||
213 | } | 210 | } |
214 | 211 | ||
215 | int lua_istable (lua_State *L, lua_Object o) { | 212 | int lua_istable (lua_State *L, lua_Object o) { |
216 | return (o != LUA_NOOBJECT) && (ttype(Address(L, o)) == LUA_T_ARRAY); | 213 | UNUSED(L); |
214 | return (o != LUA_NOOBJECT) && (ttype(o) == LUA_T_ARRAY); | ||
217 | } | 215 | } |
218 | 216 | ||
219 | int lua_isuserdata (lua_State *L, lua_Object o) { | 217 | int lua_isuserdata (lua_State *L, lua_Object o) { |
220 | return (o != LUA_NOOBJECT) && (ttype(Address(L, o)) == LUA_T_USERDATA); | 218 | UNUSED(L); |
219 | return (o != LUA_NOOBJECT) && (ttype(o) == LUA_T_USERDATA); | ||
221 | } | 220 | } |
222 | 221 | ||
223 | int lua_iscfunction (lua_State *L, lua_Object o) { | 222 | int lua_iscfunction (lua_State *L, lua_Object o) { |
223 | UNUSED(L); | ||
224 | return (lua_tag(L, o) == LUA_T_CPROTO); | 224 | return (lua_tag(L, o) == LUA_T_CPROTO); |
225 | } | 225 | } |
226 | 226 | ||
227 | int lua_isnumber (lua_State *L, lua_Object o) { | 227 | int lua_isnumber (lua_State *L, lua_Object o) { |
228 | return (o != LUA_NOOBJECT) && (tonumber(Address(L, o)) == 0); | 228 | UNUSED(L); |
229 | return (o != LUA_NOOBJECT) && (tonumber(o) == 0); | ||
229 | } | 230 | } |
230 | 231 | ||
231 | int lua_isstring (lua_State *L, lua_Object o) { | 232 | int lua_isstring (lua_State *L, lua_Object o) { |
@@ -239,41 +240,44 @@ int lua_isfunction (lua_State *L, lua_Object o) { | |||
239 | } | 240 | } |
240 | 241 | ||
241 | int lua_equal(lua_State *L, lua_Object o1, lua_Object o2) { | 242 | int lua_equal(lua_State *L, lua_Object o1, lua_Object o2) { |
243 | UNUSED(L); | ||
242 | if (o1 == LUA_NOOBJECT || o2 == LUA_NOOBJECT) return (o1 == o2); | 244 | if (o1 == LUA_NOOBJECT || o2 == LUA_NOOBJECT) return (o1 == o2); |
243 | else return luaO_equalObj(Address(L, o1), Address(L, o2)); | 245 | else return luaO_equalObj(o1, o2); |
244 | } | 246 | } |
245 | 247 | ||
246 | 248 | ||
247 | double lua_getnumber (lua_State *L, lua_Object obj) { | 249 | double lua_getnumber (lua_State *L, lua_Object obj) { |
248 | if (obj == LUA_NOOBJECT) return 0.0; | 250 | UNUSED(L); |
249 | if (tonumber(Address(L, obj))) return 0.0; | 251 | if (obj == LUA_NOOBJECT) return 0.0; |
250 | else return (nvalue(Address(L, obj))); | 252 | if (tonumber(obj)) return 0.0; |
253 | else return (nvalue(obj)); | ||
251 | } | 254 | } |
252 | 255 | ||
253 | const char *lua_getstring (lua_State *L, lua_Object obj) { | 256 | const char *lua_getstring (lua_State *L, lua_Object obj) { |
254 | luaC_checkGC(L); /* `tostring' may create a new string */ | 257 | luaC_checkGC(L); /* `tostring' may create a new string */ |
255 | if (obj == LUA_NOOBJECT || tostring(L, Address(L, obj))) | 258 | if (obj == LUA_NOOBJECT || tostring(L, obj)) |
256 | return NULL; | 259 | return NULL; |
257 | else return (svalue(Address(L, obj))); | 260 | else return (svalue(obj)); |
258 | } | 261 | } |
259 | 262 | ||
260 | long lua_strlen (lua_State *L, lua_Object obj) { | 263 | long lua_strlen (lua_State *L, lua_Object obj) { |
261 | luaC_checkGC(L); /* `tostring' may create a new string */ | 264 | UNUSED(L); |
262 | if (obj == LUA_NOOBJECT || tostring(L, Address(L, obj))) | 265 | if (obj == LUA_NOOBJECT || tostring(L, obj)) |
263 | return 0L; | 266 | return 0L; |
264 | else return (tsvalue(Address(L, obj))->u.s.len); | 267 | else return (tsvalue(obj)->u.s.len); |
265 | } | 268 | } |
266 | 269 | ||
267 | void *lua_getuserdata (lua_State *L, lua_Object obj) { | 270 | void *lua_getuserdata (lua_State *L, lua_Object obj) { |
268 | if (obj == LUA_NOOBJECT || ttype(Address(L, obj)) != LUA_T_USERDATA) | 271 | UNUSED(L); |
272 | if (obj == LUA_NOOBJECT || ttype(obj) != LUA_T_USERDATA) | ||
269 | return NULL; | 273 | return NULL; |
270 | else return tsvalue(Address(L, obj))->u.d.value; | 274 | else return tsvalue(obj)->u.d.value; |
271 | } | 275 | } |
272 | 276 | ||
273 | lua_CFunction lua_getcfunction (lua_State *L, lua_Object obj) { | 277 | lua_CFunction lua_getcfunction (lua_State *L, lua_Object obj) { |
274 | if (!lua_iscfunction(L, obj)) | 278 | if (!lua_iscfunction(L, obj)) |
275 | return NULL; | 279 | return NULL; |
276 | else return fvalue(luaA_protovalue(Address(L, obj))); | 280 | else return fvalue(luaA_protovalue(obj)); |
277 | } | 281 | } |
278 | 282 | ||
279 | 283 | ||
@@ -330,16 +334,16 @@ void luaA_pushobject (lua_State *L, const TObject *o) { | |||
330 | void lua_pushobject (lua_State *L, lua_Object o) { | 334 | void lua_pushobject (lua_State *L, lua_Object o) { |
331 | if (o == LUA_NOOBJECT) | 335 | if (o == LUA_NOOBJECT) |
332 | lua_error(L, "API error - attempt to push a NOOBJECT"); | 336 | lua_error(L, "API error - attempt to push a NOOBJECT"); |
333 | set_normalized(L->top, Address(L, o)); | 337 | set_normalized(L->top, o); |
334 | incr_top; | 338 | incr_top; |
335 | } | 339 | } |
336 | 340 | ||
337 | 341 | ||
338 | int lua_tag (lua_State *L, lua_Object lo) { | 342 | int lua_tag (lua_State *L, lua_Object o) { |
339 | if (lo == LUA_NOOBJECT) | 343 | UNUSED(L); |
344 | if (o == LUA_NOOBJECT) | ||
340 | return LUA_T_NIL; | 345 | return LUA_T_NIL; |
341 | else { | 346 | else { |
342 | const TObject *o = Address(L, lo); | ||
343 | int t; | 347 | int t; |
344 | switch (t = ttype(o)) { | 348 | switch (t = ttype(o)) { |
345 | case LUA_T_USERDATA: | 349 | case LUA_T_USERDATA: |
@@ -429,8 +433,7 @@ int luaA_next (lua_State *L, const Hash *t, int i) { | |||
429 | } | 433 | } |
430 | 434 | ||
431 | 435 | ||
432 | int lua_next (lua_State *L, lua_Object o, int i) { | 436 | int lua_next (lua_State *L, lua_Object t, int i) { |
433 | const TObject *t = Address(L, o); | ||
434 | if (ttype(t) != LUA_T_ARRAY) | 437 | if (ttype(t) != LUA_T_ARRAY) |
435 | lua_error(L, "API error - object is not a table in `lua_next'"); | 438 | lua_error(L, "API error - object is not a table in `lua_next'"); |
436 | i = luaA_next(L, avalue(t), i); | 439 | i = luaA_next(L, avalue(t), i); |
@@ -482,33 +485,31 @@ lua_Function lua_stackedfunction (lua_State *L, int level) { | |||
482 | int t = L->stack[i].ttype; | 485 | int t = L->stack[i].ttype; |
483 | if (t == LUA_T_CLMARK || t == LUA_T_PMARK || t == LUA_T_CMARK) | 486 | if (t == LUA_T_CLMARK || t == LUA_T_PMARK || t == LUA_T_CMARK) |
484 | if (level-- == 0) | 487 | if (level-- == 0) |
485 | return Ref(L, L->stack+i); | 488 | return L->stack+i; |
486 | } | 489 | } |
487 | return LUA_NOOBJECT; | 490 | return LUA_NOOBJECT; |
488 | } | 491 | } |
489 | 492 | ||
490 | 493 | ||
491 | int lua_nups (lua_State *L, lua_Function func) { | 494 | int lua_nups (lua_State *L, lua_Function f) { |
492 | const TObject *o = luaA_Address(L, func); | 495 | UNUSED(L); |
493 | return (!o || normalized_type(o) != LUA_T_CLOSURE) ? 0 : o->value.cl->nelems; | 496 | return (!f || normalized_type(f) != LUA_T_CLOSURE) ? 0 : f->value.cl->nelems; |
494 | } | 497 | } |
495 | 498 | ||
496 | 499 | ||
497 | int lua_currentline (lua_State *L, lua_Function func) { | 500 | int lua_currentline (lua_State *L, lua_Function f) { |
498 | const TObject *f = Address(L, func); | ||
499 | return (f+1 < L->top && (f+1)->ttype == LUA_T_LINE) ? (f+1)->value.i : -1; | 501 | return (f+1 < L->top && (f+1)->ttype == LUA_T_LINE) ? (f+1)->value.i : -1; |
500 | } | 502 | } |
501 | 503 | ||
502 | 504 | ||
503 | lua_Object lua_getlocal (lua_State *L, lua_Function func, int local_number, | 505 | lua_Object lua_getlocal (lua_State *L, lua_Function f, int local_number, |
504 | const char **name) { | 506 | const char **name) { |
505 | /* check whether func is a Lua function */ | 507 | /* check whether `f' is a Lua function */ |
506 | if (lua_tag(L, func) != LUA_T_PROTO) | 508 | if (lua_tag(L, f) != LUA_T_PROTO) |
507 | return LUA_NOOBJECT; | 509 | return LUA_NOOBJECT; |
508 | else { | 510 | else { |
509 | TObject *f = Address(L, func); | ||
510 | TProtoFunc *fp = luaA_protovalue(f)->value.tf; | 511 | TProtoFunc *fp = luaA_protovalue(f)->value.tf; |
511 | *name = luaF_getlocalname(fp, local_number, lua_currentline(L, func)); | 512 | *name = luaF_getlocalname(fp, local_number, lua_currentline(L, f)); |
512 | if (*name) { | 513 | if (*name) { |
513 | /* if "*name", there must be a LUA_T_LINE */ | 514 | /* if "*name", there must be a LUA_T_LINE */ |
514 | /* therefore, f+2 points to function base */ | 515 | /* therefore, f+2 points to function base */ |
@@ -520,15 +521,14 @@ lua_Object lua_getlocal (lua_State *L, lua_Function func, int local_number, | |||
520 | } | 521 | } |
521 | 522 | ||
522 | 523 | ||
523 | int lua_setlocal (lua_State *L, lua_Function func, int local_number) { | 524 | int lua_setlocal (lua_State *L, lua_Function f, int local_number) { |
524 | /* check whether func is a Lua function */ | 525 | /* check whether `f' is a Lua function */ |
525 | if (lua_tag(L, func) != LUA_T_PROTO) | 526 | if (lua_tag(L, f) != LUA_T_PROTO) |
526 | return 0; | 527 | return 0; |
527 | else { | 528 | else { |
528 | TObject *f = Address(L, func); | ||
529 | TProtoFunc *fp = luaA_protovalue(f)->value.tf; | 529 | TProtoFunc *fp = luaA_protovalue(f)->value.tf; |
530 | const char *name = luaF_getlocalname(fp, local_number, | 530 | const char *name = luaF_getlocalname(fp, local_number, |
531 | lua_currentline(L, func)); | 531 | lua_currentline(L, f)); |
532 | checkCparams(L, 1); | 532 | checkCparams(L, 1); |
533 | --L->top; | 533 | --L->top; |
534 | if (name) { | 534 | if (name) { |
@@ -548,7 +548,7 @@ void lua_funcinfo (lua_State *L, lua_Object func, | |||
548 | if (!lua_isfunction(L, func)) | 548 | if (!lua_isfunction(L, func)) |
549 | lua_error(L, "API error - `funcinfo' called with a non-function value"); | 549 | lua_error(L, "API error - `funcinfo' called with a non-function value"); |
550 | else { | 550 | else { |
551 | const TObject *f = luaA_protovalue(Address(L, func)); | 551 | const TObject *f = luaA_protovalue(func); |
552 | if (normalized_type(f) == LUA_T_PROTO) { | 552 | if (normalized_type(f) == LUA_T_PROTO) { |
553 | *source = tfvalue(f)->source->str; | 553 | *source = tfvalue(f)->source->str; |
554 | *linedefined = tfvalue(f)->lineDefined; | 554 | *linedefined = tfvalue(f)->lineDefined; |
@@ -569,7 +569,7 @@ static int checkfunc (lua_State *L, TObject *o) { | |||
569 | const char *lua_getobjname (lua_State *L, lua_Object o, const char **name) { | 569 | const char *lua_getobjname (lua_State *L, lua_Object o, const char **name) { |
570 | /* try to find a name for given function */ | 570 | /* try to find a name for given function */ |
571 | GlobalVar *g; | 571 | GlobalVar *g; |
572 | set_normalized(L->top, Address(L, o)); /* to be used by `checkfunc' */ | 572 | set_normalized(L->top, o); /* to be used by `checkfunc' */ |
573 | for (g=L->rootglobal; g; g=g->next) { | 573 | for (g=L->rootglobal; g; g=g->next) { |
574 | if (checkfunc(L, &g->value)) { | 574 | if (checkfunc(L, &g->value)) { |
575 | *name = g->name->str; | 575 | *name = g->name->str; |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lapi.h,v 1.8 1999/11/04 17:22:26 roberto Exp roberto $ | 2 | ** $Id: lapi.h,v 1.9 1999/11/22 13:12:07 roberto Exp roberto $ |
3 | ** Auxiliary functions from Lua API | 3 | ** Auxiliary functions from Lua API |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -11,7 +11,6 @@ | |||
11 | #include "lobject.h" | 11 | #include "lobject.h" |
12 | 12 | ||
13 | 13 | ||
14 | TObject *luaA_Address (lua_State *L, lua_Object o); | ||
15 | void luaA_pushobject (lua_State *L, const TObject *o); | 14 | void luaA_pushobject (lua_State *L, const TObject *o); |
16 | GlobalVar *luaA_nextvar (lua_State *L, TaggedString *g); | 15 | GlobalVar *luaA_nextvar (lua_State *L, TaggedString *g); |
17 | int luaA_next (lua_State *L, const Hash *t, int i); | 16 | int luaA_next (lua_State *L, const Hash *t, int i); |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lbuiltin.c,v 1.78 1999/11/30 13:06:50 roberto Exp roberto $ | 2 | ** $Id: lbuiltin.c,v 1.79 1999/12/01 19:50:08 roberto Exp roberto $ |
3 | ** Built-in functions | 3 | ** Built-in functions |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -70,7 +70,7 @@ static real getnarg (lua_State *L, const Hash *a) { | |||
70 | 70 | ||
71 | 71 | ||
72 | static Hash *gettable (lua_State *L, int arg) { | 72 | static Hash *gettable (lua_State *L, int arg) { |
73 | return avalue(luaA_Address(L, luaL_tablearg(L, arg))); | 73 | return avalue(luaL_tablearg(L, arg)); |
74 | } | 74 | } |
75 | 75 | ||
76 | /* }====================================================== */ | 76 | /* }====================================================== */ |
@@ -329,7 +329,7 @@ static void luaB_call (lua_State *L) { | |||
329 | 329 | ||
330 | 330 | ||
331 | static void luaB_nextvar (lua_State *L) { | 331 | static void luaB_nextvar (lua_State *L) { |
332 | const TObject *o = luaA_Address(L, luaL_nonnullarg(L, 1)); | 332 | lua_Object o = luaL_nonnullarg(L, 1); |
333 | TaggedString *g; | 333 | TaggedString *g; |
334 | if (ttype(o) == LUA_T_NIL) | 334 | if (ttype(o) == LUA_T_NIL) |
335 | g = NULL; | 335 | g = NULL; |
@@ -344,7 +344,7 @@ static void luaB_nextvar (lua_State *L) { | |||
344 | 344 | ||
345 | static void luaB_next (lua_State *L) { | 345 | static void luaB_next (lua_State *L) { |
346 | const Hash *a = gettable(L, 1); | 346 | const Hash *a = gettable(L, 1); |
347 | const TObject *k = luaA_Address(L, luaL_nonnullarg(L, 2)); | 347 | lua_Object k = luaL_nonnullarg(L, 2); |
348 | int i; /* will get first element after `i' */ | 348 | int i; /* will get first element after `i' */ |
349 | if (ttype(k) == LUA_T_NIL) | 349 | if (ttype(k) == LUA_T_NIL) |
350 | i = 0; /* get first */ | 350 | i = 0; /* get first */ |
@@ -358,15 +358,14 @@ static void luaB_next (lua_State *L) { | |||
358 | 358 | ||
359 | 359 | ||
360 | static void luaB_tostring (lua_State *L) { | 360 | static void luaB_tostring (lua_State *L) { |
361 | lua_Object obj = lua_getparam(L, 1); | 361 | lua_Object o = lua_getparam(L, 1); |
362 | const TObject *o = luaA_Address(L, obj); | ||
363 | char buff[64]; | 362 | char buff[64]; |
364 | switch (ttype(o)) { | 363 | switch (ttype(o)) { |
365 | case LUA_T_NUMBER: | 364 | case LUA_T_NUMBER: |
366 | lua_pushstring(L, lua_getstring(L, obj)); | 365 | lua_pushstring(L, lua_getstring(L, o)); |
367 | return; | 366 | return; |
368 | case LUA_T_STRING: | 367 | case LUA_T_STRING: |
369 | lua_pushobject(L, obj); | 368 | lua_pushobject(L, o); |
370 | return; | 369 | return; |
371 | case LUA_T_ARRAY: | 370 | case LUA_T_ARRAY: |
372 | sprintf(buff, "table: %p", o->value.a); | 371 | sprintf(buff, "table: %p", o->value.a); |
@@ -417,7 +416,7 @@ static void luaB_foreachi (lua_State *L) { | |||
417 | const Hash *t = gettable(L, 1); | 416 | const Hash *t = gettable(L, 1); |
418 | int n = (int)getnarg(L, t); | 417 | int n = (int)getnarg(L, t); |
419 | int i; | 418 | int i; |
420 | StkId f = luaA_Address(L, luaL_functionarg(L, 2)); | 419 | lua_Object f = luaL_functionarg(L, 2); |
421 | luaD_checkstack(L, 3); /* for f, key, and val */ | 420 | luaD_checkstack(L, 3); /* for f, key, and val */ |
422 | for (i=1; i<=n; i++) { | 421 | for (i=1; i<=n; i++) { |
423 | *(L->top++) = *f; | 422 | *(L->top++) = *f; |
@@ -433,7 +432,7 @@ static void luaB_foreachi (lua_State *L) { | |||
433 | 432 | ||
434 | static void luaB_foreach (lua_State *L) { | 433 | static void luaB_foreach (lua_State *L) { |
435 | const Hash *a = gettable(L, 1); | 434 | const Hash *a = gettable(L, 1); |
436 | StkId f = luaA_Address(L, luaL_functionarg(L, 2)); | 435 | lua_Object f = luaL_functionarg(L, 2); |
437 | int i; | 436 | int i; |
438 | luaD_checkstack(L, 3); /* for f, key, and val */ | 437 | luaD_checkstack(L, 3); /* for f, key, and val */ |
439 | for (i=0; i<a->size; i++) { | 438 | for (i=0; i<a->size; i++) { |
@@ -452,7 +451,7 @@ static void luaB_foreach (lua_State *L) { | |||
452 | 451 | ||
453 | 452 | ||
454 | static void luaB_foreachvar (lua_State *L) { | 453 | static void luaB_foreachvar (lua_State *L) { |
455 | StkId f = luaA_Address(L, luaL_functionarg(L, 1)); | 454 | lua_Object f = luaL_functionarg(L, 1); |
456 | GlobalVar *gv; | 455 | GlobalVar *gv; |
457 | luaD_checkstack(L, 4); /* for extra var name, f, var name, and globalval */ | 456 | luaD_checkstack(L, 4); /* for extra var name, f, var name, and globalval */ |
458 | for (gv = L->rootglobal; gv; gv = gv->next) { | 457 | for (gv = L->rootglobal; gv; gv = gv->next) { |
@@ -492,7 +491,7 @@ static void luaB_tinsert (lua_State *L) { | |||
492 | luaV_setn(L, a, n+1); /* a.n = n+1 */ | 491 | luaV_setn(L, a, n+1); /* a.n = n+1 */ |
493 | for ( ;n>=pos; n--) | 492 | for ( ;n>=pos; n--) |
494 | luaH_move(L, a, n, n+1); /* a[n+1] = a[n] */ | 493 | luaH_move(L, a, n, n+1); /* a[n+1] = a[n] */ |
495 | luaH_setint(L, a, pos, luaA_Address(L, v)); /* a[pos] = v */ | 494 | luaH_setint(L, a, pos, v); /* a[pos] = v */ |
496 | } | 495 | } |
497 | 496 | ||
498 | 497 | ||
@@ -525,7 +524,7 @@ static int sort_comp (lua_State *L, lua_Object f, const TObject *a, | |||
525 | const TObject *b) { | 524 | const TObject *b) { |
526 | /* notice: the caller (auxsort) must check stack space */ | 525 | /* notice: the caller (auxsort) must check stack space */ |
527 | if (f != LUA_NOOBJECT) { | 526 | if (f != LUA_NOOBJECT) { |
528 | *(L->top) = *luaA_Address(L, f); | 527 | *(L->top) = *f; |
529 | *(L->top+1) = *a; | 528 | *(L->top+1) = *a; |
530 | *(L->top+2) = *b; | 529 | *(L->top+2) = *b; |
531 | L->top += 3; | 530 | L->top += 3; |
@@ -618,20 +617,20 @@ static void mem_query (lua_State *L) { | |||
618 | 617 | ||
619 | 618 | ||
620 | static void hash_query (lua_State *L) { | 619 | static void hash_query (lua_State *L) { |
621 | const TObject *o = luaA_Address(L, luaL_nonnullarg(L, 1)); | 620 | lua_Object o = luaL_nonnullarg(L, 1); |
622 | if (lua_getparam(L, 2) == LUA_NOOBJECT) { | 621 | if (lua_getparam(L, 2) == LUA_NOOBJECT) { |
623 | luaL_arg_check(L, ttype(o) == LUA_T_STRING, 1, "string expected"); | 622 | luaL_arg_check(L, ttype(o) == LUA_T_STRING, 1, "string expected"); |
624 | lua_pushnumber(L, tsvalue(o)->hash); | 623 | lua_pushnumber(L, tsvalue(o)->hash); |
625 | } | 624 | } |
626 | else { | 625 | else { |
627 | const Hash *t = avalue(luaA_Address(L, luaL_tablearg(L, 2))); | 626 | const Hash *t = avalue(luaL_tablearg(L, 2)); |
628 | lua_pushnumber(L, luaH_mainposition(L, t, o) - t->node); | 627 | lua_pushnumber(L, luaH_mainposition(L, t, o) - t->node); |
629 | } | 628 | } |
630 | } | 629 | } |
631 | 630 | ||
632 | 631 | ||
633 | static void table_query (lua_State *L) { | 632 | static void table_query (lua_State *L) { |
634 | const Hash *t = avalue(luaA_Address(L, luaL_tablearg(L, 1))); | 633 | const Hash *t = avalue(luaL_tablearg(L, 1)); |
635 | int i = luaL_opt_int(L, 2, -1); | 634 | int i = luaL_opt_int(L, 2, -1); |
636 | if (i == -1) { | 635 | if (i == -1) { |
637 | lua_pushnumber(L, t->size); | 636 | lua_pushnumber(L, t->size); |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ldo.c,v 1.53 1999/11/25 18:58:51 roberto Exp roberto $ | 2 | ** $Id: ldo.c,v 1.54 1999/12/01 19:50:08 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 | */ |
@@ -121,8 +121,8 @@ void luaD_callHook (lua_State *L, StkId base, const TProtoFunc *tf, | |||
121 | else { | 121 | else { |
122 | TObject *f = base-1; | 122 | TObject *f = base-1; |
123 | if (tf) | 123 | if (tf) |
124 | (*L->callhook)(L, Ref(L, f), tf->source->str, tf->lineDefined); | 124 | v 1.3 1997/10/16, f, tf->source->str, tf->lineDefined); |
125 | else (*L->callhook)(L, Ref(L, f), "(C)", -1); | 125 | else (*L->callhook)(L, f, "(C)", -1); |
126 | } | 126 | } |
127 | L->top = old_top; | 127 | L->top = old_top; |
128 | L->Cstack = oldCLS; | 128 | L->Cstack = oldCLS; |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ldo.h,v 1.11 1999/11/25 18:58:51 roberto Exp roberto $ | 2 | ** $Id: ldo.h,v 1.12 1999/12/01 19:50:08 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 | */ |
@@ -23,12 +23,6 @@ | |||
23 | #define incr_top {if (L->top == L->stack_last) luaD_checkstack(L, 1); L->top++;} | 23 | #define incr_top {if (L->top == L->stack_last) luaD_checkstack(L, 1); L->top++;} |
24 | 24 | ||
25 | 25 | ||
26 | /* macros to convert from lua_Object to (TObject *) and back */ | ||
27 | |||
28 | #define Address(L, lo) ((lo)+L->stack-1) | ||
29 | #define Ref(L, st) ((st)-L->stack+1) | ||
30 | |||
31 | |||
32 | void luaD_init (lua_State *L); | 26 | void luaD_init (lua_State *L); |
33 | void luaD_adjusttop (lua_State *L, StkId base, int extra); | 27 | void luaD_adjusttop (lua_State *L, StkId base, int extra); |
34 | void luaD_openstack (lua_State *L, StkId pos); | 28 | void luaD_openstack (lua_State *L, StkId pos); |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lobject.h,v 1.37 1999/11/22 13:12:07 roberto Exp roberto $ | 2 | ** $Id: lobject.h,v 1.38 1999/11/26 18:59:20 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 | */ |
@@ -26,6 +26,8 @@ | |||
26 | #endif | 26 | #endif |
27 | 27 | ||
28 | 28 | ||
29 | #define UNUSED(x) (void)x /* to avoid warnings */ | ||
30 | |||
29 | /* | 31 | /* |
30 | ** "real" is the type "number" of Lua | 32 | ** "real" is the type "number" of Lua |
31 | ** GREP LUA_NUMBER to change that | 33 | ** GREP LUA_NUMBER to change that |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lua.h,v 1.40 1999/11/29 19:11:36 roberto Exp roberto $ | 2 | ** $Id: lua.h,v 1.41 1999/11/29 19:31:29 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 |
@@ -16,8 +16,6 @@ | |||
16 | #define LUA_AUTHORS "W. Celes, R. Ierusalimschy & L. H. de Figueiredo" | 16 | #define LUA_AUTHORS "W. Celes, R. Ierusalimschy & L. H. de Figueiredo" |
17 | 17 | ||
18 | 18 | ||
19 | #define LUA_NOOBJECT 0 | ||
20 | |||
21 | #define LUA_NOREF (-2) | 19 | #define LUA_NOREF (-2) |
22 | #define LUA_REFNIL (-1) | 20 | #define LUA_REFNIL (-1) |
23 | 21 | ||
@@ -26,7 +24,11 @@ | |||
26 | typedef struct lua_State lua_State; | 24 | typedef struct lua_State lua_State; |
27 | 25 | ||
28 | typedef void (*lua_CFunction) ( /* lua_State *L */ ); | 26 | typedef void (*lua_CFunction) ( /* lua_State *L */ ); |
29 | typedef unsigned int lua_Object; | 27 | |
28 | typedef struct TObject *lua_Object; | ||
29 | |||
30 | #define LUA_NOOBJECT ((lua_Object)0) | ||
31 | |||
30 | 32 | ||
31 | lua_State *lua_newstate (void); | 33 | lua_State *lua_newstate (void); |
32 | void lua_close (lua_State *L); | 34 | void lua_close (lua_State *L); |