⚠ This page is served via a proxy. Original site: https://github.com
This service does not collect credentials or authentication data.
Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions scripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
3 changes: 2 additions & 1 deletion scripts/download.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

3 changes: 2 additions & 1 deletion scripts/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
`dirname "$0"`/build.sh lua-5.4.7
`dirname "$0"`/build.sh lua-5.5.0
4 changes: 3 additions & 1 deletion simple-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -15,4 +16,5 @@ simpleTest(Lua50);
simpleTest(Lua51);
simpleTest(Lua52);
simpleTest(Lua53);
simpleTest(Lua54);
simpleTest(Lua54);
simpleTest(Lua55);
23 changes: 22 additions & 1 deletion src/binding-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,18 @@ const lauxBindings: Record<string, lauxBindingFactoryFunc> = {
}
}
},
"<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 */
Expand Down Expand Up @@ -246,11 +258,20 @@ const luaLibBindings: Record<string, luaLibBindingFactoryFunc> = {
}
}
},
">=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 */
Expand Down
File renamed without changes.
5 changes: 5 additions & 0 deletions src/glue/glue-lua-5.5.0.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import type { EmscriptenModuleFactorySync, LuaEmscriptenModule } from "./glue";

declare const glue: EmscriptenModuleFactorySync<LuaEmscriptenModule>;

export default glue;
8 changes: 4 additions & 4 deletions src/lua.54.ts
Original file line number Diff line number Diff line change
@@ -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");
11 changes: 11 additions & 0 deletions src/lua.55.ts
Original file line number Diff line number Diff line change
@@ -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");
1 change: 1 addition & 0 deletions src/lua.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}