diff --git a/scripts/build.sh b/scripts/build.sh index 39868a6..53b7bbf 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -136,6 +136,47 @@ elif [[ "$1" == "lua-5.2.4" ]]; then '_luaopen_debug', \ '_luaopen_base' \ ]" +elif [[ "$1" == "lua-5.5.0" ]]; then + emcc -Ithirdparty/$1 thirdparty/$1/src/liblua.a \ + -s WASM=1 -O3 -o dist/glue/glue-$1.js \ + -s EXPORTED_RUNTIME_METHODS="['cwrap']" \ + -s MODULARIZE=1 \ + -s ALLOW_TABLE_GROWTH \ + -s EXPORT_NAME="glue" \ + -s ALLOW_MEMORY_GROWTH=1 \ + -s STRICT=1 \ + -s MALLOC=emmalloc \ + -s WASM_ASYNC_COMPILATION=0 \ + -s EXPORTED_FUNCTIONS="[ + '_luaL_newstate', \ + '_luaL_openselectedlibs', \ + '_luaL_loadstring', \ + '_luaL_makeseed', \ + '_lua_callk', \ + '_lua_close', \ + '_lua_copy', \ + '_lua_getfield', \ + '_lua_getglobal', \ + '_lua_gettable', \ + '_lua_gettop', \ + '_lua_isstring', \ + '_lua_pcallk', \ + '_lua_pushstring', \ + '_lua_pushvalue', \ + '_lua_rotate', \ + '_lua_setfield', \ + '_lua_settable', \ + '_lua_settop', \ + '_lua_tolstring', \ + '_lua_type', \ + '_lua_typename', \ + '_luaopen_math', \ + '_luaopen_string', \ + '_luaopen_io', \ + '_luaopen_table', \ + '_luaopen_debug', \ + '_luaopen_base' \ + ]" else emcc -Ithirdparty/$1 thirdparty/$1/src/liblua.a \ -s WASM=1 -O3 -o dist/glue/glue-$1.js \ diff --git a/scripts/download.sh b/scripts/download.sh index 10d5c94..41d8d59 100755 --- a/scripts/download.sh +++ b/scripts/download.sh @@ -4,5 +4,6 @@ curl https://www.lua.org/ftp/lua-5.0.3.tar.gz | tar xvz -C `dirname "$0"`/../thi curl https://www.lua.org/ftp/lua-5.1.5.tar.gz | tar xvz -C `dirname "$0"`/../thirdparty curl https://www.lua.org/ftp/lua-5.2.4.tar.gz | tar xvz -C `dirname "$0"`/../thirdparty curl https://www.lua.org/ftp/lua-5.3.6.tar.gz | tar xvz -C `dirname "$0"`/../thirdparty -curl https://www.lua.org/ftp/lua-5.4.2.tar.gz | tar xvz -C `dirname "$0"`/../thirdparty +curl https://www.lua.org/ftp/lua-5.4.7.tar.gz | tar xvz -C `dirname "$0"`/../thirdparty +curl https://www.lua.org/ftp/lua-5.5.0.tar.gz | tar xvz -C `dirname "$0"`/../thirdparty diff --git a/scripts/setup.sh b/scripts/setup.sh index 044e1c2..f60f87c 100755 --- a/scripts/setup.sh +++ b/scripts/setup.sh @@ -4,4 +4,5 @@ `dirname "$0"`/build.sh lua-5.1.5 `dirname "$0"`/build.sh lua-5.2.4 `dirname "$0"`/build.sh lua-5.3.6 -`dirname "$0"`/build.sh lua-5.4.2 \ No newline at end of file +`dirname "$0"`/build.sh lua-5.4.7 +`dirname "$0"`/build.sh lua-5.5.0 \ No newline at end of file diff --git a/simple-test.ts b/simple-test.ts index 81cd743..fd540c0 100644 --- a/simple-test.ts +++ b/simple-test.ts @@ -5,6 +5,7 @@ import * as Lua51 from "./dist/lua.51"; import * as Lua52 from "./dist/lua.52"; import * as Lua53 from "./dist/lua.53"; import * as Lua54 from "./dist/lua.54"; +import * as Lua55 from "./dist/lua.55"; function simpleTest(luaBundle: {lua: Lua, lauxlib: LauxLib, lualib: LuaLib}) { const state = luaBundle.lauxlib.luaL_newstate(); @@ -15,4 +16,5 @@ simpleTest(Lua50); simpleTest(Lua51); simpleTest(Lua52); simpleTest(Lua53); -simpleTest(Lua54); \ No newline at end of file +simpleTest(Lua54); +simpleTest(Lua55); \ No newline at end of file diff --git a/src/binding-factory.ts b/src/binding-factory.ts index 59d22cb..4f4f3c1 100644 --- a/src/binding-factory.ts +++ b/src/binding-factory.ts @@ -201,6 +201,18 @@ const lauxBindings: Record = { } } }, + "<5.5.0": function(_luaGlue: LuaEmscriptenModule, _lua: Lua) { + return { + luaL_makeseed: function() { + throw "luaL_makeseed not supported before Lua 5.5"; + } + } + }, + ">=5.5.0": function(luaGlue: LuaEmscriptenModule, _lua: Lua) { + return { + luaL_makeseed: luaGlue.cwrap("luaL_makeseed", "number", []), + } + }, } /** @internal */ @@ -246,11 +258,20 @@ const luaLibBindings: Record = { } } }, - ">=5.1.0": function(luaGlue: LuaEmscriptenModule) { + ">=5.1.0 <5.5.0": function(luaGlue: LuaEmscriptenModule) { return { luaL_openlibs: luaGlue.cwrap("luaL_openlibs", null, ["number"]), } }, + ">=5.5.0": function(luaGlue: LuaEmscriptenModule) { + // In Lua 5.5, luaL_openlibs is a macro: #define luaL_openlibs(L) luaL_openselectedlibs(L, ~0, 0) + const openselectedlibs = luaGlue.cwrap("luaL_openselectedlibs", null, ["number", "number", "number"]); + return { + luaL_openlibs: function(L: LuaState) { + openselectedlibs(L, ~0, 0); + } + } + }, } /** @internal */ diff --git a/src/glue/glue-lua-5.4.2.d.ts b/src/glue/glue-lua-5.4.7.d.ts similarity index 100% rename from src/glue/glue-lua-5.4.2.d.ts rename to src/glue/glue-lua-5.4.7.d.ts diff --git a/src/glue/glue-lua-5.5.0.d.ts b/src/glue/glue-lua-5.5.0.d.ts new file mode 100644 index 0000000..90cf317 --- /dev/null +++ b/src/glue/glue-lua-5.5.0.d.ts @@ -0,0 +1,5 @@ +import type { EmscriptenModuleFactorySync, LuaEmscriptenModule } from "./glue"; + +declare const glue: EmscriptenModuleFactorySync; + +export default glue; diff --git a/src/lua.54.ts b/src/lua.54.ts index 5facd81..0ee360c 100644 --- a/src/lua.54.ts +++ b/src/lua.54.ts @@ -1,11 +1,11 @@ import { createLauxLib, createLua, createLuaLib } from "./binding-factory"; -import glue from "./glue/glue-lua-5.4.2"; +import glue from "./glue/glue-lua-5.4.7"; let luaGlue = glue({ print: console.log, printErr: console.error, }); -export const lua = createLua(luaGlue, "5.4.2"); -export const lauxlib = createLauxLib(luaGlue, lua, "5.4.2"); -export const lualib = createLuaLib(luaGlue, "5.4.2"); +export const lua = createLua(luaGlue, "5.4.7"); +export const lauxlib = createLauxLib(luaGlue, lua, "5.4.7"); +export const lualib = createLuaLib(luaGlue, "5.4.7"); diff --git a/src/lua.55.ts b/src/lua.55.ts new file mode 100644 index 0000000..2d50663 --- /dev/null +++ b/src/lua.55.ts @@ -0,0 +1,11 @@ +import { createLauxLib, createLua, createLuaLib } from "./binding-factory"; +import glue from "./glue/glue-lua-5.5.0"; + +let luaGlue = glue({ + print: console.log, + printErr: console.error, +}); + +export const lua = createLua(luaGlue, "5.5.0"); +export const lauxlib = createLauxLib(luaGlue, lua, "5.5.0"); +export const lualib = createLuaLib(luaGlue, "5.5.0"); diff --git a/src/lua.ts b/src/lua.ts index deb1f8f..bd0d366 100644 --- a/src/lua.ts +++ b/src/lua.ts @@ -66,5 +66,6 @@ export interface LauxLib { luaL_dostring(L: LuaState, s: string): number; luaL_loadbuffer(L: LuaState, s: string, slen: number, name: string): typeof LUA_OK | typeof LUA_ERRSYNTAX | typeof LUA_ERRMEM luaL_loadstring(L: LuaState, s: string): typeof LUA_OK | typeof LUA_ERRSYNTAX | typeof LUA_ERRMEM; + luaL_makeseed(): number; luaL_newstate(): LuaState; }