diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1994-11-07 14:34:44 -0200 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1994-11-07 14:34:44 -0200 |
commit | d95a8b312166752e2211678b33514edb1d68a0a6 (patch) | |
tree | 87a7180705c1c5e6db71831fb8cb49ce8980f4d0 | |
parent | 9ffba7a3dbdfa68595cd8cec26bd99689ce5fd08 (diff) | |
download | lua-d95a8b312166752e2211678b33514edb1d68a0a6.tar.gz lua-d95a8b312166752e2211678b33514edb1d68a0a6.tar.bz2 lua-d95a8b312166752e2211678b33514edb1d68a0a6.zip |
new API: lua_Object now is an integer
-rw-r--r-- | hash.c | 22 | ||||
-rw-r--r-- | inout.c | 33 | ||||
-rw-r--r-- | lua.h | 28 | ||||
-rw-r--r-- | opcode.c | 145 | ||||
-rw-r--r-- | opcode.h | 5 | ||||
-rw-r--r-- | table.c | 20 |
6 files changed, 112 insertions, 141 deletions
@@ -3,7 +3,7 @@ | |||
3 | ** hash manager for lua | 3 | ** hash manager for lua |
4 | */ | 4 | */ |
5 | 5 | ||
6 | char *rcs_hash="$Id: hash.c,v 2.12 1994/11/03 22:20:15 roberto Exp $"; | 6 | char *rcs_hash="$Id: hash.c,v 2.13 1994/11/07 15:19:51 roberto Exp roberto $"; |
7 | 7 | ||
8 | #include <string.h> | 8 | #include <string.h> |
9 | #include <stdlib.h> | 9 | #include <stdlib.h> |
@@ -293,29 +293,29 @@ static void hashnext (Hash *t, int i) | |||
293 | return; | 293 | return; |
294 | } | 294 | } |
295 | } | 295 | } |
296 | lua_pushobject(ref(node(t,i))); | 296 | luaI_pushobject(ref(node(t,i))); |
297 | lua_pushobject(val(node(t,i))); | 297 | luaI_pushobject(val(node(t,i))); |
298 | } | 298 | } |
299 | 299 | ||
300 | void lua_next (void) | 300 | void lua_next (void) |
301 | { | 301 | { |
302 | Hash *t; | 302 | Hash *t; |
303 | Object *o = lua_getparam (1); | 303 | lua_Object o = lua_getparam(1); |
304 | Object *r = lua_getparam (2); | 304 | lua_Object r = lua_getparam(2); |
305 | if (o == NULL || r == NULL) | 305 | if (o == 0 || r == 0) |
306 | lua_error ("too few arguments to function `next'"); | 306 | lua_error ("too few arguments to function `next'"); |
307 | if (lua_getparam (3) != NULL) | 307 | if (lua_getparam(3) != 0) |
308 | lua_error ("too many arguments to function `next'"); | 308 | lua_error ("too many arguments to function `next'"); |
309 | if (tag(o) != LUA_T_ARRAY) | 309 | if (!lua_istable(o)) |
310 | lua_error ("first argument of function `next' is not a table"); | 310 | lua_error ("first argument of function `next' is not a table"); |
311 | t = avalue(o); | 311 | t = avalue(luaI_Address(o)); |
312 | if (tag(r) == LUA_T_NIL) | 312 | if (lua_isnil(r)) |
313 | { | 313 | { |
314 | hashnext(t, 0); | 314 | hashnext(t, 0); |
315 | } | 315 | } |
316 | else | 316 | else |
317 | { | 317 | { |
318 | int h = present (t, r); | 318 | int h = present (t, luaI_Address(r)); |
319 | hashnext(t, h+1); | 319 | hashnext(t, h+1); |
320 | } | 320 | } |
321 | } | 321 | } |
@@ -5,7 +5,7 @@ | |||
5 | ** Also provides some predefined lua functions. | 5 | ** Also provides some predefined lua functions. |
6 | */ | 6 | */ |
7 | 7 | ||
8 | char *rcs_inout="$Id: inout.c,v 2.6 1994/11/02 20:29:39 roberto Exp roberto $"; | 8 | char *rcs_inout="$Id: inout.c,v 2.7 1994/11/03 22:34:29 roberto Exp roberto $"; |
9 | 9 | ||
10 | #include <stdio.h> | 10 | #include <stdio.h> |
11 | #include <stdlib.h> | 11 | #include <stdlib.h> |
@@ -32,15 +32,6 @@ static int nfuncstack=0; | |||
32 | 32 | ||
33 | static FILE *fp; | 33 | static FILE *fp; |
34 | static char *st; | 34 | static char *st; |
35 | static void (*usererror) (char *s); | ||
36 | |||
37 | /* | ||
38 | ** Function to set user function to handle errors. | ||
39 | */ | ||
40 | void lua_errorfunction (void (*fn) (char *s)) | ||
41 | { | ||
42 | usererror = fn; | ||
43 | } | ||
44 | 35 | ||
45 | /* | 36 | /* |
46 | ** Function to get the next character from the input file | 37 | ** Function to get the next character from the input file |
@@ -202,16 +193,16 @@ void lua_internaldofile (void) | |||
202 | void lua_print (void) | 193 | void lua_print (void) |
203 | { | 194 | { |
204 | int i=1; | 195 | int i=1; |
205 | Object *obj; | 196 | lua_Object obj; |
206 | while ((obj=lua_getparam (i++)) != NULL) | 197 | while ((obj=lua_getparam (i++)) != 0) |
207 | { | 198 | { |
208 | if (lua_isnumber(obj)) printf("%g\n",lua_getnumber (obj)); | 199 | if (lua_isnumber(obj)) printf("%g\n",lua_getnumber(obj)); |
209 | else if (lua_isstring(obj)) printf("%s\n",lua_getstring (obj)); | 200 | else if (lua_isstring(obj)) printf("%s\n",lua_getstring(obj)); |
210 | else if (lua_isfunction(obj)) printf("function: %p\n",bvalue(obj)); | 201 | else if (lua_isfunction(obj)) printf("function: %p\n",bvalue(luaI_Address(obj))); |
211 | else if (lua_iscfunction(obj)) printf("cfunction: %p\n",lua_getcfunction (obj) | 202 | else if (lua_iscfunction(obj)) printf("cfunction: %p\n",lua_getcfunction(obj) |
212 | ); | 203 | ); |
213 | else if (lua_isuserdata(obj)) printf("userdata: %p\n",lua_getuserdata (obj)); | 204 | else if (lua_isuserdata(obj)) printf("userdata: %p\n",lua_getuserdata(obj)); |
214 | else if (lua_istable(obj)) printf("table: %p\n",avalue(obj)); | 205 | else if (lua_istable(obj)) printf("table: %p\n",avalue(luaI_Address(obj))); |
215 | else if (lua_isnil(obj)) printf("nil\n"); | 206 | else if (lua_isnil(obj)) printf("nil\n"); |
216 | else printf("invalid value to print\n"); | 207 | else printf("invalid value to print\n"); |
217 | } | 208 | } |
@@ -223,10 +214,10 @@ void lua_print (void) | |||
223 | */ | 214 | */ |
224 | void luaI_type (void) | 215 | void luaI_type (void) |
225 | { | 216 | { |
226 | Object *o = lua_getparam(1); | 217 | lua_Object o = lua_getparam(1); |
227 | if (o == NULL) | 218 | if (o == 0) |
228 | lua_error("no parameter to function 'type'"); | 219 | lua_error("no parameter to function 'type'"); |
229 | switch (tag(o)) | 220 | switch (lua_type(o)) |
230 | { | 221 | { |
231 | case LUA_T_NIL : | 222 | case LUA_T_NIL : |
232 | lua_pushstring("nil"); | 223 | lua_pushstring("nil"); |
@@ -2,7 +2,7 @@ | |||
2 | ** LUA - Linguagem para Usuarios de Aplicacao | 2 | ** LUA - Linguagem para Usuarios de Aplicacao |
3 | ** Grupo de Tecnologia em Computacao Grafica | 3 | ** Grupo de Tecnologia em Computacao Grafica |
4 | ** TeCGraf - PUC-Rio | 4 | ** TeCGraf - PUC-Rio |
5 | ** $Id: lua.h,v 3.1 1994/11/02 20:30:53 roberto Exp roberto $ | 5 | ** $Id: lua.h,v 3.2 1994/11/04 10:47:49 roberto Exp roberto $ |
6 | */ | 6 | */ |
7 | 7 | ||
8 | 8 | ||
@@ -21,56 +21,52 @@ typedef enum | |||
21 | LUA_T_FUNCTION, | 21 | LUA_T_FUNCTION, |
22 | LUA_T_CFUNCTION, | 22 | LUA_T_CFUNCTION, |
23 | LUA_T_USERDATA | 23 | LUA_T_USERDATA |
24 | } Type; | 24 | } lua_Type; |
25 | 25 | ||
26 | 26 | ||
27 | /* Public Part */ | 27 | /* Public Part */ |
28 | 28 | ||
29 | typedef void (*lua_CFunction) (void); | 29 | typedef void (*lua_CFunction) (void); |
30 | typedef struct Object *lua_Object; | 30 | typedef unsigned int lua_Object; |
31 | 31 | ||
32 | #define lua_register(n,f) (lua_pushcfunction(f), lua_storeglobal(n)) | ||
33 | |||
34 | void lua_errorfunction (void (*fn) (char *s)); | ||
35 | void lua_error (char *s); | 32 | void lua_error (char *s); |
36 | int lua_dofile (char *filename); | 33 | int lua_dofile (char *filename); |
37 | int lua_dostring (char *string); | 34 | int lua_dostring (char *string); |
38 | int lua_callfunction (lua_Object function); | 35 | int lua_callfunction (lua_Object function); |
39 | 36 | ||
40 | lua_Object lua_getparam (int number); | 37 | lua_Object lua_getparam (int number); |
38 | #define lua_getresult lua_getparam | ||
39 | |||
41 | float lua_getnumber (lua_Object object); | 40 | float lua_getnumber (lua_Object object); |
42 | char *lua_getstring (lua_Object object); | 41 | char *lua_getstring (lua_Object object); |
43 | char *lua_copystring (lua_Object object); | 42 | char *lua_copystring (lua_Object object); |
44 | lua_CFunction lua_getcfunction (lua_Object object); | 43 | lua_CFunction lua_getcfunction (lua_Object object); |
45 | void *lua_getuserdata (lua_Object object); | 44 | void *lua_getuserdata (lua_Object object); |
46 | void *lua_gettable (lua_Object object); | ||
47 | lua_Object lua_getfield (lua_Object object, char *field); | ||
48 | lua_Object lua_getindexed (lua_Object object, float index); | ||
49 | lua_Object lua_getglobal (char *name); | ||
50 | 45 | ||
51 | int lua_pushnil (void); | 46 | int lua_pushnil (void); |
52 | int lua_pushnumber (float n); | 47 | int lua_pushnumber (float n); |
53 | int lua_pushstring (char *s); | 48 | int lua_pushstring (char *s); |
54 | int lua_pushcfunction (lua_CFunction fn); | 49 | int lua_pushcfunction (lua_CFunction fn); |
55 | int lua_pushuserdata (void *u); | 50 | int lua_pushuserdata (void *u); |
56 | int lua_pushtable (void *t); | ||
57 | int lua_pushsubscript (void); | ||
58 | int lua_pushobject (lua_Object object); | 51 | int lua_pushobject (lua_Object object); |
59 | 52 | ||
53 | lua_Object lua_getglobal (char *name); | ||
60 | int lua_storeglobal (char *name); | 54 | int lua_storeglobal (char *name); |
61 | int lua_storefield (lua_Object object, char *field); | 55 | |
62 | int lua_storeindexed (lua_Object object, float index); | ||
63 | int lua_storesubscript (void); | 56 | int lua_storesubscript (void); |
57 | lua_Object lua_getIndex (void); | ||
64 | 58 | ||
65 | int lua_type (lua_Object object); | 59 | int lua_type (lua_Object object); |
66 | 60 | ||
67 | 61 | ||
68 | /* for lua 1.1 */ | 62 | /* for lua 1.1 */ |
69 | 63 | ||
64 | #define lua_register(n,f) (lua_pushcfunction(f), lua_storeglobal(n)) | ||
65 | |||
70 | #define lua_call(f) lua_callfunction(lua_getglobal(f)) | 66 | #define lua_call(f) lua_callfunction(lua_getglobal(f)) |
71 | 67 | ||
72 | #define lua_getindexed(o,n) (lua_pushnumber(n), lua_getIndex(o)) | 68 | #define lua_getindexed(o,n) (lua_pushobject(o), lua_pushnumber(n), lua_getIndex()) |
73 | #define lua_getfield(o,f) (lua_pushstring(f), lua_getIndex(o)) | 69 | #define lua_getfield(o,f) (lua_pushobject(o), lua_pushstring(f), lua_getIndex()) |
74 | 70 | ||
75 | #define lua_isnil(_) (lua_type(_)==LUA_T_NIL) | 71 | #define lua_isnil(_) (lua_type(_)==LUA_T_NIL) |
76 | #define lua_isnumber(_) (lua_type(_)==LUA_T_NUMBER) | 72 | #define lua_isnumber(_) (lua_type(_)==LUA_T_NUMBER) |
@@ -3,7 +3,7 @@ | |||
3 | ** TecCGraf - PUC-Rio | 3 | ** TecCGraf - PUC-Rio |
4 | */ | 4 | */ |
5 | 5 | ||
6 | char *rcs_opcode="$Id: opcode.c,v 3.2 1994/11/04 10:47:49 roberto Exp roberto $"; | 6 | char *rcs_opcode="$Id: opcode.c,v 3.3 1994/11/07 15:20:56 roberto Exp $"; |
7 | 7 | ||
8 | #include <stdio.h> | 8 | #include <stdio.h> |
9 | #include <stdlib.h> | 9 | #include <stdlib.h> |
@@ -32,6 +32,12 @@ static Object *stack = NULL; | |||
32 | static Object *top = NULL; | 32 | static Object *top = NULL; |
33 | 33 | ||
34 | 34 | ||
35 | /* macros to convert from lua_Object to (Object *) and back */ | ||
36 | |||
37 | #define Address(lo) ((lo)+stack-1) | ||
38 | #define Ref(st) ((st)-stack+1) | ||
39 | |||
40 | |||
35 | static int CBase = 0; /* when Lua calls C or C calls Lua, points to the */ | 41 | static int CBase = 0; /* when Lua calls C or C calls Lua, points to the */ |
36 | /* first slot after the last parameter. */ | 42 | /* first slot after the last parameter. */ |
37 | static int CnResults = 0; /* when Lua calls C, has the number of parameters; */ | 43 | static int CnResults = 0; /* when Lua calls C, has the number of parameters; */ |
@@ -44,6 +50,12 @@ static int lua_execute (Byte *pc, int base); | |||
44 | static void do_call (Object *func, int base, int nResults, int whereRes); | 50 | static void do_call (Object *func, int base, int nResults, int whereRes); |
45 | 51 | ||
46 | 52 | ||
53 | Object *luaI_Address (lua_Object o) | ||
54 | { | ||
55 | return Address(o); | ||
56 | } | ||
57 | |||
58 | |||
47 | /* | 59 | /* |
48 | ** Fallbacks | 60 | ** Fallbacks |
49 | */ | 61 | */ |
@@ -87,8 +99,8 @@ void luaI_setfallback (void) | |||
87 | { | 99 | { |
88 | if (strcmp(fallBacks[i].kind, name) == 0) | 100 | if (strcmp(fallBacks[i].kind, name) == 0) |
89 | { | 101 | { |
90 | lua_pushobject(&fallBacks[i].function); | 102 | lua_pushobject(Ref(&fallBacks[i].function)); |
91 | fallBacks[i].function = *func; | 103 | fallBacks[i].function = *Address(func); |
92 | return; | 104 | return; |
93 | } | 105 | } |
94 | } | 106 | } |
@@ -96,6 +108,7 @@ void luaI_setfallback (void) | |||
96 | lua_pushnil(); | 108 | lua_pushnil(); |
97 | } | 109 | } |
98 | 110 | ||
111 | |||
99 | /* | 112 | /* |
100 | ** Error messages | 113 | ** Error messages |
101 | */ | 114 | */ |
@@ -373,12 +386,12 @@ static int do_protectedrun (Object *function, int nResults) | |||
373 | /* | 386 | /* |
374 | ** Execute the given lua function. Return 0 on success or 1 on error. | 387 | ** Execute the given lua function. Return 0 on success or 1 on error. |
375 | */ | 388 | */ |
376 | int lua_callfunction (Object *function) | 389 | int lua_callfunction (lua_Object function) |
377 | { | 390 | { |
378 | if (function == NULL) | 391 | if (function == NULL) |
379 | return 1; | 392 | return 1; |
380 | else | 393 | else |
381 | return do_protectedrun (function, MULT_RET); | 394 | return do_protectedrun (Address(function), MULT_RET); |
382 | } | 395 | } |
383 | 396 | ||
384 | 397 | ||
@@ -420,73 +433,77 @@ int lua_dostring (char *string) | |||
420 | 433 | ||
421 | 434 | ||
422 | /* | 435 | /* |
423 | ** Get a parameter, returning the object handle or NULL on error. | 436 | ** Get a parameter, returning the object handle or 0 on error. |
424 | ** 'number' must be 1 to get the first parameter. | 437 | ** 'number' must be 1 to get the first parameter. |
425 | */ | 438 | */ |
426 | Object *lua_getparam (int number) | 439 | lua_Object lua_getparam (int number) |
427 | { | 440 | { |
428 | if (number <= 0 || number > CnResults) return NULL; | 441 | if (number <= 0 || number > CnResults) return 0; |
429 | return (stack+(CBase-CnResults+number-1)); | 442 | /* Ref(stack+(CBase-CnResults+number-1)) == |
443 | stack+(CBase-CnResults+number-1)-stack+1 == */ | ||
444 | return CBase-CnResults+number; | ||
430 | } | 445 | } |
431 | 446 | ||
432 | /* | 447 | /* |
433 | ** Given an object handle, return its number value. On error, return 0.0. | 448 | ** Given an object handle, return its number value. On error, return 0.0. |
434 | */ | 449 | */ |
435 | real lua_getnumber (Object *object) | 450 | real lua_getnumber (lua_Object object) |
436 | { | 451 | { |
437 | if (object == NULL || tag(object) == LUA_T_NIL) return 0.0; | 452 | if (object == 0 || tag(Address(object)) == LUA_T_NIL) return 0.0; |
438 | if (tonumber (object)) return 0.0; | 453 | if (tonumber (Address(object))) return 0.0; |
439 | else return (nvalue(object)); | 454 | else return (nvalue(Address(object))); |
440 | } | 455 | } |
441 | 456 | ||
442 | /* | 457 | /* |
443 | ** Given an object handle, return its string pointer. On error, return NULL. | 458 | ** Given an object handle, return its string pointer. On error, return NULL. |
444 | */ | 459 | */ |
445 | char *lua_getstring (Object *object) | 460 | char *lua_getstring (lua_Object object) |
446 | { | 461 | { |
447 | if (object == NULL || tag(object) == LUA_T_NIL) return NULL; | 462 | if (object == 0 || tag(Address(object)) == LUA_T_NIL) return NULL; |
448 | if (tostring (object)) return NULL; | 463 | if (tostring (Address(object))) return NULL; |
449 | else return (svalue(object)); | 464 | else return (svalue(Address(object))); |
450 | } | 465 | } |
451 | 466 | ||
452 | /* | 467 | /* |
453 | ** Given an object handle, return a copy of its string. On error, return NULL. | 468 | ** Given an object handle, return a copy of its string. On error, return NULL. |
454 | */ | 469 | */ |
455 | char *lua_copystring (Object *object) | 470 | char *lua_copystring (lua_Object object) |
456 | { | 471 | { |
457 | if (object == NULL || tag(object) == LUA_T_NIL) return NULL; | 472 | if (object == 0 || tag(Address(object)) == LUA_T_NIL) return NULL; |
458 | if (tostring (object)) return NULL; | 473 | if (tostring (Address(object))) return NULL; |
459 | else return (strdup(svalue(object))); | 474 | else return (strdup(svalue(Address(object)))); |
460 | } | 475 | } |
461 | 476 | ||
462 | /* | 477 | /* |
463 | ** Given an object handle, return its cfuntion pointer. On error, return NULL. | 478 | ** Given an object handle, return its cfuntion pointer. On error, return NULL. |
464 | */ | 479 | */ |
465 | lua_CFunction lua_getcfunction (Object *object) | 480 | lua_CFunction lua_getcfunction (lua_Object object) |
466 | { | 481 | { |
467 | if (object == NULL) return NULL; | 482 | if (object == 0) return NULL; |
468 | if (tag(object) != LUA_T_CFUNCTION) return NULL; | 483 | if (tag(Address(object)) != LUA_T_CFUNCTION) return NULL; |
469 | else return (fvalue(object)); | 484 | else return (fvalue(Address(object))); |
470 | } | 485 | } |
471 | 486 | ||
472 | /* | 487 | /* |
473 | ** Given an object handle, return its user data. On error, return NULL. | 488 | ** Given an object handle, return its user data. On error, return NULL. |
474 | */ | 489 | */ |
475 | void *lua_getuserdata (Object *object) | 490 | void *lua_getuserdata (lua_Object object) |
476 | { | 491 | { |
477 | if (object == NULL) return NULL; | 492 | if (object == 0) return NULL; |
478 | if (tag(object) != LUA_T_USERDATA) return NULL; | 493 | if (tag(Address(object)) != LUA_T_USERDATA) return NULL; |
479 | else return (uvalue(object)); | 494 | else return (uvalue(Address(object))); |
480 | } | 495 | } |
481 | 496 | ||
482 | /* | 497 | /* |
483 | ** Get a global object. Return the object handle or NULL on error. | 498 | ** Get a global object. Return the object handle or NULL on error. |
484 | */ | 499 | */ |
485 | Object *lua_getglobal (char *name) | 500 | lua_Object lua_getglobal (char *name) |
486 | { | 501 | { |
487 | int n = lua_findsymbol(name); | 502 | int n = lua_findsymbol(name); |
488 | if (n < 0) return NULL; | 503 | if (n < 0) return 0; |
489 | return &s_object(n); | 504 | *(top-1) = s_object(n); |
505 | top++; | ||
506 | return Ref(top-1); | ||
490 | } | 507 | } |
491 | 508 | ||
492 | /* | 509 | /* |
@@ -541,16 +558,25 @@ int lua_pushuserdata (void *u) | |||
541 | } | 558 | } |
542 | 559 | ||
543 | /* | 560 | /* |
544 | ** Push an object to stack. | 561 | ** Push a lua_Object to stack. |
545 | */ | 562 | */ |
546 | int lua_pushobject (Object *o) | 563 | int lua_pushobject (lua_Object o) |
547 | { | 564 | { |
548 | lua_checkstack(top-stack+1); | 565 | lua_checkstack(top-stack+1); |
549 | *top++ = *o; | 566 | *top++ = *Address(o); |
550 | return 0; | 567 | return 0; |
551 | } | 568 | } |
552 | 569 | ||
553 | /* | 570 | /* |
571 | ** Push an object on the stack. | ||
572 | */ | ||
573 | void luaI_pushobject (Object *o) | ||
574 | { | ||
575 | lua_checkstack(top-stack+1); | ||
576 | *top++ = *o; | ||
577 | } | ||
578 | |||
579 | /* | ||
554 | ** Store top of the stack at a global variable array field. | 580 | ** Store top of the stack at a global variable array field. |
555 | ** Return 1 on error, 0 on success. | 581 | ** Return 1 on error, 0 on success. |
556 | */ | 582 | */ |
@@ -558,60 +584,16 @@ int lua_storeglobal (char *name) | |||
558 | { | 584 | { |
559 | int n = lua_findsymbol (name); | 585 | int n = lua_findsymbol (name); |
560 | if (n < 0) return 1; | 586 | if (n < 0) return 1; |
561 | if (top-stack <= CBase) return 1; | ||
562 | s_object(n) = *(--top); | 587 | s_object(n) = *(--top); |
563 | return 0; | 588 | return 0; |
564 | } | 589 | } |
565 | 590 | ||
566 | |||
567 | /* | ||
568 | ** Store top of the stack at an array field. Return 1 on error, 0 on success. | ||
569 | */ | ||
570 | int lua_storefield (lua_Object object, char *field) | ||
571 | { | ||
572 | if (tag(object) != LUA_T_ARRAY) | ||
573 | return 1; | ||
574 | else | ||
575 | { | ||
576 | Object ref, *h; | ||
577 | tag(&ref) = LUA_T_STRING; | ||
578 | svalue(&ref) = lua_createstring(field); | ||
579 | h = lua_hashdefine(avalue(object), &ref); | ||
580 | if (h == NULL) return 1; | ||
581 | if (tag(top-1) == LUA_T_MARK) return 1; | ||
582 | *h = *(--top); | ||
583 | } | ||
584 | return 0; | ||
585 | } | ||
586 | |||
587 | |||
588 | /* | ||
589 | ** Store top of the stack at an array index. Return 1 on error, 0 on success. | ||
590 | */ | ||
591 | int lua_storeindexed (lua_Object object, float index) | ||
592 | { | ||
593 | if (tag(object) != LUA_T_ARRAY) | ||
594 | return 1; | ||
595 | else | ||
596 | { | ||
597 | Object ref, *h; | ||
598 | tag(&ref) = LUA_T_NUMBER; | ||
599 | nvalue(&ref) = index; | ||
600 | h = lua_hashdefine(avalue(object), &ref); | ||
601 | if (h == NULL) return 1; | ||
602 | if (tag(top-1) == LUA_T_MARK) return 1; | ||
603 | *h = *(--top); | ||
604 | } | ||
605 | return 0; | ||
606 | } | ||
607 | |||
608 | |||
609 | int lua_type (lua_Object o) | 591 | int lua_type (lua_Object o) |
610 | { | 592 | { |
611 | if (o == NULL) | 593 | if (o == 0) |
612 | return LUA_T_NIL; | 594 | return LUA_T_NIL; |
613 | else | 595 | else |
614 | return tag(o); | 596 | return tag(Address(o)); |
615 | } | 597 | } |
616 | 598 | ||
617 | 599 | ||
@@ -1063,3 +1045,4 @@ static int lua_execute (Byte *pc, int base) | |||
1063 | } | 1045 | } |
1064 | } | 1046 | } |
1065 | 1047 | ||
1048 | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | ** TeCGraf - PUC-Rio | 2 | ** TeCGraf - PUC-Rio |
3 | ** $Id: opcode.h,v 3.3 1994/11/06 15:35:04 roberto Exp $ | 3 | ** $Id: opcode.h,v 3.4 1994/11/07 15:20:56 roberto Exp roberto $ |
4 | */ | 4 | */ |
5 | 5 | ||
6 | #ifndef opcode_h | 6 | #ifndef opcode_h |
@@ -152,7 +152,6 @@ typedef struct | |||
152 | code.m.c3 = *pc++; code.m.c4 = *pc++;} | 152 | code.m.c3 = *pc++; code.m.c4 = *pc++;} |
153 | 153 | ||
154 | 154 | ||
155 | |||
156 | /* Exported functions */ | 155 | /* Exported functions */ |
157 | char *lua_strdup (char *l); | 156 | char *lua_strdup (char *l); |
158 | 157 | ||
@@ -162,5 +161,7 @@ int yylex (void); /* from "lex.c" module */ | |||
162 | Byte *lua_parse (void); /* from "lua.stx" module */ | 161 | Byte *lua_parse (void); /* from "lua.stx" module */ |
163 | void lua_travstack (void (*fn)(Object *)); | 162 | void lua_travstack (void (*fn)(Object *)); |
164 | void luaI_setfallback (void); | 163 | void luaI_setfallback (void); |
164 | Object *luaI_Address (lua_Object o); | ||
165 | void luaI_pushobject (Object *o); | ||
165 | 166 | ||
166 | #endif | 167 | #endif |
@@ -3,7 +3,7 @@ | |||
3 | ** Module to control static tables | 3 | ** Module to control static tables |
4 | */ | 4 | */ |
5 | 5 | ||
6 | char *rcs_table="$Id: table.c,v 2.10 1994/11/03 22:33:40 roberto Exp roberto $"; | 6 | char *rcs_table="$Id: table.c,v 2.11 1994/11/04 17:20:00 roberto Exp roberto $"; |
7 | 7 | ||
8 | #include <stdlib.h> | 8 | #include <stdlib.h> |
9 | #include <string.h> | 9 | #include <string.h> |
@@ -259,23 +259,23 @@ char *lua_filename (void) | |||
259 | void lua_nextvar (void) | 259 | void lua_nextvar (void) |
260 | { | 260 | { |
261 | char *varname, *next; | 261 | char *varname, *next; |
262 | Object *o = lua_getparam (1); | 262 | lua_Object o = lua_getparam(1); |
263 | if (o == NULL) | 263 | if (o == 0) |
264 | { lua_error ("too few arguments to function `nextvar'"); return; } | 264 | { lua_error ("too few arguments to function `nextvar'"); return; } |
265 | if (lua_getparam (2) != NULL) | 265 | if (lua_getparam(2) != NULL) |
266 | { lua_error ("too many arguments to function `nextvar'"); return; } | 266 | { lua_error ("too many arguments to function `nextvar'"); return; } |
267 | if (tag(o) == LUA_T_NIL) | 267 | if (lua_isnil(o)) |
268 | { | 268 | { |
269 | varname = 0; | 269 | varname = NULL; |
270 | } | 270 | } |
271 | else if (tag(o) != LUA_T_STRING) | 271 | else if (!lua_isstring(o)) |
272 | { | 272 | { |
273 | lua_error ("incorrect argument to function `nextvar'"); | 273 | lua_error ("incorrect argument to function `nextvar'"); |
274 | return; | 274 | return; |
275 | } | 275 | } |
276 | else | 276 | else |
277 | { | 277 | { |
278 | varname = svalue(o); | 278 | varname = lua_getstring(o); |
279 | } | 279 | } |
280 | next = lua_varnext(varname); | 280 | next = lua_varnext(varname); |
281 | if (next == NULL) | 281 | if (next == NULL) |
@@ -288,7 +288,7 @@ void lua_nextvar (void) | |||
288 | Object name; | 288 | Object name; |
289 | tag(&name) = LUA_T_STRING; | 289 | tag(&name) = LUA_T_STRING; |
290 | svalue(&name) = next; | 290 | svalue(&name) = next; |
291 | if (lua_pushobject (&name)) return; | 291 | luaI_pushobject(&name); |
292 | if (lua_pushobject (&s_object(indexstring(next)))) return; | 292 | luaI_pushobject(&s_object(indexstring(next))); |
293 | } | 293 | } |
294 | } | 294 | } |