Fixes for setting values in UserData
This commit is contained in:
parent
4a91629f98
commit
21e6d3af24
|
@ -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 evalValue = Convert.ChangeType(new EvalValue(val).GetObjectValue(), field.FieldType);
|
||||
field.SetValue(obj, evalValue);
|
||||
});
|
||||
var scriptType = ScriptType.ScriptType.GetScriptType(field.FieldType);
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue