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 | |
parent | f8a571ee356f386ed7b5af898c2d297fd6d295fd (diff) | |
download | lua-efaaf99c425db615e63b6c5ee56c2878a592e2fa.tar.gz lua-efaaf99c425db615e63b6c5ee56c2878a592e2fa.tar.bz2 lua-efaaf99c425db615e63b6c5ee56c2878a592e2fa.zip |
first version of "setglobal" and "getglobal" internal methods.
-rw-r--r-- | fallback.c | 81 | ||||
-rw-r--r-- | fallback.h | 22 | ||||
-rw-r--r-- | inout.c | 30 | ||||
-rw-r--r-- | iolib.c | 2 | ||||
-rw-r--r-- | lua.h | 4 | ||||
-rw-r--r-- | opcode.c | 58 |
6 files changed, 115 insertions, 82 deletions
@@ -3,7 +3,7 @@ | |||
3 | ** TecCGraf - PUC-Rio | 3 | ** TecCGraf - PUC-Rio |
4 | */ | 4 | */ |
5 | 5 | ||
6 | char *rcs_fallback="$Id: fallback.c,v 1.34 1997/03/31 14:02:58 roberto Exp roberto $"; | 6 | char *rcs_fallback="$Id: fallback.c,v 1.35 1997/03/31 14:17:09 roberto Exp roberto $"; |
7 | 7 | ||
8 | #include <stdio.h> | 8 | #include <stdio.h> |
9 | #include <string.h> | 9 | #include <string.h> |
@@ -109,16 +109,13 @@ void luaI_invalidaterefs (void) | |||
109 | */ | 109 | */ |
110 | 110 | ||
111 | char *luaI_eventname[] = { /* ORDER IM */ | 111 | char *luaI_eventname[] = { /* ORDER IM */ |
112 | "gettable", "settable", "index", "add", "sub", "mul", "div", | 112 | "gettable", "settable", "index", "getglobal", "setglobal", "add", |
113 | "pow", "unm", "lt", "le", "gt", "ge", "concat", "gc", "function", | 113 | "sub", "mul", "div", "pow", "unm", "lt", "le", "gt", "ge", |
114 | "concat", "gc", "function", | ||
114 | NULL | 115 | NULL |
115 | }; | 116 | }; |
116 | 117 | ||
117 | 118 | ||
118 | static char *geventname[] = { /* ORDER GIM */ | ||
119 | "error", "getglobal", "setglobal", | ||
120 | NULL | ||
121 | }; | ||
122 | 119 | ||
123 | static int findstring (char *name, char *list[]) | 120 | static int findstring (char *name, char *list[]) |
124 | { | 121 | { |
@@ -147,16 +144,16 @@ static int IMtable_size = 0; | |||
147 | static int last_tag = LUA_T_NIL; /* ORDER LUA_T */ | 144 | static int last_tag = LUA_T_NIL; /* ORDER LUA_T */ |
148 | 145 | ||
149 | static char validevents[NUM_TYPES][IM_N] = { /* ORDER LUA_T, ORDER IM */ | 146 | static char validevents[NUM_TYPES][IM_N] = { /* ORDER LUA_T, ORDER IM */ |
150 | {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, /* LUA_T_USERDATA */ | 147 | {1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, /* LUA_T_USERDATA */ |
151 | {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, /* LUA_T_LINE */ | 148 | {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, /* LUA_T_LINE */ |
152 | {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, /* LUA_T_CMARK */ | 149 | {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, /* LUA_T_CMARK */ |
153 | {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, /* LUA_T_MARK */ | 150 | {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, /* LUA_T_MARK */ |
154 | {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0}, /* LUA_T_CFUNCTION */ | 151 | {1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0}, /* LUA_T_CFUNCTION */ |
155 | {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0}, /* LUA_T_FUNCTION */ | 152 | {1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0}, /* LUA_T_FUNCTION */ |
156 | {0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, /* LUA_T_ARRAY */ | 153 | {0, 0, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, /* LUA_T_ARRAY */ |
157 | {1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, /* LUA_T_STRING */ | 154 | {1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, /* LUA_T_STRING */ |
158 | {1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1}, /* LUA_T_NUMBER */ | 155 | {1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1}, /* LUA_T_NUMBER */ |
159 | {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0} /* LUA_T_NIL */ | 156 | {0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0} /* LUA_T_NIL */ |
160 | }; | 157 | }; |
161 | 158 | ||
162 | static int validevent (lua_Type t, int e) | 159 | static int validevent (lua_Type t, int e) |
@@ -263,32 +260,29 @@ void luaI_setintmethod (void) | |||
263 | luaI_IMtable[-t].int_method[e] = *luaI_Address(func); | 260 | luaI_IMtable[-t].int_method[e] = *luaI_Address(func); |
264 | } | 261 | } |
265 | 262 | ||
266 | static TObject gmethod[GIM_N] = { | ||
267 | {LUA_T_NIL, {NULL}}, {LUA_T_NIL, {NULL}}, {LUA_T_NIL, {NULL}} | ||
268 | }; | ||
269 | 263 | ||
270 | TObject *luaI_getgim (IMGS event) | 264 | static TObject errorim = {LUA_T_NIL, {NULL}}; |
265 | |||
266 | |||
267 | TObject *luaI_geterrorim (void) | ||
271 | { | 268 | { |
272 | return &gmethod[event]; | 269 | return &errorim; |
273 | } | 270 | } |
274 | 271 | ||
275 | void luaI_setglobalmethod (void) | 272 | void luaI_seterrormethod (void) |
276 | { | 273 | { |
277 | int e = luaI_checkevent(luaL_check_string(1, "setintmethod"), geventname); | 274 | lua_Object func = lua_getparam(1); |
278 | lua_Object func = lua_getparam(2); | 275 | luaL_arg_check(lua_isnil(func) || lua_isfunction(func), "seterrormethod", |
279 | luaL_arg_check(lua_isnil(func) || lua_isfunction(func), "setintmethod", | 276 | 1, "function expected"); |
280 | 2, "function expected"); | 277 | luaI_pushobject(&errorim); |
281 | luaI_pushobject(&gmethod[e]); | 278 | errorim = *luaI_Address(func); |
282 | gmethod[e] = *luaI_Address(func); | ||
283 | } | 279 | } |
284 | 280 | ||
285 | char *luaI_travfallbacks (int (*fn)(TObject *)) | 281 | char *luaI_travfallbacks (int (*fn)(TObject *)) |
286 | { | 282 | { |
287 | int e; | 283 | int e; |
288 | for (e=GIM_ERROR; e<=GIM_SETGLOBAL; e++) { /* ORDER GIM */ | 284 | if (fn(&errorim)) |
289 | if (fn(&gmethod[e])) | 285 | return "error"; |
290 | return geventname[e]; | ||
291 | } | ||
292 | for (e=IM_GETTABLE; e<=IM_FUNCTION; e++) { /* ORDER IM */ | 286 | for (e=IM_GETTABLE; e<=IM_FUNCTION; e++) { /* ORDER IM */ |
293 | int t; | 287 | int t; |
294 | for (t=0; t>=last_tag; t--) | 288 | for (t=0; t>=last_tag; t--) |
@@ -339,28 +333,33 @@ void luaI_setfallback (void) | |||
339 | lua_CFunction replace; | 333 | lua_CFunction replace; |
340 | char *name = luaL_check_string(1, "setfallback"); | 334 | char *name = luaL_check_string(1, "setfallback"); |
341 | lua_Object func = lua_getparam(2); | 335 | lua_Object func = lua_getparam(2); |
336 | luaI_initfallbacks(); | ||
342 | luaL_arg_check(lua_isfunction(func), "setfallback", 2, "function expected"); | 337 | luaL_arg_check(lua_isfunction(func), "setfallback", 2, "function expected"); |
343 | e = findstring(name, geventname); | 338 | if (strcmp(name, "error") == 0) { /* old error fallback */ |
344 | if (e >= 0) { /* global event */ | 339 | oldfunc = errorim; |
345 | oldfunc = gmethod[e]; | 340 | errorim = *luaI_Address(func); |
346 | gmethod[e] = *luaI_Address(func); | 341 | replace = errorFB; |
347 | replace = (e == GIM_ERROR) ? errorFB : nilFB; | 342 | } |
343 | else if (strcmp(name, "getglobal") == 0) { /* old getglobal fallback */ | ||
344 | oldfunc = luaI_IMtable[-LUA_T_NIL].int_method[IM_GETGLOBAL]; | ||
345 | luaI_IMtable[-LUA_T_NIL].int_method[IM_GETGLOBAL] = *luaI_Address(func); | ||
346 | replace = nilFB; | ||
348 | } | 347 | } |
349 | else if ((e = findstring(name, luaI_eventname)) >= 0) { | 348 | else if ((e = findstring(name, luaI_eventname)) >= 0) { |
350 | oldfunc = luaI_IMtable[LUA_T_USERDATA].int_method[e]; | 349 | oldfunc = luaI_IMtable[-LUA_T_USERDATA].int_method[e]; |
351 | fillvalids(e, luaI_Address(func)); | 350 | fillvalids(e, luaI_Address(func)); |
352 | replace = (e == IM_GC || e == IM_INDEX) ? nilFB : typeFB; | 351 | replace = (e == IM_GC || e == IM_INDEX) ? nilFB : typeFB; |
353 | } | 352 | } |
354 | else if (strcmp(name, "arith") == 0) { /* old arith fallback */ | 353 | else if (strcmp(name, "arith") == 0) { /* old arith fallback */ |
355 | int i; | 354 | int i; |
356 | oldfunc = luaI_IMtable[LUA_T_USERDATA].int_method[IM_POW]; | 355 | oldfunc = luaI_IMtable[-LUA_T_USERDATA].int_method[IM_POW]; |
357 | for (i=IM_ADD; i<=IM_UNM; i++) /* ORDER IM */ | 356 | for (i=IM_ADD; i<=IM_UNM; i++) /* ORDER IM */ |
358 | fillvalids(i, luaI_Address(func)); | 357 | fillvalids(i, luaI_Address(func)); |
359 | replace = typeFB; | 358 | replace = typeFB; |
360 | } | 359 | } |
361 | else if (strcmp(name, "order") == 0) { /* old order fallback */ | 360 | else if (strcmp(name, "order") == 0) { /* old order fallback */ |
362 | int i; | 361 | int i; |
363 | oldfunc = luaI_IMtable[LUA_T_USERDATA].int_method[IM_LT]; | 362 | oldfunc = luaI_IMtable[-LUA_T_USERDATA].int_method[IM_LT]; |
364 | for (i=IM_LT; i<=IM_GE; i++) /* ORDER IM */ | 363 | for (i=IM_LT; i<=IM_GE; i++) /* ORDER IM */ |
365 | fillvalids(i, luaI_Address(func)); | 364 | fillvalids(i, luaI_Address(func)); |
366 | replace = typeFB; | 365 | replace = typeFB; |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: fallback.h,v 1.17 1997/03/24 17:13:22 roberto Exp roberto $ | 2 | ** $Id: fallback.h,v 1.18 1997/03/31 14:02:58 roberto Exp roberto $ |
3 | */ | 3 | */ |
4 | 4 | ||
5 | #ifndef fallback_h | 5 | #ifndef fallback_h |
@@ -16,6 +16,8 @@ typedef enum { | |||
16 | IM_GETTABLE = 0, | 16 | IM_GETTABLE = 0, |
17 | IM_SETTABLE, | 17 | IM_SETTABLE, |
18 | IM_INDEX, | 18 | IM_INDEX, |
19 | IM_GETGLOBAL, | ||
20 | IM_SETGLOBAL, | ||
19 | IM_ADD, | 21 | IM_ADD, |
20 | IM_SUB, | 22 | IM_SUB, |
21 | IM_MUL, | 23 | IM_MUL, |
@@ -31,23 +33,11 @@ typedef enum { | |||
31 | IM_FUNCTION | 33 | IM_FUNCTION |
32 | } IMS; | 34 | } IMS; |
33 | 35 | ||
34 | #define IM_N 16 | 36 | #define IM_N 18 |
35 | 37 | ||
36 | extern char *luaI_eventname[]; | 38 | extern char *luaI_eventname[]; |
37 | 39 | ||
38 | 40 | ||
39 | /* | ||
40 | * WARNING: if you change the order of this enumeration, | ||
41 | * grep "ORDER GIM" | ||
42 | */ | ||
43 | typedef enum { | ||
44 | GIM_ERROR = 0, | ||
45 | GIM_GETGLOBAL, | ||
46 | GIM_SETGLOBAL | ||
47 | } IMGS; | ||
48 | |||
49 | #define GIM_N 3 | ||
50 | |||
51 | void luaI_setfallback (void); | 41 | void luaI_setfallback (void); |
52 | int luaI_ref (TObject *object, int lock); | 42 | int luaI_ref (TObject *object, int lock); |
53 | TObject *luaI_getref (int ref); | 43 | TObject *luaI_getref (int ref); |
@@ -60,10 +50,10 @@ void luaI_settag (int tag, TObject *o); | |||
60 | lua_Type luaI_typetag (int tag); | 50 | lua_Type luaI_typetag (int tag); |
61 | TObject *luaI_getim (int tag, IMS event); | 51 | TObject *luaI_getim (int tag, IMS event); |
62 | #define luaI_getimbyObj(o,e) (luaI_getim(luaI_tag(o),(e))) | 52 | #define luaI_getimbyObj(o,e) (luaI_getim(luaI_tag(o),(e))) |
63 | TObject *luaI_getgim (IMGS event); | 53 | TObject *luaI_geterrorim (void); |
64 | int luaI_tag (TObject *o); | 54 | int luaI_tag (TObject *o); |
65 | void luaI_setintmethod (void); | 55 | void luaI_setintmethod (void); |
66 | void luaI_setglobalmethod (void); | 56 | void luaI_seterrormethod (void); |
67 | void luaI_initfallbacks (void); | 57 | void luaI_initfallbacks (void); |
68 | 58 | ||
69 | #endif | 59 | #endif |
@@ -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.48 1997/03/20 19:20:23 roberto Exp roberto $"; | 8 | char *rcs_inout="$Id: inout.c,v 2.49 1997/03/31 14:17:09 roberto Exp roberto $"; |
9 | 9 | ||
10 | #include <stdio.h> | 10 | #include <stdio.h> |
11 | #include <string.h> | 11 | #include <string.h> |
@@ -194,11 +194,25 @@ static void luaI_setglobal (void) | |||
194 | lua_pushobject(value); /* return given value */ | 194 | lua_pushobject(value); /* return given value */ |
195 | } | 195 | } |
196 | 196 | ||
197 | static void luaI_basicsetglobal (void) | ||
198 | { | ||
199 | lua_Object value = lua_getparam(2); | ||
200 | luaL_arg_check(value != LUA_NOOBJECT, "basicsetglobal", 2, NULL); | ||
201 | lua_pushobject(value); | ||
202 | lua_basicstoreglobal(luaL_check_string(1, "basicsetglobal")); | ||
203 | lua_pushobject(value); /* return given value */ | ||
204 | } | ||
205 | |||
197 | static void luaI_getglobal (void) | 206 | static void luaI_getglobal (void) |
198 | { | 207 | { |
199 | lua_pushobject(lua_getglobal(luaL_check_string(1, "getglobal"))); | 208 | lua_pushobject(lua_getglobal(luaL_check_string(1, "getglobal"))); |
200 | } | 209 | } |
201 | 210 | ||
211 | static void luaI_basicgetglobal (void) | ||
212 | { | ||
213 | lua_pushobject(lua_basicgetglobal(luaL_check_string(1, "basicgetglobal"))); | ||
214 | } | ||
215 | |||
202 | #define MAXPARAMS 256 | 216 | #define MAXPARAMS 256 |
203 | static void luaI_call (void) | 217 | static void luaI_call (void) |
204 | { | 218 | { |
@@ -281,27 +295,29 @@ static struct { | |||
281 | lua_CFunction func; | 295 | lua_CFunction func; |
282 | } int_funcs[] = { | 296 | } int_funcs[] = { |
283 | {"assert", luaI_assert}, | 297 | {"assert", luaI_assert}, |
284 | {"call", luaI_call}, | 298 | {"basicgetglobal", luaI_basicgetglobal}, |
285 | {"basicindex", basicindex}, | 299 | {"basicindex", basicindex}, |
300 | {"basicsetglobal", luaI_basicsetglobal}, | ||
286 | {"basicstoreindex", basicstoreindex}, | 301 | {"basicstoreindex", basicstoreindex}, |
287 | {"settag", luaIl_settag}, | 302 | {"call", luaI_call}, |
288 | {"dofile", lua_internaldofile}, | 303 | {"dofile", lua_internaldofile}, |
289 | {"dostring", lua_internaldostring}, | 304 | {"dostring", lua_internaldostring}, |
290 | {"error", luaI_error}, | 305 | {"error", luaI_error}, |
291 | {"getglobal", luaI_getglobal}, | 306 | {"getglobal", luaI_getglobal}, |
307 | {"newtag", luaIl_newtag}, | ||
292 | {"next", lua_next}, | 308 | {"next", lua_next}, |
293 | {"nextvar", luaI_nextvar}, | 309 | {"nextvar", luaI_nextvar}, |
294 | {"newtag", luaIl_newtag}, | ||
295 | {"print", luaI_print}, | 310 | {"print", luaI_print}, |
311 | {"seterrormethod", luaI_seterrormethod}, | ||
296 | {"setfallback", luaI_setfallback}, | 312 | {"setfallback", luaI_setfallback}, |
297 | {"setintmethod", luaI_setintmethod}, | ||
298 | {"setglobalmethod", luaI_setglobalmethod}, | ||
299 | {"setglobal", luaI_setglobal}, | 313 | {"setglobal", luaI_setglobal}, |
314 | {"setintmethod", luaI_setintmethod}, | ||
315 | {"settag", luaIl_settag}, | ||
300 | {"tonumber", lua_obj2number}, | 316 | {"tonumber", lua_obj2number}, |
301 | {"tostring", luaI_tostring}, | 317 | {"tostring", luaI_tostring}, |
302 | {"type", luaI_type} | 318 | {"type", luaI_type} |
303 | }; | 319 | }; |
304 | 320 | ||
305 | #define INTFUNCSIZE (sizeof(int_funcs)/sizeof(int_funcs[0])) | 321 | #define INTFUNCSIZE (sizeof(int_funcs)/sizeof(int_funcs[0])) |
306 | 322 | ||
307 | 323 | ||
@@ -340,5 +340,5 @@ void iolib_open (void) | |||
340 | lua_tagio = lua_newtag("userdata"); | 340 | lua_tagio = lua_newtag("userdata"); |
341 | lua_infile=stdin; lua_outfile=stdout; | 341 | lua_infile=stdin; lua_outfile=stdout; |
342 | luaL_openlib(iolib, (sizeof(iolib)/sizeof(iolib[0]))); | 342 | luaL_openlib(iolib, (sizeof(iolib)/sizeof(iolib[0]))); |
343 | lua_setglobalmethod("error", errorfb); | 343 | lua_seterrormethod(errorfb); |
344 | } | 344 | } |
@@ -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.36 1997/03/17 17:01:10 roberto Exp roberto $ | 5 | ** $Id: lua.h,v 3.37 1997/03/19 19:41:10 roberto Exp roberto $ |
6 | */ | 6 | */ |
7 | 7 | ||
8 | 8 | ||
@@ -21,7 +21,7 @@ typedef unsigned int lua_Object; | |||
21 | 21 | ||
22 | lua_Object lua_setfallback (char *event, lua_CFunction fallback); | 22 | lua_Object lua_setfallback (char *event, lua_CFunction fallback); |
23 | void lua_setintmethod (int tag, char *event, lua_CFunction method); | 23 | void lua_setintmethod (int tag, char *event, lua_CFunction method); |
24 | void lua_setglobalmethod (char *event, lua_CFunction method); | 24 | void lua_seterrormethod (lua_CFunction method); |
25 | 25 | ||
26 | int lua_newtag (char *t); | 26 | int lua_newtag (char *t); |
27 | void lua_settag (int tag); /* In: object */ | 27 | void lua_settag (int tag); /* In: object */ |
@@ -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 | ||