public static void DoRefLuaFun(IntPtr L, string funName, int reference, LuaDLL.tolua_getref_fun refFun) { int moreOldTop = LuaDLL.lua_gettop(L); if (refFun == null) { LuaDLL.lua_getref(L, reference); } else { refFun(L, reference); } if (LuaDLL.lua_isfunction(L, -1) || LuaDLL.lua_istable(L, -1)) { int oldTop = LuaDLL.lua_gettop(L); LuaDLL.lua_getglobal(L, "miku_handle_error"); do { LuaDLL.lua_getglobal(L, funName); if (!LuaDLL.lua_isfunction(L, -1)) { break; } LuaDLL.lua_pushvalue(L, oldTop); if (LuaDLL.lua_pcall(L, 1, 0, oldTop + 1) == 0) { LuaDLL.lua_remove(L, oldTop + 1); } } while (false); LuaDLL.lua_settop(L, oldTop); } LuaDLL.lua_settop(L, moreOldTop); }
static int CheckType(IntPtr L) { if (LuaDLL.lua_isfunction(L, 1)) { LuaDLL.lua_pushnumber(L, 1); } else if (LuaDLL.lua_istable(L, 1)) { LuaDLL.lua_pushnumber(L, 2); } else { LuaDLL.lua_pushnumber(L, 0); } return(1); }
public static void DoRefLuaFun(IntPtr L, string funName, int reference) { LuaDLL.lua_getref(L, reference); int oldTop = LuaDLL.lua_gettop(L); LuaDLL.lua_getglobal(L, "miku_handle_error"); do { LuaDLL.lua_getglobal(L, funName); if (!LuaDLL.lua_isfunction(L, -1)) { break; } LuaDLL.lua_pushvalue(L, oldTop); if (LuaDLL.lua_pcall(L, 1, 0, oldTop + 1) == 0) { LuaDLL.lua_remove(L, oldTop + 1); } } while (false); LuaDLL.lua_settop(L, oldTop); LuaDLL.lua_pop(L, 1); }