提交 994bea5a 编写于 作者: J johnche(车雄生)

添加xlua.release,用于主动解除lua对c#某对象的引用

上级 38e26cad
......@@ -569,6 +569,9 @@ namespace XLua
LuaAPI.xlua_pushasciistring(L, "tofunction");
LuaAPI.lua_pushstdcallcfunction(L, StaticLuaCallbacks.ToFunction);
LuaAPI.lua_rawset(L, -3);
LuaAPI.xlua_pushasciistring(L, "release");
LuaAPI.lua_pushstdcallcfunction(L, StaticLuaCallbacks.ReleaseCsObject);
LuaAPI.lua_rawset(L, -3);
LuaAPI.lua_pop(L, 1);
LuaAPI.lua_createtable(L, 1, 4); // 4 for __gc, __tostring, __index, __newindex
......@@ -1217,6 +1220,15 @@ namespace XLua
return getCsObj(L, index, LuaAPI.xlua_tocsobj_fast(L,index));
}
internal void ReleaseCSObj(RealStatePtr L, int index)
{
int udata = LuaAPI.xlua_tocsobj_safe(L, index);
if (udata != -1)
{
objects.Replace(udata, null);
}
}
List<LuaCSFunction> fix_cs_functions = new List<LuaCSFunction>();
internal LuaCSFunction GetFixCSFunction(int index)
......
......@@ -29,7 +29,7 @@ namespace XLua
internal LuaCSFunction StaticCSFunctionWraper, FixCSFunctionWraper;
internal LuaCSFunction DelegateCtor;
public StaticLuaCallbacks()
{
GcMeta = new LuaCSFunction(StaticLuaCallbacks.LuaGC);
......@@ -94,7 +94,7 @@ namespace XLua
LuaCSFunction func = (LuaCSFunction)translator.FastGetCSObj(L, LuaAPI.xlua_upvalueindex(1));
return func(L);
}
catch(Exception e)
catch (Exception e)
{
return LuaAPI.luaL_error(L, "c# exception in StaticCSFunction:" + e);
}
......@@ -1079,5 +1079,20 @@ namespace XLua
return LuaAPI.luaL_error(L, "c# exception in ToFunction: " + e);
}
}
[MonoPInvokeCallback(typeof(LuaCSFunction))]
public static int ReleaseCsObject(RealStatePtr L)
{
try
{
ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);
translator.ReleaseCSObj(L, 1);
return 0;
}
catch (Exception e)
{
return LuaAPI.luaL_error(L, "c# exception in ReleaseCsObject: " + e);
}
}
}
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册