Skip to content

Commit

Permalink
Encode strings as UTF8 when sending them to Lua, to match the string …
Browse files Browse the repository at this point in the history
…decoding.
  • Loading branch information
DaleStan committed Jul 23, 2024
1 parent 3c7356a commit 1e2e463
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
10 changes: 5 additions & 5 deletions Yafc.Parser/LuaContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,13 @@ private enum Type {
[UnmanagedCallConv(CallConvs = [typeof(System.Runtime.CompilerServices.CallConvCdecl)])]
private static partial void lua_close(IntPtr state);

[LibraryImport(LUA, StringMarshalling = StringMarshalling.Custom, StringMarshallingCustomType = typeof(System.Runtime.InteropServices.Marshalling.AnsiStringMarshaller))]
[LibraryImport(LUA, StringMarshalling = StringMarshalling.Utf8)]
[UnmanagedCallConv(CallConvs = new System.Type[] { typeof(System.Runtime.CompilerServices.CallConvCdecl) })]
private static partial Result luaL_loadbufferx(IntPtr state, in byte buf, IntPtr sz, string name, string? mode);
[LibraryImport(LUA)]
[UnmanagedCallConv(CallConvs = [typeof(System.Runtime.CompilerServices.CallConvCdecl)])]
private static partial Result lua_pcallk(IntPtr state, int nargs, int nresults, int msgh, IntPtr ctx, IntPtr k);
[LibraryImport(LUA, StringMarshalling = StringMarshalling.Custom, StringMarshallingCustomType = typeof(System.Runtime.InteropServices.Marshalling.AnsiStringMarshaller))]
[LibraryImport(LUA, StringMarshalling = StringMarshalling.Utf8)]
[UnmanagedCallConv(CallConvs = new System.Type[] { typeof(System.Runtime.CompilerServices.CallConvCdecl) })]
private static partial void luaL_traceback(IntPtr state, IntPtr state2, string? msg, int level);

Expand All @@ -74,10 +74,10 @@ private enum Type {
[UnmanagedCallConv(CallConvs = new System.Type[] { typeof(System.Runtime.CompilerServices.CallConvCdecl) })]
private static partial double lua_tonumberx(IntPtr state, int idx, [MarshalAs(UnmanagedType.Bool)] out bool isnum);

[LibraryImport(LUA, StringMarshalling = StringMarshalling.Custom, StringMarshallingCustomType = typeof(System.Runtime.InteropServices.Marshalling.AnsiStringMarshaller))]
[LibraryImport(LUA, StringMarshalling = StringMarshalling.Utf8)]
[UnmanagedCallConv(CallConvs = new System.Type[] { typeof(System.Runtime.CompilerServices.CallConvCdecl) })]
private static partial int lua_getglobal(IntPtr state, string var);
[LibraryImport(LUA, StringMarshalling = StringMarshalling.Custom, StringMarshallingCustomType = typeof(System.Runtime.InteropServices.Marshalling.AnsiStringMarshaller))]
[LibraryImport(LUA, StringMarshalling = StringMarshalling.Utf8)]
[UnmanagedCallConv(CallConvs = new System.Type[] { typeof(System.Runtime.CompilerServices.CallConvCdecl) })]
private static partial void lua_setglobal(IntPtr state, string name);
[LibraryImport(LUA)]
Expand All @@ -90,7 +90,7 @@ private enum Type {
[LibraryImport(LUA)]
[UnmanagedCallConv(CallConvs = [typeof(System.Runtime.CompilerServices.CallConvCdecl)])]
private static partial void lua_pushnil(IntPtr state);
[LibraryImport(LUA, StringMarshalling = StringMarshalling.Custom, StringMarshallingCustomType = typeof(System.Runtime.InteropServices.Marshalling.AnsiStringMarshaller))]
[LibraryImport(LUA, StringMarshalling = StringMarshalling.Utf8)]
[UnmanagedCallConv(CallConvs = new System.Type[] { typeof(System.Runtime.CompilerServices.CallConvCdecl) })]
private static partial IntPtr lua_pushstring(IntPtr state, string s);
[LibraryImport(LUA)]
Expand Down
1 change: 1 addition & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Date:
- Add the ability to switch through project pages with control-tab and control-shift-tab
Bugfixes:
- Fix a possible threading race while destroying textures, which could cause an illegal access crash.
- Fix a loading error when mods use non-ASCII characters in their settings.
----------------------------------------------------------------------------------------------------------------------
Version 0.7.3
Date: July 21st 2024
Expand Down

0 comments on commit 1e2e463

Please sign in to comment.