Skip to content

Fix Unicode strings for luaL_loadbuffer in Lua 5.0#5

Merged
lolleko merged 6 commits intoTypeScriptToLua:masterfrom
YoRyan:fix-lua50-loadbuffer
Sep 1, 2022
Merged

Fix Unicode strings for luaL_loadbuffer in Lua 5.0#5
lolleko merged 6 commits intoTypeScriptToLua:masterfrom
YoRyan:fix-lua50-loadbuffer

Conversation

@YoRyan
Copy link
Contributor

@YoRyan YoRyan commented Aug 31, 2022

This particular binding chops 14 characters from the end of the input string, corrupting the Lua payload it contains. Quite honestly, I have no idea why this behavior is happening. I first noticed it when attempting (and failing) to load TypescriptToLua's lualib bundle. We are calling the C wrapper directly, so maybe this is caused by an underlying issue with emscripten?

For Lua 5.0, we need to manually convert from a UTF-16 Node string to a UTF-8 Lua string, as this doesn't seem to be automatic.

The string buffer size should be Lua's UTF-8 length, not Node's UTF-16 length.

@YoRyan YoRyan closed this Aug 31, 2022
@YoRyan YoRyan reopened this Aug 31, 2022
@YoRyan YoRyan changed the title Stop luaL_loadbuffer from truncating the input string in Lua 5.0 Fix Unicode strings for luaL_loadbuffer in Lua 5.0 Aug 31, 2022
@lolleko lolleko merged commit 21ae5c0 into TypeScriptToLua:master Sep 1, 2022
@YoRyan YoRyan deleted the fix-lua50-loadbuffer branch September 2, 2022 10:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants