diff --git a/PorygonSharp/Script.cs b/PorygonSharp/Script.cs index 22418f7..f839fc7 100644 --- a/PorygonSharp/Script.cs +++ b/PorygonSharp/Script.cs @@ -36,24 +36,10 @@ namespace PorygonSharp public Script(string s) { - _internalScriptHandle = Create(new StringBuilder(s)); + _internalScriptHandle = Create(s); _internalScript = Marshal.PtrToStructure(_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); } } \ No newline at end of file diff --git a/PorygonSharpTests/UserDataTests.cs b/PorygonSharpTests/UserDataTests.cs index 734c293..4019617 100644 --- a/PorygonSharpTests/UserDataTests.cs +++ b/PorygonSharpTests/UserDataTests.cs @@ -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 diff --git a/libPorygonLang.so b/libPorygonLang.so index fc7093d..55f3687 100755 Binary files a/libPorygonLang.so and b/libPorygonLang.so differ