Skip to content

Commit e9b2283

Browse files
authored
Add support for Lua 5.5 (#8)
* Add support for Lua 5.5 * Update Lua 5.4 from 5.4.2 to 5.4.7 while I am at it * Polyfill luaL_openlibs macro
1 parent e7b8f31 commit e9b2283

File tree

10 files changed

+91
-8
lines changed

10 files changed

+91
-8
lines changed

scripts/build.sh

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,47 @@ elif [[ "$1" == "lua-5.2.4" ]]; then
136136
'_luaopen_debug', \
137137
'_luaopen_base' \
138138
]"
139+
elif [[ "$1" == "lua-5.5.0" ]]; then
140+
emcc -Ithirdparty/$1 thirdparty/$1/src/liblua.a \
141+
-s WASM=1 -O3 -o dist/glue/glue-$1.js \
142+
-s EXPORTED_RUNTIME_METHODS="['cwrap']" \
143+
-s MODULARIZE=1 \
144+
-s ALLOW_TABLE_GROWTH \
145+
-s EXPORT_NAME="glue" \
146+
-s ALLOW_MEMORY_GROWTH=1 \
147+
-s STRICT=1 \
148+
-s MALLOC=emmalloc \
149+
-s WASM_ASYNC_COMPILATION=0 \
150+
-s EXPORTED_FUNCTIONS="[
151+
'_luaL_newstate', \
152+
'_luaL_openselectedlibs', \
153+
'_luaL_loadstring', \
154+
'_luaL_makeseed', \
155+
'_lua_callk', \
156+
'_lua_close', \
157+
'_lua_copy', \
158+
'_lua_getfield', \
159+
'_lua_getglobal', \
160+
'_lua_gettable', \
161+
'_lua_gettop', \
162+
'_lua_isstring', \
163+
'_lua_pcallk', \
164+
'_lua_pushstring', \
165+
'_lua_pushvalue', \
166+
'_lua_rotate', \
167+
'_lua_setfield', \
168+
'_lua_settable', \
169+
'_lua_settop', \
170+
'_lua_tolstring', \
171+
'_lua_type', \
172+
'_lua_typename', \
173+
'_luaopen_math', \
174+
'_luaopen_string', \
175+
'_luaopen_io', \
176+
'_luaopen_table', \
177+
'_luaopen_debug', \
178+
'_luaopen_base' \
179+
]"
139180
else
140181
emcc -Ithirdparty/$1 thirdparty/$1/src/liblua.a \
141182
-s WASM=1 -O3 -o dist/glue/glue-$1.js \

scripts/download.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@ curl https://www.lua.org/ftp/lua-5.0.3.tar.gz | tar xvz -C `dirname "$0"`/../thi
44
curl https://www.lua.org/ftp/lua-5.1.5.tar.gz | tar xvz -C `dirname "$0"`/../thirdparty
55
curl https://www.lua.org/ftp/lua-5.2.4.tar.gz | tar xvz -C `dirname "$0"`/../thirdparty
66
curl https://www.lua.org/ftp/lua-5.3.6.tar.gz | tar xvz -C `dirname "$0"`/../thirdparty
7-
curl https://www.lua.org/ftp/lua-5.4.2.tar.gz | tar xvz -C `dirname "$0"`/../thirdparty
7+
curl https://www.lua.org/ftp/lua-5.4.7.tar.gz | tar xvz -C `dirname "$0"`/../thirdparty
8+
curl https://www.lua.org/ftp/lua-5.5.0.tar.gz | tar xvz -C `dirname "$0"`/../thirdparty
89

scripts/setup.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@
44
`dirname "$0"`/build.sh lua-5.1.5
55
`dirname "$0"`/build.sh lua-5.2.4
66
`dirname "$0"`/build.sh lua-5.3.6
7-
`dirname "$0"`/build.sh lua-5.4.2
7+
`dirname "$0"`/build.sh lua-5.4.7
8+
`dirname "$0"`/build.sh lua-5.5.0

simple-test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import * as Lua51 from "./dist/lua.51";
55
import * as Lua52 from "./dist/lua.52";
66
import * as Lua53 from "./dist/lua.53";
77
import * as Lua54 from "./dist/lua.54";
8+
import * as Lua55 from "./dist/lua.55";
89

910
function simpleTest(luaBundle: {lua: Lua, lauxlib: LauxLib, lualib: LuaLib}) {
1011
const state = luaBundle.lauxlib.luaL_newstate();
@@ -15,4 +16,5 @@ simpleTest(Lua50);
1516
simpleTest(Lua51);
1617
simpleTest(Lua52);
1718
simpleTest(Lua53);
18-
simpleTest(Lua54);
19+
simpleTest(Lua54);
20+
simpleTest(Lua55);

src/binding-factory.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,18 @@ const lauxBindings: Record<string, lauxBindingFactoryFunc> = {
201201
}
202202
}
203203
},
204+
"<5.5.0": function(_luaGlue: LuaEmscriptenModule, _lua: Lua) {
205+
return {
206+
luaL_makeseed: function() {
207+
throw "luaL_makeseed not supported before Lua 5.5";
208+
}
209+
}
210+
},
211+
">=5.5.0": function(luaGlue: LuaEmscriptenModule, _lua: Lua) {
212+
return {
213+
luaL_makeseed: luaGlue.cwrap("luaL_makeseed", "number", []),
214+
}
215+
},
204216
}
205217

206218
/** @internal */
@@ -246,11 +258,20 @@ const luaLibBindings: Record<string, luaLibBindingFactoryFunc> = {
246258
}
247259
}
248260
},
249-
">=5.1.0": function(luaGlue: LuaEmscriptenModule) {
261+
">=5.1.0 <5.5.0": function(luaGlue: LuaEmscriptenModule) {
250262
return {
251263
luaL_openlibs: luaGlue.cwrap("luaL_openlibs", null, ["number"]),
252264
}
253265
},
266+
">=5.5.0": function(luaGlue: LuaEmscriptenModule) {
267+
// In Lua 5.5, luaL_openlibs is a macro: #define luaL_openlibs(L) luaL_openselectedlibs(L, ~0, 0)
268+
const openselectedlibs = luaGlue.cwrap("luaL_openselectedlibs", null, ["number", "number", "number"]);
269+
return {
270+
luaL_openlibs: function(L: LuaState) {
271+
openselectedlibs(L, ~0, 0);
272+
}
273+
}
274+
},
254275
}
255276

256277
/** @internal */

src/glue/glue-lua-5.5.0.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import type { EmscriptenModuleFactorySync, LuaEmscriptenModule } from "./glue";
2+
3+
declare const glue: EmscriptenModuleFactorySync<LuaEmscriptenModule>;
4+
5+
export default glue;

src/lua.54.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { createLauxLib, createLua, createLuaLib } from "./binding-factory";
2-
import glue from "./glue/glue-lua-5.4.2";
2+
import glue from "./glue/glue-lua-5.4.7";
33

44
let luaGlue = glue({
55
print: console.log,
66
printErr: console.error,
77
});
88

9-
export const lua = createLua(luaGlue, "5.4.2");
10-
export const lauxlib = createLauxLib(luaGlue, lua, "5.4.2");
11-
export const lualib = createLuaLib(luaGlue, "5.4.2");
9+
export const lua = createLua(luaGlue, "5.4.7");
10+
export const lauxlib = createLauxLib(luaGlue, lua, "5.4.7");
11+
export const lualib = createLuaLib(luaGlue, "5.4.7");

src/lua.55.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { createLauxLib, createLua, createLuaLib } from "./binding-factory";
2+
import glue from "./glue/glue-lua-5.5.0";
3+
4+
let luaGlue = glue({
5+
print: console.log,
6+
printErr: console.error,
7+
});
8+
9+
export const lua = createLua(luaGlue, "5.5.0");
10+
export const lauxlib = createLauxLib(luaGlue, lua, "5.5.0");
11+
export const lualib = createLuaLib(luaGlue, "5.5.0");

src/lua.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,5 +66,6 @@ export interface LauxLib {
6666
luaL_dostring(L: LuaState, s: string): number;
6767
luaL_loadbuffer(L: LuaState, s: string, slen: number, name: string): typeof LUA_OK | typeof LUA_ERRSYNTAX | typeof LUA_ERRMEM
6868
luaL_loadstring(L: LuaState, s: string): typeof LUA_OK | typeof LUA_ERRSYNTAX | typeof LUA_ERRMEM;
69+
luaL_makeseed(): number;
6970
luaL_newstate(): LuaState;
7071
}

0 commit comments

Comments
 (0)