fallback for "call expression not a function" errors

This commit is contained in:
Roberto Ierusalimschy 1994-11-21 16:22:58 -02:00
parent 96ea2e0fb4
commit 609392ff2e
3 changed files with 29 additions and 7 deletions

View File

@ -3,7 +3,7 @@
** TecCGraf - PUC-Rio ** 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> #include <stdio.h>
@ -21,6 +21,7 @@ static void arithFB (void);
static void concatFB (void); static void concatFB (void);
static void orderFB (void); static void orderFB (void);
static void GDFB (void); static void GDFB (void);
static void funcFB (void);
/* /*
@ -34,7 +35,8 @@ struct FB luaI_fallBacks[] = {
{"order", {LUA_T_CFUNCTION, orderFB}}, {"order", {LUA_T_CFUNCTION, orderFB}},
{"concat", {LUA_T_CFUNCTION, concatFB}}, {"concat", {LUA_T_CFUNCTION, concatFB}},
{"settable", {LUA_T_CFUNCTION, gettableFB}}, {"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)) #define N_FB (sizeof(luaI_fallBacks)/sizeof(struct FB))
@ -103,6 +105,11 @@ static void orderFB (void)
static void GDFB (void) { } static void GDFB (void) { }
static void funcFB (void)
{
lua_reportbug("call expression not a function");
}
/* /*
** Lock routines ** Lock routines

View File

@ -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 #ifndef fallback_h
@ -20,6 +20,7 @@ extern struct FB {
#define FB_CONCAT 5 #define FB_CONCAT 5
#define FB_SETTABLE 6 #define FB_SETTABLE 6
#define FB_GC 7 #define FB_GC 7
#define FB_FUNCTION 8
void luaI_setfallback (void); void luaI_setfallback (void);
int luaI_lock (Object *object); int luaI_lock (Object *object);

View File

@ -3,7 +3,7 @@
** TecCGraf - PUC-Rio ** 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 <setjmp.h>
#include <stdio.h> #include <stdio.h>
@ -209,6 +209,20 @@ static int callC (lua_CFunction func, int base)
return firstResult; 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, ** 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) else if (tag(func) == LUA_T_FUNCTION)
firstResult = lua_execute(bvalue(func), base); firstResult = lua_execute(bvalue(func), base);
else else
{ { /* func is not a function */
lua_reportbug ("call expression not a function"); call_funcFB(func, base, nResults, whereRes);
return; /* to avoid warnings */ return;
} }
/* adjust the number of results */ /* adjust the number of results */
if (nResults != MULT_RET && top - (stack+firstResult) != nResults) if (nResults != MULT_RET && top - (stack+firstResult) != nResults)