diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1994-11-10 15:11:52 -0200 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1994-11-10 15:11:52 -0200 |
| commit | 9deac27704eee47f858f6b41a386c3198bc49587 (patch) | |
| tree | 27f28b2953f4cd9e2ee60a2ae7067fadb21b8a00 /fallback.c | |
| parent | d531ccd082a73aa2fda585dfe5edf2749c7e7d13 (diff) | |
| download | lua-9deac27704eee47f858f6b41a386c3198bc49587.tar.gz lua-9deac27704eee47f858f6b41a386c3198bc49587.tar.bz2 lua-9deac27704eee47f858f6b41a386c3198bc49587.zip | |
fallback list moved from opcode.c to fallback.c
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); |
