Added support for UserData

This commit is contained in:
2019-06-14 22:22:42 +02:00
parent d8bf2c2994
commit 4a91629f98
8 changed files with 226 additions and 2 deletions

View File

@@ -1,6 +1,8 @@
using System;
using NUnit.Framework;
using PorygonSharp;
using PorygonSharp.UserData;
using PorygonSharp.Utilities;
namespace PorygonSharpTests
{
@@ -107,5 +109,41 @@ namespace PorygonSharpTests
}
}
private class UserDataTestObject
{
public int Foo = 200;
}
[Test]
public void Test9()
{
UserDataHandler.RegisterType("testObject", typeof(UserDataTestObject));
using (var script = Script.CreateScript(@"
function test(testObject v)
result = v['Foo']
end
"))
{
var diags = script.Diagnostics.GetDiagnostics();
foreach (var diag in diags)
{
throw new Exception(diag.GetCode().ToString());
}
script.Evaluate();
script.CallFunction("test", new UserDataTestObject());
var variable = script.GetVariable("result");
Assert.AreEqual(200, variable.EvaluateInteger());
}
}
[Test]
public void TestHash()
{
var hash = HashedString.ScriptHash("Foo");
Assert.AreEqual(193501609, hash);
}
}
}