Skip to content

Commit 21ae5c0

Browse files
authored
Merge pull request #5 from YoRyan/fix-lua50-loadbuffer
Fix Unicode strings for luaL_loadbuffer in Lua 5.0
2 parents d86a6ca + c3662a5 commit 21ae5c0

File tree

3 files changed

+3
-2
lines changed

3 files changed

+3
-2
lines changed

scripts/build.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ cd ../..
2020
if [[ "$1" == "lua-5.0.3" ]]; then
2121
emcc -Ithirdparty/$1 thirdparty/$1/lib/liblua.a thirdparty/$1/lib/liblualib.a \
2222
-s WASM=1 -O3 -o dist/glue/glue-$1.js \
23-
-s EXPORTED_RUNTIME_METHODS="['cwrap']" \
23+
-s EXPORTED_RUNTIME_METHODS="['cwrap', 'lengthBytesUTF8']" \
2424
-s MODULARIZE=1 \
2525
-s ALLOW_TABLE_GROWTH \
2626
-s EXPORT_NAME="glue" \

src/binding-factory.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ const lauxBindings: Record<string, lauxBindingFactoryFunc> = {
165165
return (this as LauxLib).luaL_loadstring(L, s) || lua.lua_pcall(L, 0, LUA_MULTRET, 0);
166166
},
167167
luaL_loadstring: function(L: LuaState, s: string) {
168-
return (this as LauxLib).luaL_loadbuffer(L, s, s.length, s);
168+
return (this as LauxLib).luaL_loadbuffer(L, s, luaGlue.lengthBytesUTF8(s), s);
169169
},
170170
luaL_newstate: luaGlue.cwrap("lua_open", "number", []),
171171
}

src/glue/glue.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
export interface LuaEmscriptenModule extends EmscriptenModule {
22
cwrap: typeof cwrap;
3+
lengthBytesUTF8: typeof lengthBytesUTF8;
34
}
45

56
export type EmscriptenModuleFactorySync<T extends EmscriptenModule = EmscriptenModule> = (

0 commit comments

Comments
 (0)