diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1994-12-16 13:56:45 -0200 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1994-12-16 13:56:45 -0200 |
commit | 068d1cd1eea8a90bca09352085c8ac14b0773490 (patch) | |
tree | 3258f5fd3108ccb3028e5f770b84436f71779278 | |
parent | 3365a352431a0def0acccec0807751962726c4be (diff) | |
download | lua-068d1cd1eea8a90bca09352085c8ac14b0773490.tar.gz lua-068d1cd1eea8a90bca09352085c8ac14b0773490.tar.bz2 lua-068d1cd1eea8a90bca09352085c8ac14b0773490.zip |
new constant LUA_NOOBJECT.
'lua_createtable' does not have parameters.
'lua_copystring' now is a macro
-rw-r--r-- | lua.h | 9 | ||||
-rw-r--r-- | opcode.c | 34 |
2 files changed, 18 insertions, 25 deletions
@@ -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.11 1994/11/18 19:46:21 roberto Stab roberto $ | 5 | ** $Id: lua.h,v 3.12 1994/12/13 15:54:21 roberto Exp roberto $ |
6 | */ | 6 | */ |
7 | 7 | ||
8 | 8 | ||
@@ -25,6 +25,8 @@ typedef enum | |||
25 | 25 | ||
26 | /* Public Part */ | 26 | /* Public Part */ |
27 | 27 | ||
28 | #define LUA_NOOBJECT 0 | ||
29 | |||
28 | typedef void (*lua_CFunction) (void); | 30 | typedef void (*lua_CFunction) (void); |
29 | typedef unsigned int lua_Object; | 31 | typedef unsigned int lua_Object; |
30 | 32 | ||
@@ -44,7 +46,6 @@ lua_Object lua_getparam (int number); | |||
44 | 46 | ||
45 | float lua_getnumber (lua_Object object); | 47 | float lua_getnumber (lua_Object object); |
46 | char *lua_getstring (lua_Object object); | 48 | char *lua_getstring (lua_Object object); |
47 | char *lua_copystring (lua_Object object); | ||
48 | lua_CFunction lua_getcfunction (lua_Object object); | 49 | lua_CFunction lua_getcfunction (lua_Object object); |
49 | void *lua_getuserdata (lua_Object object); | 50 | void *lua_getuserdata (lua_Object object); |
50 | 51 | ||
@@ -68,7 +69,7 @@ int lua_lock (void); | |||
68 | lua_Object lua_getlocked (int ref); | 69 | lua_Object lua_getlocked (int ref); |
69 | void lua_unlock (int ref); | 70 | void lua_unlock (int ref); |
70 | 71 | ||
71 | lua_Object lua_createtable (int initSize); | 72 | lua_Object lua_createtable (void); |
72 | 73 | ||
73 | 74 | ||
74 | /* some useful macros */ | 75 | /* some useful macros */ |
@@ -93,4 +94,6 @@ lua_Object lua_createtable (int initSize); | |||
93 | #define lua_getindexed(o,n) (lua_pushobject(o), lua_pushnumber(n), lua_getsubscript()) | 94 | #define lua_getindexed(o,n) (lua_pushobject(o), lua_pushnumber(n), lua_getsubscript()) |
94 | #define lua_getfield(o,f) (lua_pushobject(o), lua_pushstring(f), lua_getsubscript()) | 95 | #define lua_getfield(o,f) (lua_pushobject(o), lua_pushstring(f), lua_getsubscript()) |
95 | 96 | ||
97 | #define lua_copystring(o) (strdup(lua_getstring(o))) | ||
98 | |||
96 | #endif | 99 | #endif |
@@ -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.24 1994/12/06 14:27:18 roberto Exp roberto $"; | 6 | char *rcs_opcode="$Id: opcode.c,v 3.25 1994/12/13 15:54:21 roberto Exp roberto $"; |
7 | 7 | ||
8 | #include <setjmp.h> | 8 | #include <setjmp.h> |
9 | #include <stdio.h> | 9 | #include <stdio.h> |
@@ -448,7 +448,7 @@ lua_Object lua_getsubscript (void) | |||
448 | if (status == 0) | 448 | if (status == 0) |
449 | return (Ref(top-1)); | 449 | return (Ref(top-1)); |
450 | else | 450 | else |
451 | return 0; | 451 | return LUA_NOOBJECT; |
452 | } | 452 | } |
453 | 453 | ||
454 | 454 | ||
@@ -495,10 +495,10 @@ int lua_storesubscript (void) | |||
495 | /* | 495 | /* |
496 | ** API: creates a new table | 496 | ** API: creates a new table |
497 | */ | 497 | */ |
498 | lua_Object lua_createtable (int initSize) | 498 | lua_Object lua_createtable (void) |
499 | { | 499 | { |
500 | adjustC(0); | 500 | adjustC(0); |
501 | avalue(top) = lua_createarray(initSize); | 501 | avalue(top) = lua_createarray(0); |
502 | tag(top) = LUA_T_ARRAY; | 502 | tag(top) = LUA_T_ARRAY; |
503 | top++; | 503 | top++; |
504 | CBase++; /* incorporate object in the stack */ | 504 | CBase++; /* incorporate object in the stack */ |
@@ -506,12 +506,12 @@ lua_Object lua_createtable (int initSize) | |||
506 | } | 506 | } |
507 | 507 | ||
508 | /* | 508 | /* |
509 | ** Get a parameter, returning the object handle or 0 on error. | 509 | ** Get a parameter, returning the object handle or LUA_NOOBJECT on error. |
510 | ** 'number' must be 1 to get the first parameter. | 510 | ** 'number' must be 1 to get the first parameter. |
511 | */ | 511 | */ |
512 | lua_Object lua_getparam (int number) | 512 | lua_Object lua_getparam (int number) |
513 | { | 513 | { |
514 | if (number <= 0 || number > CnResults) return 0; | 514 | if (number <= 0 || number > CnResults) return LUA_NOOBJECT; |
515 | /* Ref(stack+(CBase-CnResults+number-1)) == | 515 | /* Ref(stack+(CBase-CnResults+number-1)) == |
516 | stack+(CBase-CnResults+number-1)-stack+1 == */ | 516 | stack+(CBase-CnResults+number-1)-stack+1 == */ |
517 | return CBase-CnResults+number; | 517 | return CBase-CnResults+number; |
@@ -522,7 +522,7 @@ lua_Object lua_getparam (int number) | |||
522 | */ | 522 | */ |
523 | real lua_getnumber (lua_Object object) | 523 | real lua_getnumber (lua_Object object) |
524 | { | 524 | { |
525 | if (object == 0 || tag(Address(object)) == LUA_T_NIL) return 0.0; | 525 | if (object == LUA_NOOBJECT || tag(Address(object)) == LUA_T_NIL) return 0.0; |
526 | if (tonumber (Address(object))) return 0.0; | 526 | if (tonumber (Address(object))) return 0.0; |
527 | else return (nvalue(Address(object))); | 527 | else return (nvalue(Address(object))); |
528 | } | 528 | } |
@@ -532,28 +532,18 @@ real lua_getnumber (lua_Object object) | |||
532 | */ | 532 | */ |
533 | char *lua_getstring (lua_Object object) | 533 | char *lua_getstring (lua_Object object) |
534 | { | 534 | { |
535 | if (object == 0 || tag(Address(object)) == LUA_T_NIL) return NULL; | 535 | if (object == LUA_NOOBJECT || tag(Address(object)) == LUA_T_NIL) return NULL; |
536 | if (tostring (Address(object))) return NULL; | 536 | if (tostring (Address(object))) return NULL; |
537 | else return (svalue(Address(object))); | 537 | else return (svalue(Address(object))); |
538 | } | 538 | } |
539 | 539 | ||
540 | /* | 540 | /* |
541 | ** Given an object handle, return a copy of its string. On error, return NULL. | ||
542 | */ | ||
543 | char *lua_copystring (lua_Object object) | ||
544 | { | ||
545 | if (object == 0 || tag(Address(object)) == LUA_T_NIL) return NULL; | ||
546 | if (tostring (Address(object))) return NULL; | ||
547 | else return (strdup(svalue(Address(object)))); | ||
548 | } | ||
549 | |||
550 | /* | ||
551 | ** Given an object handle, return its cfuntion pointer. On error, return NULL. | 541 | ** Given an object handle, return its cfuntion pointer. On error, return NULL. |
552 | */ | 542 | */ |
553 | lua_CFunction lua_getcfunction (lua_Object object) | 543 | lua_CFunction lua_getcfunction (lua_Object object) |
554 | { | 544 | { |
555 | if (object == 0) return NULL; | 545 | if (object == LUA_NOOBJECT || tag(Address(object)) != LUA_T_CFUNCTION) |
556 | if (tag(Address(object)) != LUA_T_CFUNCTION) return NULL; | 546 | return NULL; |
557 | else return (fvalue(Address(object))); | 547 | else return (fvalue(Address(object))); |
558 | } | 548 | } |
559 | 549 | ||
@@ -562,8 +552,8 @@ lua_CFunction lua_getcfunction (lua_Object object) | |||
562 | */ | 552 | */ |
563 | void *lua_getuserdata (lua_Object object) | 553 | void *lua_getuserdata (lua_Object object) |
564 | { | 554 | { |
565 | if (object == 0) return NULL; | 555 | if (object == LUA_NOOBJECT || tag(Address(object)) < LUA_T_USERDATA) |
566 | if (tag(Address(object)) < LUA_T_USERDATA) return NULL; | 556 | return NULL; |
567 | else return (uvalue(Address(object))); | 557 | else return (uvalue(Address(object))); |
568 | } | 558 | } |
569 | 559 | ||