Added support for UserData
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user