Take advantage of porygon now using u16strings
This commit is contained in:
parent
d01f264a0d
commit
203ddf149f
|
@ -36,24 +36,10 @@ namespace PorygonSharp
|
||||||
|
|
||||||
public Script(string s)
|
public Script(string s)
|
||||||
{
|
{
|
||||||
_internalScriptHandle = Create(new StringBuilder(s));
|
_internalScriptHandle = Create(s);
|
||||||
_internalScript = Marshal.PtrToStructure<InternalScript>(_internalScriptHandle);
|
_internalScript = Marshal.PtrToStructure<InternalScript>(_internalScriptHandle);
|
||||||
}
|
}
|
||||||
|
|
||||||
[HandleProcessCorruptedStateExceptions]
|
|
||||||
[SecurityCritical]
|
|
||||||
public static Script CreateScript(string s)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
return new Script(s);
|
|
||||||
}
|
|
||||||
catch
|
|
||||||
{
|
|
||||||
throw new Exception("This");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
Marshal.FreeHGlobal(_internalScriptHandle);
|
Marshal.FreeHGlobal(_internalScriptHandle);
|
||||||
|
@ -95,20 +81,20 @@ namespace PorygonSharp
|
||||||
}
|
}
|
||||||
|
|
||||||
[DllImport("libPorygonLang", EntryPoint = "CreateScript", CallingConvention = CallingConvention.Cdecl)]
|
[DllImport("libPorygonLang", EntryPoint = "CreateScript", CallingConvention = CallingConvention.Cdecl)]
|
||||||
private static extern IntPtr Create(StringBuilder s);
|
private static extern IntPtr Create([MarshalAs(UnmanagedType.LPWStr)]string s);
|
||||||
[DllImport("libPorygonLang", EntryPoint = "EvaluateScript", CallingConvention = CallingConvention.Cdecl)]
|
[DllImport("libPorygonLang", EntryPoint = "EvaluateScript", CallingConvention = CallingConvention.Cdecl)]
|
||||||
private static extern void Evaluate(IntPtr script);
|
private static extern void Evaluate(IntPtr script);
|
||||||
[DllImport("libPorygonLang", EntryPoint = "GetLastValue", CallingConvention = CallingConvention.Cdecl)]
|
[DllImport("libPorygonLang", EntryPoint = "GetLastValue", CallingConvention = CallingConvention.Cdecl)]
|
||||||
private static extern IntPtr GetLastValue(IntPtr script);
|
private static extern IntPtr GetLastValue(IntPtr script);
|
||||||
[DllImport("libPorygonLang", EntryPoint = "HasVariable", CallingConvention = CallingConvention.Cdecl)]
|
[DllImport("libPorygonLang", EntryPoint = "HasVariable", CallingConvention = CallingConvention.Cdecl)]
|
||||||
private static extern bool HasVariable(IntPtr script, string key);
|
private static extern bool HasVariable(IntPtr script, [MarshalAs(UnmanagedType.LPWStr)]string key);
|
||||||
[DllImport("libPorygonLang", EntryPoint = "GetVariable", CallingConvention = CallingConvention.Cdecl)]
|
[DllImport("libPorygonLang", EntryPoint = "GetVariable", CallingConvention = CallingConvention.Cdecl)]
|
||||||
private static extern IntPtr GetVariable(IntPtr script, string key);
|
private static extern IntPtr GetVariable(IntPtr script, [MarshalAs(UnmanagedType.LPWStr)]string key);
|
||||||
|
|
||||||
[DllImport("libPorygonLang", EntryPoint = "HasFunction", CallingConvention = CallingConvention.Cdecl)]
|
[DllImport("libPorygonLang", EntryPoint = "HasFunction", CallingConvention = CallingConvention.Cdecl)]
|
||||||
private static extern bool HasFunction(IntPtr script, string key);
|
private static extern bool HasFunction(IntPtr script, [MarshalAs(UnmanagedType.LPWStr)]string key);
|
||||||
[DllImport("libPorygonLang", EntryPoint = "CallFunction", CallingConvention = CallingConvention.Cdecl)]
|
[DllImport("libPorygonLang", EntryPoint = "CallFunction", CallingConvention = CallingConvention.Cdecl)]
|
||||||
private static extern IntPtr CallFunction(IntPtr script, string key, IntPtr[] parameters, int parameterCount);
|
private static extern IntPtr CallFunction(IntPtr script, [MarshalAs(UnmanagedType.LPWStr)]string key, IntPtr[] parameters, int parameterCount);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -21,7 +21,7 @@ namespace PorygonSharpTests
|
||||||
public void CanGetFromUserDataField()
|
public void CanGetFromUserDataField()
|
||||||
{
|
{
|
||||||
UserDataHandler.RegisterType("testObject", typeof(UserDataTestObject));
|
UserDataHandler.RegisterType("testObject", typeof(UserDataTestObject));
|
||||||
using (var script = Script.CreateScript(@"
|
using (var script = new Script(@"
|
||||||
function test(testObject v)
|
function test(testObject v)
|
||||||
result = v['Foo']
|
result = v['Foo']
|
||||||
end
|
end
|
||||||
|
@ -45,7 +45,7 @@ end
|
||||||
public void CanSetToUserDataField()
|
public void CanSetToUserDataField()
|
||||||
{
|
{
|
||||||
UserDataHandler.RegisterType("testObject", typeof(UserDataTestObject));
|
UserDataHandler.RegisterType("testObject", typeof(UserDataTestObject));
|
||||||
using (var script = Script.CreateScript(@"
|
using (var script = new Script(@"
|
||||||
function test(testObject v)
|
function test(testObject v)
|
||||||
v['Foo'] = 20000
|
v['Foo'] = 20000
|
||||||
end
|
end
|
||||||
|
@ -69,7 +69,7 @@ end
|
||||||
public void CanGetFromPropertyWithoutSetter()
|
public void CanGetFromPropertyWithoutSetter()
|
||||||
{
|
{
|
||||||
UserDataHandler.RegisterType("testObject", typeof(UserDataTestObject));
|
UserDataHandler.RegisterType("testObject", typeof(UserDataTestObject));
|
||||||
using (var script = Script.CreateScript(@"
|
using (var script = new Script(@"
|
||||||
function test(testObject v)
|
function test(testObject v)
|
||||||
result = v['GetOnly']
|
result = v['GetOnly']
|
||||||
end
|
end
|
||||||
|
@ -93,7 +93,7 @@ end
|
||||||
public void CantSetToPropertyWithoutSetter()
|
public void CantSetToPropertyWithoutSetter()
|
||||||
{
|
{
|
||||||
UserDataHandler.RegisterType("testObject", typeof(UserDataTestObject));
|
UserDataHandler.RegisterType("testObject", typeof(UserDataTestObject));
|
||||||
using (var script = Script.CreateScript(@"
|
using (var script = new Script(@"
|
||||||
function test(testObject v)
|
function test(testObject v)
|
||||||
v['GetOnly'] = 10000
|
v['GetOnly'] = 10000
|
||||||
end
|
end
|
||||||
|
@ -110,7 +110,7 @@ end
|
||||||
public void CanGetFromReadonlyField()
|
public void CanGetFromReadonlyField()
|
||||||
{
|
{
|
||||||
UserDataHandler.RegisterType("testObject", typeof(UserDataTestObject));
|
UserDataHandler.RegisterType("testObject", typeof(UserDataTestObject));
|
||||||
using (var script = Script.CreateScript(@"
|
using (var script = new Script(@"
|
||||||
function test(testObject v)
|
function test(testObject v)
|
||||||
result = v['ReadOnly']
|
result = v['ReadOnly']
|
||||||
end
|
end
|
||||||
|
@ -134,7 +134,7 @@ end
|
||||||
public void CantSetToReadonlyField()
|
public void CantSetToReadonlyField()
|
||||||
{
|
{
|
||||||
UserDataHandler.RegisterType("testObject", typeof(UserDataTestObject));
|
UserDataHandler.RegisterType("testObject", typeof(UserDataTestObject));
|
||||||
using (var script = Script.CreateScript(@"
|
using (var script = new Script(@"
|
||||||
function test(testObject v)
|
function test(testObject v)
|
||||||
v['ReadOnly'] = 10000
|
v['ReadOnly'] = 10000
|
||||||
end
|
end
|
||||||
|
|
Binary file not shown.
Loading…
Reference in New Issue