Skip to content

Commit c3662a5

Browse files
committed
refactor: further simplification using utf-8 autoconversion
Thanks, Pyry!
1 parent cf13fff commit c3662a5

File tree

3 files changed

+3
-12
lines changed

3 files changed

+3
-12
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', 'stackSave', 'stackRestore', 'lengthBytesUTF8', 'allocateUTF8OnStack']" \
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

+2-8
Original file line numberDiff line numberDiff line change
@@ -165,18 +165,12 @@ 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-
const lastStack = luaGlue.stackSave();
169-
const cstr = luaGlue.allocateUTF8OnStack(s) as unknown;
170-
const result = (this as LauxLib).luaL_loadbuffer(L, cstr as string, luaGlue.lengthBytesUTF8(s), s);
171-
luaGlue.stackRestore(lastStack);
172-
return result;
168+
return (this as LauxLib).luaL_loadbuffer(L, s, luaGlue.lengthBytesUTF8(s), s);
173169
},
174-
// Note that s has a "number" type, so we can pass a raw pointer
175-
luaL_loadbuffer: luaGlue.cwrap("luaL_loadbuffer", "number", ["number", "number", "number", "string"]),
176170
luaL_newstate: luaGlue.cwrap("lua_open", "number", []),
177171
}
178172
},
179-
"5.1.x": function(luaGlue: LuaEmscriptenModule, _lua: Lua) {
173+
"<=5.1.x": function(luaGlue: LuaEmscriptenModule, _lua: Lua) {
180174
return {
181175
luaL_loadbuffer: luaGlue.cwrap("luaL_loadbuffer", "number", ["number", "string", "number", "string"]),
182176
}

src/glue/glue.ts

-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
export interface LuaEmscriptenModule extends EmscriptenModule {
22
cwrap: typeof cwrap;
3-
stackSave: typeof stackSave;
4-
stackRestore: typeof stackRestore;
53
lengthBytesUTF8: typeof lengthBytesUTF8;
6-
allocateUTF8OnStack: typeof allocateUTF8;
74
}
85

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

0 commit comments

Comments
 (0)