diff options
Diffstat (limited to 'opcode.c')
-rw-r--r-- | opcode.c | 41 |
1 files changed, 21 insertions, 20 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 3.93 1997/04/02 23:04:12 roberto Exp roberto $"; | 6 | char *rcs_opcode="$Id: opcode.c,v 4.1 1997/04/03 18:27:06 roberto Exp roberto $"; |
7 | 7 | ||
8 | #include <setjmp.h> | 8 | #include <setjmp.h> |
9 | #include <stdio.h> | 9 | #include <stdio.h> |
@@ -19,6 +19,7 @@ char *rcs_opcode="$Id: opcode.c,v 3.93 1997/04/02 23:04:12 roberto Exp roberto $ | |||
19 | #include "lua.h" | 19 | #include "lua.h" |
20 | #include "fallback.h" | 20 | #include "fallback.h" |
21 | #include "undump.h" | 21 | #include "undump.h" |
22 | #include "auxlib.h" | ||
22 | 23 | ||
23 | #define tonumber(o) ((ttype(o) != LUA_T_NUMBER) && (lua_tonumber(o) != 0)) | 24 | #define tonumber(o) ((ttype(o) != LUA_T_NUMBER) && (lua_tonumber(o) != 0)) |
24 | #define tostring(o) ((ttype(o) != LUA_T_STRING) && (lua_tostring(o) != 0)) | 25 | #define tostring(o) ((ttype(o) != LUA_T_STRING) && (lua_tostring(o) != 0)) |
@@ -340,11 +341,11 @@ static void pushsubscript (void) | |||
340 | } | 341 | } |
341 | 342 | ||
342 | 343 | ||
343 | lua_Object lua_basicindex (void) | 344 | lua_Object lua_rawgettable (void) |
344 | { | 345 | { |
345 | adjustC(2); | 346 | adjustC(2); |
346 | if (ttype(top-2) != LUA_T_ARRAY) | 347 | if (ttype(top-2) != LUA_T_ARRAY) |
347 | lua_error("indexed expression not a table in basic indexing"); | 348 | lua_error("indexed expression not a table in raw gettable"); |
348 | else { | 349 | else { |
349 | TObject *h = lua_hashget(avalue(top-2), top-1); | 350 | TObject *h = lua_hashget(avalue(top-2), top-1); |
350 | --top; | 351 | --top; |
@@ -360,7 +361,7 @@ lua_Object lua_basicindex (void) | |||
360 | 361 | ||
361 | /* | 362 | /* |
362 | ** Function to store indexed based on values at the top | 363 | ** Function to store indexed based on values at the top |
363 | ** mode = 0: basic store (without internal methods) | 364 | ** mode = 0: raw store (without internal methods) |
364 | ** mode = 1: normal store (with internal methods) | 365 | ** mode = 1: normal store (with internal methods) |
365 | ** mode = 2: "deep stack" store (with internal methods) | 366 | ** mode = 2: "deep stack" store (with internal methods) |
366 | */ | 367 | */ |
@@ -656,14 +657,14 @@ lua_Object lua_setfallback (char *name, lua_CFunction fallback) | |||
656 | return (Ref(top-1)); | 657 | return (Ref(top-1)); |
657 | } | 658 | } |
658 | 659 | ||
659 | void lua_getintmethod (int tag, char *event) | 660 | void lua_gettagmethod (int tag, char *event) |
660 | { | 661 | { |
661 | lua_pushnumber(tag); | 662 | lua_pushnumber(tag); |
662 | lua_pushstring(event); | 663 | lua_pushstring(event); |
663 | do_unprotectedrun(luaI_getintmethod, 2, 1); | 664 | do_unprotectedrun(luaI_gettagmethod, 2, 1); |
664 | } | 665 | } |
665 | 666 | ||
666 | void lua_setintmethod (int tag, char *event, lua_CFunction method) | 667 | void lua_settagmethod (int tag, char *event, lua_CFunction method) |
667 | { | 668 | { |
668 | lua_pushnumber(tag); | 669 | lua_pushnumber(tag); |
669 | lua_pushstring(event); | 670 | lua_pushstring(event); |
@@ -671,7 +672,7 @@ void lua_setintmethod (int tag, char *event, lua_CFunction method) | |||
671 | lua_pushcfunction (method); | 672 | lua_pushcfunction (method); |
672 | else | 673 | else |
673 | lua_pushnil(); | 674 | lua_pushnil(); |
674 | do_unprotectedrun(luaI_setintmethod, 3, 1); | 675 | do_unprotectedrun(luaI_settagmethod, 3, 1); |
675 | } | 676 | } |
676 | 677 | ||
677 | void lua_seterrormethod (lua_CFunction method) | 678 | void lua_seterrormethod (lua_CFunction method) |
@@ -685,7 +686,7 @@ void lua_seterrormethod (lua_CFunction method) | |||
685 | ** API: receives on the stack the table and the index. | 686 | ** API: receives on the stack the table and the index. |
686 | ** returns the value. | 687 | ** returns the value. |
687 | */ | 688 | */ |
688 | lua_Object lua_getsubscript (void) | 689 | lua_Object lua_gettable (void) |
689 | { | 690 | { |
690 | adjustC(2); | 691 | adjustC(2); |
691 | pushsubscript(); | 692 | pushsubscript(); |
@@ -729,13 +730,13 @@ void lua_settag (int tag) | |||
729 | /* | 730 | /* |
730 | ** API: receives on the stack the table, the index, and the new value. | 731 | ** API: receives on the stack the table, the index, and the new value. |
731 | */ | 732 | */ |
732 | void lua_storesubscript (void) | 733 | void lua_settable (void) |
733 | { | 734 | { |
734 | adjustC(3); | 735 | adjustC(3); |
735 | storesubscript(top-3, 1); | 736 | storesubscript(top-3, 1); |
736 | } | 737 | } |
737 | 738 | ||
738 | void lua_basicstoreindex (void) | 739 | void lua_rawsettable (void) |
739 | { | 740 | { |
740 | adjustC(3); | 741 | adjustC(3); |
741 | storesubscript(top-3, 0); | 742 | storesubscript(top-3, 0); |
@@ -825,7 +826,7 @@ char *lua_getstring (lua_Object object) | |||
825 | else return (svalue(Address(object))); | 826 | else return (svalue(Address(object))); |
826 | } | 827 | } |
827 | 828 | ||
828 | void *lua_getbinarydata (lua_Object object) | 829 | void *lua_getbindata (lua_Object object) |
829 | { | 830 | { |
830 | if (object == LUA_NOOBJECT || ttype(Address(object)) != LUA_T_USERDATA) | 831 | if (object == LUA_NOOBJECT || ttype(Address(object)) != LUA_T_USERDATA) |
831 | return NULL; | 832 | return NULL; |
@@ -834,7 +835,7 @@ void *lua_getbinarydata (lua_Object object) | |||
834 | 835 | ||
835 | void *lua_getuserdata (lua_Object object) | 836 | void *lua_getuserdata (lua_Object object) |
836 | { | 837 | { |
837 | void *add = lua_getbinarydata(object); | 838 | void *add = lua_getbindata(object); |
838 | if (add == NULL) return NULL; | 839 | if (add == NULL) return NULL; |
839 | else return *(void **)add; | 840 | else return *(void **)add; |
840 | } | 841 | } |
@@ -875,7 +876,7 @@ void lua_pushref (int ref) | |||
875 | { | 876 | { |
876 | TObject *o = luaI_getref(ref); | 877 | TObject *o = luaI_getref(ref); |
877 | if (o == NULL) | 878 | if (o == NULL) |
878 | lua_error("access to invalid (possibly garbage collected) reference"); | 879 | lua_error("access to invalid reference (possibly garbage collected)"); |
879 | luaI_pushobject(o); | 880 | luaI_pushobject(o); |
880 | } | 881 | } |
881 | 882 | ||
@@ -900,7 +901,7 @@ lua_Object lua_getglobal (char *name) | |||
900 | } | 901 | } |
901 | 902 | ||
902 | 903 | ||
903 | lua_Object lua_basicgetglobal (char *name) | 904 | lua_Object lua_rawgetglobal (char *name) |
904 | { | 905 | { |
905 | adjustC(0); | 906 | adjustC(0); |
906 | *top = lua_table[luaI_findsymbolbyname(name)].object; | 907 | *top = lua_table[luaI_findsymbolbyname(name)].object; |
@@ -938,7 +939,7 @@ void lua_setglobal (char *name) | |||
938 | setglobal(luaI_findsymbolbyname(name)); | 939 | setglobal(luaI_findsymbolbyname(name)); |
939 | } | 940 | } |
940 | 941 | ||
941 | void lua_basicsetglobal (char *name) | 942 | void lua_rawsetglobal (char *name) |
942 | { | 943 | { |
943 | Word n = luaI_findsymbolbyname(name); | 944 | Word n = luaI_findsymbolbyname(name); |
944 | adjustC(1); | 945 | adjustC(1); |
@@ -989,13 +990,13 @@ void lua_pushcfunction (lua_CFunction fn) | |||
989 | incr_top; | 990 | incr_top; |
990 | } | 991 | } |
991 | 992 | ||
992 | void lua_pushbinarydata (void *buff, int size, int tag) | 993 | void lua_pushbindata (void *buff, int size, int tag) |
993 | { | 994 | { |
994 | if (buff == NULL) | 995 | if (buff == NULL) |
995 | ttype(top) = LUA_T_NIL; | 996 | ttype(top) = LUA_T_NIL; |
996 | else { | 997 | else { |
997 | if (!luaI_userdatatag(tag)) | 998 | if (tag < 0) |
998 | lua_error("invalid tag for userdata"); | 999 | luaI_realtag(tag); |
999 | tsvalue(top) = luaI_createuserdata(buff, size, tag); | 1000 | tsvalue(top) = luaI_createuserdata(buff, size, tag); |
1000 | ttype(top) = LUA_T_USERDATA; | 1001 | ttype(top) = LUA_T_USERDATA; |
1001 | } | 1002 | } |
@@ -1007,7 +1008,7 @@ void lua_pushbinarydata (void *buff, int size, int tag) | |||
1007 | */ | 1008 | */ |
1008 | void lua_pushusertag (void *u, int tag) | 1009 | void lua_pushusertag (void *u, int tag) |
1009 | { | 1010 | { |
1010 | lua_pushbinarydata(&u, sizeof(void *), tag); | 1011 | lua_pushbindata(&u, sizeof(void *), tag); |
1011 | } | 1012 | } |
1012 | 1013 | ||
1013 | /* | 1014 | /* |