Fixes for setting values in UserData

This commit is contained in:
Deukhoofd 2019-06-14 22:40:15 +02:00
parent 4a91629f98
commit 21e6d3af24
No known key found for this signature in database
GPG Key ID: B4C087AC81641654
2 changed files with 26 additions and 3 deletions

View File

@ -30,8 +30,8 @@ namespace PorygonSharp.UserData
});
var setter = new SetterDelegate((ptr, val) =>
{
var evalValue = new EvalValue(val).GetObjectValue();
var obj = GCHandle.FromIntPtr(ptr).Target;
var obj = GCHandle.FromIntPtr(ptr).Target;
var evalValue = Convert.ChangeType(new EvalValue(val).GetObjectValue(), field.FieldType);
field.SetValue(obj, evalValue);
});
var scriptType = ScriptType.ScriptType.GetScriptType(field.FieldType);

View File

@ -138,12 +138,35 @@ end
}
}
[Test]
public void Test10()
{
UserDataHandler.RegisterType("testObject", typeof(UserDataTestObject));
using (var script = Script.CreateScript(@"
function test(testObject v)
v['Foo'] = 20000
end
"))
{
var diags = script.Diagnostics.GetDiagnostics();
foreach (var diag in diags)
{
throw new Exception(diag.GetCode().ToString());
}
script.Evaluate();
var parameter = new UserDataTestObject();
script.CallFunction("test", parameter);
Assert.AreEqual(20000, parameter.Foo);
}
}
[Test]
public void TestHash()
{
var hash = HashedString.ScriptHash("Foo");
Assert.AreEqual(193501609, hash);
}
}
}