static LuaDelegate newDelegate(IntPtr l, int p) { LuaState state = LuaState.get(l); LuaDLL.pua_pushvalue(l, p); // push function int fref = LuaDLL.puaL_ref(l, LuaIndexes.LUA_REGISTRYINDEX); // new ref function LuaDelegate f = new LuaDelegate(l, fref); LuaDLL.pua_pushvalue(l, p); LuaDLL.pua_pushinteger(l, fref); LuaDLL.pua_settable(l, -3); // __LuaDelegate[func]= fref state.delgateMap[fref] = f; return(f); }