diff options
Diffstat (limited to 'fallback.c')
-rw-r--r-- | fallback.c | 42 |
1 files changed, 41 insertions, 1 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.2 1994/11/08 19:56:39 roberto Exp roberto $"; | 6 | char *rcs_fallback="$Id: fallback.c,v 1.3 1994/11/09 18:12:42 roberto Exp roberto $"; |
7 | 7 | ||
8 | #include <stdio.h> | 8 | #include <stdio.h> |
9 | #include <stdlib.h> | 9 | #include <stdlib.h> |
@@ -14,6 +14,46 @@ char *rcs_fallback="$Id: fallback.c,v 1.2 1994/11/08 19:56:39 roberto Exp robert | |||
14 | #include "lua.h" | 14 | #include "lua.h" |
15 | 15 | ||
16 | 16 | ||
17 | /* | ||
18 | ** Warning: This list must be in the same order as the #define's | ||
19 | */ | ||
20 | struct FB luaI_fallBacks[] = { | ||
21 | {"error", {LUA_T_CFUNCTION, luaI_errorFB}}, | ||
22 | {"index", {LUA_T_CFUNCTION, luaI_indexFB}}, | ||
23 | {"gettable", {LUA_T_CFUNCTION, luaI_gettableFB}}, | ||
24 | {"arith", {LUA_T_CFUNCTION, luaI_arithFB}}, | ||
25 | {"order", {LUA_T_CFUNCTION, luaI_orderFB}}, | ||
26 | {"concat", {LUA_T_CFUNCTION, luaI_concatFB}}, | ||
27 | {"unminus", {LUA_T_CFUNCTION, luaI_arithFB}}, | ||
28 | {"settable", {LUA_T_CFUNCTION, luaI_gettableFB}} | ||
29 | }; | ||
30 | |||
31 | #define N_FB (sizeof(luaI_fallBacks)/sizeof(struct FB)) | ||
32 | |||
33 | void luaI_setfallback (void) | ||
34 | { | ||
35 | int i; | ||
36 | char *name = lua_getstring(lua_getparam(1)); | ||
37 | lua_Object func = lua_getparam(2); | ||
38 | if (name == NULL || !(lua_isfunction(func) || lua_iscfunction(func))) | ||
39 | { | ||
40 | lua_pushnil(); | ||
41 | return; | ||
42 | } | ||
43 | for (i=0; i<N_FB; i++) | ||
44 | { | ||
45 | if (strcmp(luaI_fallBacks[i].kind, name) == 0) | ||
46 | { | ||
47 | luaI_pushobject(&luaI_fallBacks[i].function); | ||
48 | luaI_fallBacks[i].function = *luaI_Address(func); | ||
49 | return; | ||
50 | } | ||
51 | } | ||
52 | /* name not found */ | ||
53 | lua_pushnil(); | ||
54 | } | ||
55 | |||
56 | |||
17 | void luaI_errorFB (void) | 57 | void luaI_errorFB (void) |
18 | { | 58 | { |
19 | lua_Object o = lua_getparam(1); | 59 | lua_Object o = lua_getparam(1); |