diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1997-03-31 17:59:09 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1997-03-31 17:59:09 -0300 |
commit | efaaf99c425db615e63b6c5ee56c2878a592e2fa (patch) | |
tree | d8d027e29e98d982b67f645e42fa38c0cc2bde32 /opcode.c | |
parent | f8a571ee356f386ed7b5af898c2d297fd6d295fd (diff) | |
download | lua-efaaf99c425db615e63b6c5ee56c2878a592e2fa.tar.gz lua-efaaf99c425db615e63b6c5ee56c2878a592e2fa.tar.bz2 lua-efaaf99c425db615e63b6c5ee56c2878a592e2fa.zip |
first version of "setglobal" and "getglobal" internal methods.
Diffstat (limited to 'opcode.c')
-rw-r--r-- | opcode.c | 58 |
1 files changed, 43 insertions, 15 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.87 1997/03/31 14:02:58 roberto Exp roberto $"; | 6 | char *rcs_opcode="$Id: opcode.c,v 3.88 1997/03/31 14:17:09 roberto Exp roberto $"; |
7 | 7 | ||
8 | #include <setjmp.h> | 8 | #include <setjmp.h> |
9 | #include <stdio.h> | 9 | #include <stdio.h> |
@@ -391,16 +391,20 @@ static void storesubscript (TObject *t, int mode) | |||
391 | 391 | ||
392 | static void getglobal (Word n) | 392 | static void getglobal (Word n) |
393 | { | 393 | { |
394 | *top = lua_table[n].object; | 394 | TObject *value = &lua_table[n].object; |
395 | incr_top; | 395 | TObject *im = luaI_getimbyObj(value, IM_GETGLOBAL); |
396 | if (ttype(top-1) == LUA_T_NIL) { /* check i.m. */ | 396 | if (ttype(im) == LUA_T_NIL) { /* default behavior */ |
397 | TObject *im = luaI_getgim(GIM_GETGLOBAL); | 397 | *top = *value; |
398 | if (ttype(im) != LUA_T_NIL) { | 398 | incr_top; |
399 | ttype(top-1) = LUA_T_STRING; | ||
400 | tsvalue(top-1) = lua_table[n].varname; | ||
401 | callIM(im, 1, 1); | ||
402 | } | ||
403 | } | 399 | } |
400 | else { | ||
401 | ttype(top) = LUA_T_STRING; | ||
402 | tsvalue(top) = lua_table[n].varname; | ||
403 | incr_top; | ||
404 | *top = *value; | ||
405 | incr_top; | ||
406 | callIM(im, 2, 1); | ||
407 | } | ||
404 | } | 408 | } |
405 | 409 | ||
406 | /* | 410 | /* |
@@ -420,7 +424,7 @@ void lua_travstack (int (*fn)(TObject *)) | |||
420 | 424 | ||
421 | static void lua_message (char *s) | 425 | static void lua_message (char *s) |
422 | { | 426 | { |
423 | TObject *im = luaI_getgim(GIM_ERROR); | 427 | TObject *im = luaI_geterrorim(); |
424 | if (ttype(im) == LUA_T_NIL) | 428 | if (ttype(im) == LUA_T_NIL) |
425 | fprintf(stderr, "lua: %s\n", s); | 429 | fprintf(stderr, "lua: %s\n", s); |
426 | else { | 430 | else { |
@@ -663,11 +667,10 @@ void lua_setintmethod (int tag, char *event, lua_CFunction method) | |||
663 | do_unprotectedrun(luaI_setintmethod, 3, 0); | 667 | do_unprotectedrun(luaI_setintmethod, 3, 0); |
664 | } | 668 | } |
665 | 669 | ||
666 | void lua_setglobalmethod (char *event, lua_CFunction method) | 670 | void lua_seterrormethod (lua_CFunction method) |
667 | { | 671 | { |
668 | lua_pushstring(event); | ||
669 | lua_pushcfunction (method); | 672 | lua_pushcfunction (method); |
670 | do_unprotectedrun(luaI_setglobalmethod, 3, 0); | 673 | do_unprotectedrun(luaI_seterrormethod, 1, 0); |
671 | } | 674 | } |
672 | 675 | ||
673 | 676 | ||
@@ -895,8 +898,33 @@ lua_Object lua_basicgetglobal (char *name) | |||
895 | /* | 898 | /* |
896 | ** Store top of the stack at a global variable array field. | 899 | ** Store top of the stack at a global variable array field. |
897 | */ | 900 | */ |
901 | static void storeglobal (Word n) | ||
902 | { | ||
903 | TObject *oldvalue = &lua_table[n].object; | ||
904 | TObject *im = luaI_getimbyObj(oldvalue, IM_SETGLOBAL); | ||
905 | if (ttype(im) == LUA_T_NIL) /* default behavior */ | ||
906 | s_object(n) = *(--top); | ||
907 | else { | ||
908 | TObject newvalue = *(top-1); | ||
909 | ttype(top-1) = LUA_T_STRING; | ||
910 | tsvalue(top-1) = lua_table[n].varname; | ||
911 | *top = *oldvalue; | ||
912 | incr_top; | ||
913 | *top = newvalue; | ||
914 | incr_top; | ||
915 | callIM(im, 3, 0); | ||
916 | } | ||
917 | } | ||
918 | |||
919 | |||
898 | void lua_storeglobal (char *name) | 920 | void lua_storeglobal (char *name) |
899 | { | 921 | { |
922 | adjustC(1); | ||
923 | storeglobal(luaI_findsymbolbyname(name)); | ||
924 | } | ||
925 | |||
926 | void lua_basicstoreglobal (char *name) | ||
927 | { | ||
900 | Word n = luaI_findsymbolbyname(name); | 928 | Word n = luaI_findsymbolbyname(name); |
901 | adjustC(1); | 929 | adjustC(1); |
902 | s_object(n) = *(--top); | 930 | s_object(n) = *(--top); |
@@ -1201,7 +1229,7 @@ static StkId lua_execute (Byte *pc, StkId base) | |||
1201 | { | 1229 | { |
1202 | Word w; | 1230 | Word w; |
1203 | get_word(w,pc); | 1231 | get_word(w,pc); |
1204 | s_object(w) = *(--top); | 1232 | storeglobal(w); |
1205 | } | 1233 | } |
1206 | break; | 1234 | break; |
1207 | 1235 | ||