Ensure LuaValues are disposed.

Adding in these missing calls prevents these instances from having to be finalized.
This commit is contained in:
RoosterDragon
2015-12-23 16:04:58 +00:00
parent 387d0d0e3f
commit 6ab6d774a7
11 changed files with 184 additions and 142 deletions

View File

@@ -71,7 +71,7 @@ namespace OpenRA.Mods.Common.Scripting
var actors = new List<Actor>();
for (var i = 0; i < actorTypes.Length; i++)
{
var af = actionFunc != null ? actionFunc.CopyReference() as LuaFunction : null;
var af = actionFunc != null ? (LuaFunction)actionFunc.CopyReference() : null;
var actor = CreateActor(owner, actorTypes[i], false, entryPath[0], entryPath.Length > 1 ? entryPath[1] : (CPos?)null);
actors.Add(actor);
@@ -86,8 +86,9 @@ namespace OpenRA.Mods.Common.Scripting
{
actor.QueueActivity(new CallFunc(() =>
{
af.Call(actor.ToLuaValue(Context));
af.Dispose();
using (af)
using (var a = actor.ToLuaValue(Context))
af.Call(a);
}));
}
};
@@ -128,11 +129,12 @@ namespace OpenRA.Mods.Common.Scripting
if (actionFunc != null)
{
var af = actionFunc.CopyReference() as LuaFunction;
var af = (LuaFunction)actionFunc.CopyReference();
transport.QueueActivity(new CallFunc(() =>
{
af.Call(transport.ToLuaValue(Context), passengers.ToArray().ToLuaValue(Context));
af.Dispose();
using (af)
using (LuaValue t = transport.ToLuaValue(Context), p = passengers.ToArray().ToLuaValue(Context))
af.Call(t, p);
}));
}
else
@@ -164,11 +166,12 @@ namespace OpenRA.Mods.Common.Scripting
if (exitFunc != null)
{
var ef = exitFunc.CopyReference() as LuaFunction;
var ef = (LuaFunction)exitFunc.CopyReference();
transport.QueueActivity(new CallFunc(() =>
{
ef.Call(transport.ToLuaValue(Context));
ef.Dispose();
using (ef)
using (var t = transport.ToLuaValue(Context))
ef.Call(t);
}));
}
else if (exitPath != null)
@@ -180,8 +183,16 @@ namespace OpenRA.Mods.Common.Scripting
}
var ret = Context.CreateTable();
ret.Add(1, transport.ToLuaValue(Context));
ret.Add(2, passengers.ToArray().ToLuaValue(Context));
using (LuaValue
tKey = 1,
tValue = transport.ToLuaValue(Context),
pKey = 2,
pValue = passengers.ToArray().ToLuaValue(Context))
{
ret.Add(tKey, tValue);
ret.Add(pKey, pValue);
}
return ret;
}
}