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-github-609392ff2e02eb44fa48c8563faf5994fc55297c.tar.gz | |
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 @@ ** TecCGraf - PUC-Rio */ -char *rcs_fallback="$Id: fallback.c,v 1.7 1994/11/18 19:46:21 roberto Exp roberto $"; +char *rcs_fallback="$Id: fallback.c,v 1.8 1994/11/21 13:30:15 roberto Exp roberto $"; #include <stdio.h> @@ -21,6 +21,7 @@ static void arithFB (void); static void concatFB (void); static void orderFB (void); static void GDFB (void); +static void funcFB (void); /* @@ -34,7 +35,8 @@ struct FB luaI_fallBacks[] = { {"order", {LUA_T_CFUNCTION, orderFB}}, {"concat", {LUA_T_CFUNCTION, concatFB}}, {"settable", {LUA_T_CFUNCTION, gettableFB}}, -{"gc", {LUA_T_CFUNCTION, GDFB}} +{"gc", {LUA_T_CFUNCTION, GDFB}}, +{"function", {LUA_T_CFUNCTION, funcFB}} }; #define N_FB (sizeof(luaI_fallBacks)/sizeof(struct FB)) @@ -103,6 +105,11 @@ static void orderFB (void) static void GDFB (void) { } +static void funcFB (void) +{ + lua_reportbug("call expression not a function"); +} + /* ** Lock routines @@ -1,5 +1,5 @@ /* -** $Id: fallback.h,v 1.5 1994/11/18 19:46:21 roberto Exp roberto $ +** $Id: fallback.h,v 1.6 1994/11/21 13:30:15 roberto Exp roberto $ */ #ifndef fallback_h @@ -20,6 +20,7 @@ extern struct FB { #define FB_CONCAT 5 #define FB_SETTABLE 6 #define FB_GC 7 +#define FB_FUNCTION 8 void luaI_setfallback (void); int luaI_lock (Object *object); @@ -3,7 +3,7 @@ ** TecCGraf - PUC-Rio */ -char *rcs_opcode="$Id: opcode.c,v 3.18 1994/11/18 19:46:21 roberto Exp roberto $"; +char *rcs_opcode="$Id: opcode.c,v 3.19 1994/11/21 13:30:15 roberto Exp $"; #include <setjmp.h> #include <stdio.h> @@ -209,6 +209,20 @@ static int callC (lua_CFunction func, int base) return firstResult; } +/* +** Call the fallback for invalid functions (see do_call) +*/ +static void call_funcFB (Object *func, int base, int nResults, int whereRes) +{ + int i; + /* open space for first parameter (func) */ + for (i=top-stack; i>base; i--) + stack[i] = stack[i-1]; + top++; + stack[base] = *func; + do_call(&luaI_fallBacks[FB_FUNCTION].function, base, nResults, whereRes); +} + /* ** 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) else if (tag(func) == LUA_T_FUNCTION) firstResult = lua_execute(bvalue(func), base); else - { - lua_reportbug ("call expression not a function"); - return; /* to avoid warnings */ + { /* func is not a function */ + call_funcFB(func, base, nResults, whereRes); + return; } /* adjust the number of results */ if (nResults != MULT_RET && top - (stack+firstResult) != nResults) |
