void lua_funcinfo(lua_Object func, const char **filename, int32 *linedefined) { if (!lua_isfunction(func)) lua_error("API - `funcinfo' called with a non-function value"); else { TObject *f = luaA_protovalue(Address(func)); if (normalized_type(f) == LUA_T_PROTO) { *filename = tfvalue(f)->fileName->str; *linedefined = tfvalue(f)->lineDefined; } else { *filename = "(C)"; *linedefined = -1; } } }
lua_Object lua_getlocal(lua_Function func, int32 local_number, char **name) { // check whether func is a Lua function if (lua_tag(func) != LUA_T_PROTO) return LUA_NOOBJECT; else { TObject *f = Address(func); TProtoFunc *fp = luaA_protovalue(f)->value.tf; *name = luaF_getlocalname(fp, local_number, lua_currentline(func)); if (*name) { // if "*name", there must be a LUA_T_LINE // therefore, f + 2 points to function base return Ref((f + 2) + (local_number - 1)); } else return LUA_NOOBJECT; } }
int32 lua_setlocal(lua_Function func, int32 local_number) { // check whether func is a Lua function if (lua_tag(func) != LUA_T_PROTO) return 0; else { TObject *f = Address(func); TProtoFunc *fp = luaA_protovalue(f)->value.tf; char *name = luaF_getlocalname(fp, local_number, lua_currentline(func)); checkCparams(1); --lua_state->stack.top; if (name) { // if "name", there must be a LUA_T_LINE // therefore, f+2 points to function base *((f + 2) + (local_number - 1)) = *lua_state->stack.top; return 1; } else return 0; } }
lua_CFunction lua_getcfunction (lua_Object object) { if (!lua_iscfunction(object)) return NULL; else return fvalue(luaA_protovalue(Address(object))); }