diff --git a/fallback.c b/fallback.c index a41712cc..0076da24 100644 --- a/fallback.c +++ b/fallback.c @@ -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 @@ -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 diff --git a/fallback.h b/fallback.h index 33c22b0d..8da9dd2e 100644 --- a/fallback.h +++ b/fallback.h @@ -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); diff --git a/opcode.c b/opcode.c index 55a41ee1..0e8a8598 100644 --- a/opcode.c +++ b/opcode.c @@ -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 #include @@ -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)