diff options
author | Waldemar Celes <celes@tecgraf.puc-rio.br> | 1994-08-17 12:02:03 -0300 |
---|---|---|
committer | Waldemar Celes <celes@tecgraf.puc-rio.br> | 1994-08-17 12:02:03 -0300 |
commit | c4b8b1b9893f253d74db96e74f0e711e5c7350c0 (patch) | |
tree | 3a450d23811a72ab4b97811900a5cdf5c9b7e90e /opcode.c | |
parent | f490b1bff8628b4de0acdfbeb06b247f1ceb8345 (diff) | |
download | lua-c4b8b1b9893f253d74db96e74f0e711e5c7350c0.tar.gz lua-c4b8b1b9893f253d74db96e74f0e711e5c7350c0.tar.bz2 lua-c4b8b1b9893f253d74db96e74f0e711e5c7350c0.zip |
novas funcoes 'gettable' e 'pushtable', nova implementacao do hash e
heranca nas indexacoes.
Diffstat (limited to 'opcode.c')
-rw-r--r-- | opcode.c | 94 |
1 files changed, 71 insertions, 23 deletions
@@ -3,7 +3,7 @@ | |||
3 | ** TecCGraf - PUC-Rio | 3 | ** TecCGraf - PUC-Rio |
4 | */ | 4 | */ |
5 | 5 | ||
6 | char *rcs_opcode="$Id: opcode.c,v 2.3 1994/08/03 14:15:46 celes Exp celes $"; | 6 | char *rcs_opcode="$Id: opcode.c,v 2.4 1994/08/05 19:31:09 celes Exp celes $"; |
7 | 7 | ||
8 | #include <stdio.h> | 8 | #include <stdio.h> |
9 | #include <stdlib.h> | 9 | #include <stdlib.h> |
@@ -236,17 +236,10 @@ int lua_execute (Byte *pc) | |||
236 | break; | 236 | break; |
237 | 237 | ||
238 | case PUSHINDEXED: | 238 | case PUSHINDEXED: |
239 | --top; | 239 | { |
240 | if (tag(top-1) != T_ARRAY) | 240 | int s = lua_pushsubscript(); |
241 | { | 241 | if (s == 1) return 1; |
242 | lua_reportbug ("indexed expression not a table"); | 242 | } |
243 | return 1; | ||
244 | } | ||
245 | { | ||
246 | Object *h = lua_hashget (avalue(top-1), top); | ||
247 | if (h == NULL) return 1; | ||
248 | *(top-1) = *h; | ||
249 | } | ||
250 | break; | 243 | break; |
251 | 244 | ||
252 | case PUSHMARK: tag(top++) = T_MARK; break; | 245 | case PUSHMARK: tag(top++) = T_MARK; break; |
@@ -269,17 +262,10 @@ int lua_execute (Byte *pc) | |||
269 | break; | 262 | break; |
270 | 263 | ||
271 | case STOREINDEXED0: | 264 | case STOREINDEXED0: |
272 | if (tag(top-3) != T_ARRAY) | 265 | { |
273 | { | 266 | int s = lua_storesubscript(); |
274 | lua_reportbug ("indexed expression not a table"); | 267 | if (s == 1) return 1; |
275 | return 1; | 268 | } |
276 | } | ||
277 | { | ||
278 | Object *h = lua_hashdefine (avalue(top-3), top-2); | ||
279 | if (h == NULL) return 1; | ||
280 | *h = *(top-1); | ||
281 | } | ||
282 | top -= 3; | ||
283 | break; | 269 | break; |
284 | 270 | ||
285 | case STOREINDEXED: | 271 | case STOREINDEXED: |
@@ -641,6 +627,46 @@ int lua_execute (Byte *pc) | |||
641 | 627 | ||
642 | 628 | ||
643 | /* | 629 | /* |
630 | ** Function to indexed the values on the top | ||
631 | */ | ||
632 | int lua_pushsubscript (void) | ||
633 | { | ||
634 | --top; | ||
635 | if (tag(top-1) != T_ARRAY) | ||
636 | { | ||
637 | lua_reportbug ("indexed expression not a table"); | ||
638 | return 1; | ||
639 | } | ||
640 | { | ||
641 | Object *h = lua_hashget (avalue(top-1), top); | ||
642 | if (h == NULL) return 1; | ||
643 | *(top-1) = *h; | ||
644 | } | ||
645 | return 0; | ||
646 | } | ||
647 | |||
648 | |||
649 | /* | ||
650 | ** Function to store indexed based on values at the top | ||
651 | */ | ||
652 | int lua_storesubscript (void) | ||
653 | { | ||
654 | if (tag(top-3) != T_ARRAY) | ||
655 | { | ||
656 | lua_reportbug ("indexed expression not a table"); | ||
657 | return 1; | ||
658 | } | ||
659 | { | ||
660 | Object *h = lua_hashdefine (avalue(top-3), top-2); | ||
661 | if (h == NULL) return 1; | ||
662 | *h = *(top-1); | ||
663 | } | ||
664 | top -= 3; | ||
665 | return 0; | ||
666 | } | ||
667 | |||
668 | |||
669 | /* | ||
644 | ** Traverse all objects on stack | 670 | ** Traverse all objects on stack |
645 | */ | 671 | */ |
646 | void lua_travstack (void (*fn)(Object *)) | 672 | void lua_travstack (void (*fn)(Object *)) |
@@ -768,6 +794,16 @@ void *lua_getuserdata (Object *object) | |||
768 | } | 794 | } |
769 | 795 | ||
770 | /* | 796 | /* |
797 | ** Given an object handle, return its table. On error, return NULL. | ||
798 | */ | ||
799 | void *lua_gettable (Object *object) | ||
800 | { | ||
801 | if (object == NULL) return NULL; | ||
802 | if (tag(object) != T_ARRAY) return NULL; | ||
803 | else return (avalue(object)); | ||
804 | } | ||
805 | |||
806 | /* | ||
771 | ** Given an object handle and a field name, return its field object. | 807 | ** Given an object handle and a field name, return its field object. |
772 | ** On error, return NULL. | 808 | ** On error, return NULL. |
773 | */ | 809 | */ |
@@ -880,6 +916,17 @@ int lua_pushuserdata (void *u) | |||
880 | } | 916 | } |
881 | 917 | ||
882 | /* | 918 | /* |
919 | ** Push an object (tag=userdata) to stack. Return 0 on success or 1 on error. | ||
920 | */ | ||
921 | int lua_pushtable (void *t) | ||
922 | { | ||
923 | if (lua_checkstack(top-stack+1) == 1) | ||
924 | return 1; | ||
925 | tag(top) = T_ARRAY; avalue(top++) = t; | ||
926 | return 0; | ||
927 | } | ||
928 | |||
929 | /* | ||
883 | ** Push an object to stack. | 930 | ** Push an object to stack. |
884 | */ | 931 | */ |
885 | int lua_pushobject (Object *o) | 932 | int lua_pushobject (Object *o) |
@@ -903,6 +950,7 @@ int lua_storeglobal (char *name) | |||
903 | return 0; | 950 | return 0; |
904 | } | 951 | } |
905 | 952 | ||
953 | |||
906 | /* | 954 | /* |
907 | ** Store top of the stack at an array field. Return 1 on error, 0 on success. | 955 | ** Store top of the stack at an array field. Return 1 on error, 0 on success. |
908 | */ | 956 | */ |