diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1994-11-21 16:22:58 -0200 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1994-11-21 16:22:58 -0200 |
commit | 609392ff2e02eb44fa48c8563faf5994fc55297c (patch) | |
tree | ae4d3a4094a795a3c04583895007f0d6119da52a | |
parent | 96ea2e0fb462789015824823801ba34782364b68 (diff) | |
download | lua-609392ff2e02eb44fa48c8563faf5994fc55297c.tar.gz lua-609392ff2e02eb44fa48c8563faf5994fc55297c.tar.bz2 lua-609392ff2e02eb44fa48c8563faf5994fc55297c.zip |
fallback for "call expression not a function" errors
-rw-r--r-- | fallback.c | 11 | ||||
-rw-r--r-- | fallback.h | 3 | ||||
-rw-r--r-- | opcode.c | 22 |
3 files changed, 29 insertions, 7 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.7 1994/11/18 19:46:21 roberto Exp roberto $"; | 6 | char *rcs_fallback="$Id: fallback.c,v 1.8 1994/11/21 13:30:15 roberto Exp roberto $"; |
7 | 7 | ||
8 | #include <stdio.h> | 8 | #include <stdio.h> |
9 | 9 | ||
@@ -21,6 +21,7 @@ static void arithFB (void); | |||
21 | static void concatFB (void); | 21 | static void concatFB (void); |
22 | static void orderFB (void); | 22 | static void orderFB (void); |
23 | static void GDFB (void); | 23 | static void GDFB (void); |
24 | static void funcFB (void); | ||
24 | 25 | ||
25 | 26 | ||
26 | /* | 27 | /* |
@@ -34,7 +35,8 @@ struct FB luaI_fallBacks[] = { | |||
34 | {"order", {LUA_T_CFUNCTION, orderFB}}, | 35 | {"order", {LUA_T_CFUNCTION, orderFB}}, |
35 | {"concat", {LUA_T_CFUNCTION, concatFB}}, | 36 | {"concat", {LUA_T_CFUNCTION, concatFB}}, |
36 | {"settable", {LUA_T_CFUNCTION, gettableFB}}, | 37 | {"settable", {LUA_T_CFUNCTION, gettableFB}}, |
37 | {"gc", {LUA_T_CFUNCTION, GDFB}} | 38 | {"gc", {LUA_T_CFUNCTION, GDFB}}, |
39 | {"function", {LUA_T_CFUNCTION, funcFB}} | ||
38 | }; | 40 | }; |
39 | 41 | ||
40 | #define N_FB (sizeof(luaI_fallBacks)/sizeof(struct FB)) | 42 | #define N_FB (sizeof(luaI_fallBacks)/sizeof(struct FB)) |
@@ -103,6 +105,11 @@ static void orderFB (void) | |||
103 | 105 | ||
104 | static void GDFB (void) { } | 106 | static void GDFB (void) { } |
105 | 107 | ||
108 | static void funcFB (void) | ||
109 | { | ||
110 | lua_reportbug("call expression not a function"); | ||
111 | } | ||
112 | |||
106 | 113 | ||
107 | /* | 114 | /* |
108 | ** Lock routines | 115 | ** Lock routines |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: fallback.h,v 1.5 1994/11/18 19:46:21 roberto Exp roberto $ | 2 | ** $Id: fallback.h,v 1.6 1994/11/21 13:30:15 roberto Exp roberto $ |
3 | */ | 3 | */ |
4 | 4 | ||
5 | #ifndef fallback_h | 5 | #ifndef fallback_h |
@@ -20,6 +20,7 @@ extern struct FB { | |||
20 | #define FB_CONCAT 5 | 20 | #define FB_CONCAT 5 |
21 | #define FB_SETTABLE 6 | 21 | #define FB_SETTABLE 6 |
22 | #define FB_GC 7 | 22 | #define FB_GC 7 |
23 | #define FB_FUNCTION 8 | ||
23 | 24 | ||
24 | void luaI_setfallback (void); | 25 | void luaI_setfallback (void); |
25 | int luaI_lock (Object *object); | 26 | int luaI_lock (Object *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.18 1994/11/18 19:46:21 roberto Exp roberto $"; | 6 | char *rcs_opcode="$Id: opcode.c,v 3.19 1994/11/21 13:30:15 roberto Exp $"; |
7 | 7 | ||
8 | #include <setjmp.h> | 8 | #include <setjmp.h> |
9 | #include <stdio.h> | 9 | #include <stdio.h> |
@@ -209,6 +209,20 @@ static int callC (lua_CFunction func, int base) | |||
209 | return firstResult; | 209 | return firstResult; |
210 | } | 210 | } |
211 | 211 | ||
212 | /* | ||
213 | ** Call the fallback for invalid functions (see do_call) | ||
214 | */ | ||
215 | static void call_funcFB (Object *func, int base, int nResults, int whereRes) | ||
216 | { | ||
217 | int i; | ||
218 | /* open space for first parameter (func) */ | ||
219 | for (i=top-stack; i>base; i--) | ||
220 | stack[i] = stack[i-1]; | ||
221 | top++; | ||
222 | stack[base] = *func; | ||
223 | do_call(&luaI_fallBacks[FB_FUNCTION].function, base, nResults, whereRes); | ||
224 | } | ||
225 | |||
212 | 226 | ||
213 | /* | 227 | /* |
214 | ** Call a function (C or Lua). The parameters must be on the stack, | 228 | ** Call a function (C or Lua). The parameters must be on the stack, |
@@ -224,9 +238,9 @@ static void do_call (Object *func, int base, int nResults, int whereRes) | |||
224 | else if (tag(func) == LUA_T_FUNCTION) | 238 | else if (tag(func) == LUA_T_FUNCTION) |
225 | firstResult = lua_execute(bvalue(func), base); | 239 | firstResult = lua_execute(bvalue(func), base); |
226 | else | 240 | else |
227 | { | 241 | { /* func is not a function */ |
228 | lua_reportbug ("call expression not a function"); | 242 | call_funcFB(func, base, nResults, whereRes); |
229 | return; /* to avoid warnings */ | 243 | return; |
230 | } | 244 | } |
231 | /* adjust the number of results */ | 245 | /* adjust the number of results */ |
232 | if (nResults != MULT_RET && top - (stack+firstResult) != nResults) | 246 | if (nResults != MULT_RET && top - (stack+firstResult) != nResults) |