diff options
Diffstat (limited to 'lapi.c')
| -rw-r--r-- | lapi.c | 46 |
1 files changed, 45 insertions, 1 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lapi.c,v 2.93 2009/10/05 16:44:33 roberto Exp roberto $ | 2 | ** $Id: lapi.c,v 2.94 2009/10/23 19:12:19 roberto Exp roberto $ |
| 3 | ** Lua API | 3 | ** Lua API |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -1088,6 +1088,50 @@ LUA_API const char *lua_setupvalue (lua_State *L, int funcindex, int n) { | |||
| 1088 | } | 1088 | } |
| 1089 | 1089 | ||
| 1090 | 1090 | ||
| 1091 | static UpVal **getupvalref (lua_State *L, int fidx, int n, Closure **pf) { | ||
| 1092 | Closure *f; | ||
| 1093 | Proto *p; | ||
| 1094 | StkId fi = index2addr(L, fidx); | ||
| 1095 | if (!ttisfunction(fi)) return NULL; /* not a function? */ | ||
| 1096 | f = clvalue(fi); | ||
| 1097 | if (f->c.isC) return NULL; /* not a Lua function? */ | ||
| 1098 | p = f->l.p; | ||
| 1099 | if (!(1 <= n && n <= p->sizeupvalues)) return NULL; | ||
| 1100 | else { | ||
| 1101 | if (pf) *pf = f; | ||
| 1102 | return &f->l.upvals[n - 1]; /* get its upvalue pointer */ | ||
| 1103 | } | ||
| 1104 | } | ||
| 1105 | |||
| 1106 | |||
| 1107 | LUA_API void *(lua_upvaladdr) (lua_State *L, int fidx, int n) { | ||
| 1108 | Closure *f; | ||
| 1109 | StkId fi = index2addr(L, fidx); | ||
| 1110 | if (!ttisfunction(fi)) return NULL; | ||
| 1111 | f = clvalue(fi); | ||
| 1112 | if (f->c.isC) { | ||
| 1113 | if (!(1 <= n && n <= f->c.nupvalues)) return NULL; | ||
| 1114 | else return &f->c.upvalue[n - 1]; | ||
| 1115 | } | ||
| 1116 | else { | ||
| 1117 | UpVal **uv = getupvalref(L, fidx, n, NULL); | ||
| 1118 | return (uv == NULL) ? NULL : *uv; | ||
| 1119 | } | ||
| 1120 | } | ||
| 1121 | |||
| 1122 | |||
| 1123 | LUA_API int (lua_upvaljoin) (lua_State *L, int fidx1, int n1, | ||
| 1124 | int fidx2, int n2) { | ||
| 1125 | Closure *f1; | ||
| 1126 | UpVal **up1 = getupvalref(L, fidx1, n1, &f1); | ||
| 1127 | UpVal **up2 = getupvalref(L, fidx2, n2, NULL); | ||
| 1128 | if (up1 == NULL || up2 == NULL) return 0; | ||
| 1129 | *up1 = *up2; | ||
| 1130 | luaC_objbarrier(L, f1, *up2); | ||
| 1131 | return 1; | ||
| 1132 | } | ||
| 1133 | |||
| 1134 | |||
| 1091 | LUA_API int lua_cpcall (lua_State *L, lua_CFunction func, void *ud) { | 1135 | LUA_API int lua_cpcall (lua_State *L, lua_CFunction func, void *ud) { |
| 1092 | lua_rawgeti(L, LUA_REGISTRYINDEX, LUA_RIDX_CPCALL); | 1136 | lua_rawgeti(L, LUA_REGISTRYINDEX, LUA_RIDX_CPCALL); |
| 1093 | lua_pushlightuserdata(L, &func); | 1137 | lua_pushlightuserdata(L, &func); |
