Take advantage of porygon now using u16strings

This commit is contained in:
Deukhoofd 2019-06-15 17:29:14 +02:00
parent d01f264a0d
commit 203ddf149f
No known key found for this signature in database
GPG Key ID: B4C087AC81641654
3 changed files with 12 additions and 26 deletions

View File

@ -36,24 +36,10 @@ namespace PorygonSharp
public Script(string s)
{
_internalScriptHandle = Create(new StringBuilder(s));
_internalScriptHandle = Create(s);
_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()
{
Marshal.FreeHGlobal(_internalScriptHandle);
@ -95,20 +81,20 @@ namespace PorygonSharp
}
[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)]
private static extern void Evaluate(IntPtr script);
[DllImport("libPorygonLang", EntryPoint = "GetLastValue", CallingConvention = CallingConvention.Cdecl)]
private static extern IntPtr GetLastValue(IntPtr script);
[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)]
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)]
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)]
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);
}
}

View File

@ -21,7 +21,7 @@ namespace PorygonSharpTests
public void CanGetFromUserDataField()
{
UserDataHandler.RegisterType("testObject", typeof(UserDataTestObject));
using (var script = Script.CreateScript(@"
using (var script = new Script(@"
function test(testObject v)
result = v['Foo']
end
@ -45,7 +45,7 @@ end
public void CanSetToUserDataField()
{
UserDataHandler.RegisterType("testObject", typeof(UserDataTestObject));
using (var script = Script.CreateScript(@"
using (var script = new Script(@"
function test(testObject v)
v['Foo'] = 20000
end
@ -69,7 +69,7 @@ end
public void CanGetFromPropertyWithoutSetter()
{
UserDataHandler.RegisterType("testObject", typeof(UserDataTestObject));
using (var script = Script.CreateScript(@"
using (var script = new Script(@"
function test(testObject v)
result = v['GetOnly']
end
@ -93,7 +93,7 @@ end
public void CantSetToPropertyWithoutSetter()
{
UserDataHandler.RegisterType("testObject", typeof(UserDataTestObject));
using (var script = Script.CreateScript(@"
using (var script = new Script(@"
function test(testObject v)
v['GetOnly'] = 10000
end
@ -110,7 +110,7 @@ end
public void CanGetFromReadonlyField()
{
UserDataHandler.RegisterType("testObject", typeof(UserDataTestObject));
using (var script = Script.CreateScript(@"
using (var script = new Script(@"
function test(testObject v)
result = v['ReadOnly']
end
@ -134,7 +134,7 @@ end
public void CantSetToReadonlyField()
{
UserDataHandler.RegisterType("testObject", typeof(UserDataTestObject));
using (var script = Script.CreateScript(@"
using (var script = new Script(@"
function test(testObject v)
v['ReadOnly'] = 10000
end

Binary file not shown.