diff --git a/scripts/build.sh b/scripts/build.sh index b98acc6..edfb87b 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -20,7 +20,7 @@ cd ../.. if [[ "$1" == "lua-5.0.3" ]]; then emcc -Ithirdparty/$1 thirdparty/$1/lib/liblua.a thirdparty/$1/lib/liblualib.a \ -s WASM=1 -O3 -o dist/glue/glue-$1.js \ - -s EXPORTED_RUNTIME_METHODS="['cwrap']" \ + -s EXPORTED_RUNTIME_METHODS="['cwrap', 'lengthBytesUTF8']" \ -s MODULARIZE=1 \ -s ALLOW_TABLE_GROWTH \ -s EXPORT_NAME="glue" \ diff --git a/src/binding-factory.ts b/src/binding-factory.ts index 1c99f5f..930c777 100644 --- a/src/binding-factory.ts +++ b/src/binding-factory.ts @@ -165,7 +165,7 @@ const lauxBindings: Record = { return (this as LauxLib).luaL_loadstring(L, s) || lua.lua_pcall(L, 0, LUA_MULTRET, 0); }, luaL_loadstring: function(L: LuaState, s: string) { - return (this as LauxLib).luaL_loadbuffer(L, s, s.length, s); + return (this as LauxLib).luaL_loadbuffer(L, s, luaGlue.lengthBytesUTF8(s), s); }, luaL_newstate: luaGlue.cwrap("lua_open", "number", []), } diff --git a/src/glue/glue.ts b/src/glue/glue.ts index a16d5b6..21c4b09 100644 --- a/src/glue/glue.ts +++ b/src/glue/glue.ts @@ -1,5 +1,6 @@ export interface LuaEmscriptenModule extends EmscriptenModule { cwrap: typeof cwrap; + lengthBytesUTF8: typeof lengthBytesUTF8; } export type EmscriptenModuleFactorySync = (