Skip to content

Commit b1ee428

Browse files
committed
fix(5.0): prevent the string passed to luaL_loadbuffer from being truncated
1 parent d86a6ca commit b1ee428

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/binding-factory.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,12 +167,18 @@ const lauxBindings: Record<string, lauxBindingFactoryFunc> = {
167167
luaL_loadstring: function(L: LuaState, s: string) {
168168
return (this as LauxLib).luaL_loadbuffer(L, s, s.length, s);
169169
},
170+
luaL_loadbuffer: function(L: LuaState, s: string, slen: number, name: string) {
171+
// Terrible, awful hack to prevent the end of the string from being mangled by the C wrapper
172+
const pad = " ";
173+
const loadbuffer = luaGlue.cwrap("luaL_loadbuffer", "number", ["number", "string", "number", "string"]);
174+
return loadbuffer(L, s + pad, slen + pad.length, name);
175+
},
170176
luaL_newstate: luaGlue.cwrap("lua_open", "number", []),
171177
}
172178
},
173-
"<=5.1.x": function(luaGlue: LuaEmscriptenModule, _lua: Lua) {
179+
"5.1.x": function(luaGlue: LuaEmscriptenModule, _lua: Lua) {
174180
return {
175-
luaL_loadbuffer: luaGlue.cwrap("luaL_loadbuffer", "number", ["number", "string", "number", "string"]),
181+
luaL_loadbuffer: luaGlue.cwrap("luaL_loadbuffer", "number", ["number", "string", "number", "string"])
176182
}
177183
},
178184
">=5.1.0": function(luaGlue: LuaEmscriptenModule, lua: Lua) {

0 commit comments

Comments
 (0)