Skip to content

Lua 5.0.3 Bindings #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 28 commits into from
Apr 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
0c4fa5e
Initial attempt for 5.0
lolleko Apr 24, 2022
3aa661a
Bump emsdk version
lolleko Apr 24, 2022
a27304d
Bump emsdk 2.0
lolleko Apr 24, 2022
e0dbb03
Removed linker setting from compiler args
lolleko Apr 24, 2022
69f4f75
Fix removing WASM from linker args instead of compiler args
lolleko Apr 24, 2022
3e373d8
Rewrite of binding generation & 5.0 support
lolleko Apr 25, 2022
8d8297e
Removed empty array values
lolleko Apr 25, 2022
b06c032
Fixed some unexported functions
lolleko Apr 25, 2022
25cb950
More 5.0 compat
lolleko Apr 25, 2022
b2fde5a
Update build.sh
lolleko Apr 25, 2022
3383c47
More 5.0 compat
lolleko Apr 25, 2022
f9b7747
Update build.sh
lolleko Apr 25, 2022
0a8f7ab
Removed unused import
lolleko Apr 25, 2022
d8cebac
Link extra library for 5.0
lolleko Apr 25, 2022
f91cce9
Update README.md
lolleko Apr 25, 2022
e73b037
Added simple test
lolleko Apr 25, 2022
f6e5aad
Added missing suffix
lolleko Apr 25, 2022
1c0fc98
Check why build fails on CI
lolleko Apr 25, 2022
d198cac
Update simple-test.ts
lolleko Apr 25, 2022
a6c7403
Update binding-factory.ts
lolleko Apr 25, 2022
22ccc06
Fixed incorrect semver usage
lolleko Apr 25, 2022
e7fce2b
More semver fixes
lolleko Apr 25, 2022
38740bf
Moved some functions to correct versions
lolleko Apr 25, 2022
f008a0d
Fixed test and 5.0 file name
lolleko Apr 25, 2022
e66e5f9
Fix typo & commit unsaved file
lolleko Apr 25, 2022
b6b4198
Removed loadstring from 5.0 exports
lolleko Apr 25, 2022
ec62579
Remove luaL_openlibs from 5.0 exports
lolleko Apr 25, 2022
0b89cd6
Improve test
lolleko Apr 25, 2022
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
5 changes: 4 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,14 @@ jobs:
steps:
- uses: actions/checkout@v2
- name: Setup emsdk
uses: mymindstorm/setup-emsdk@v7
uses: mymindstorm/setup-emsdk@v11
with:
version: 3.1.9
- name: Use Node.js 12.13.1
uses: actions/setup-node@v1
with:
node-version: 12.13.1
registry-url: "https://registry.npmjs.org"
- run: npm ci
- run: npm run complete-build
- run: npm run test
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -178,3 +178,4 @@ dist

# End of https://www.toptal.com/developers/gitignore/api/node,c
.DS_Store
.vscode/settings.json
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
## Lua WASM Bindings

WASM bindings and binaries for Lua 5.1 to 5.4.
WASM bindings and binaries for Lua 5.0 to 5.4.

Make sure to run `./scripts/setup.ts` (requires emscripten sdk) first before using `npm run build`.
Make sure to run `./scripts/setup.sh` (requires emscripten sdk) first before using `npm run build`.

### Important: This currently only includes the bindings used to test TypescriptToLua

Expand Down
298 changes: 284 additions & 14 deletions package-lock.json

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"lint:prettier": "prettier --check . || (echo 'Run `npm run fix:prettier` to fix it.' && exit 1)",
"lint:eslint": "eslint . --ext .js,.ts",
"fix:prettier": "prettier --write .",
"test": "npx ts-node simple-test.ts",
"preversion": "npm run complete-build",
"postversion": "git push && git push --tags"
},
Expand All @@ -29,6 +30,11 @@
"eslint": "^7.21.0",
"eslint-plugin-import": "^2.22.1",
"prettier": "^2.2.1",
"ts-node": "^10.7.0",
"typescript": "^4.2.2"
},
"dependencies": {
"@types/semver": "^7.3.9",
"semver": "^7.3.7"
}
}
125 changes: 117 additions & 8 deletions scripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,56 @@ mkdir -p `dirname "$0"`/../dist/glue
cd `dirname "$0"`/../thirdparty/$1

make clean
make generic MYLIBS= MYCFLAGS= CC='emcc -O3 -s WASM=1' AR='emar rcu' RANLIB='emranlib'

if [[ "$1" == "lua-5.0.3" ]]; then
make all MYLIBS= MYCFLAGS= CC='emcc -O3' AR='emar rcu' RANLIB='emranlib'
else
make generic MYLIBS= MYCFLAGS= CC='emcc -O3' AR='emar rcu' RANLIB='emranlib'
fi

cd ../..

if [[ "$1" == "lua-5.1.5" ]]; then
# TODO write a proper script and clean up this mess

if [[ "$1" == "lua-5.0.3" ]]; then
emcc -Ithirdparty/$1 thirdparty/$1/lib/liblua.a thirdparty/$1/lib/liblualib.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_loadbuffer', \
'_lua_close', \
'_lua_gettable', \
'_lua_insert', \
'_lua_isstring', \
'_lua_open', \
'_lua_pcall', \
'_lua_pushstring', \
'_lua_pushvalue', \
'_lua_remove', \
'_lua_replace', \
'_lua_settable', \
'_lua_settop', \
'_lua_tostring', \
'_lua_type', \
'_lua_typename', \
'_luaopen_math', \
'_luaopen_string', \
'_luaopen_io', \
'_luaopen_table', \
'_luaopen_debug', \
'_luaopen_base' \
]"
elif [[ "$1" == "lua-5.1.5" ]]; then
emcc -Ithirdparty/$1 thirdparty/$1/src/liblua.a \
-s WASM=1 -O3 -o dist/glue/glue-$1.js \
-s EXTRA_EXPORTED_RUNTIME_METHODS="['cwrap']" \
-s EXPORTED_RUNTIME_METHODS="['cwrap']" \
-s MODULARIZE=1 \
-s ALLOW_TABLE_GROWTH \
-s EXPORT_NAME="glue" \
Expand All @@ -23,21 +65,36 @@ if [[ "$1" == "lua-5.1.5" ]]; then
-s WASM_ASYNC_COMPILATION=0 \
-s EXPORTED_FUNCTIONS="[
'_luaL_newstate', \
'_lua_close', \
'_luaL_openlibs', \
'_luaL_loadbuffer', \
'_luaL_loadstring', \
'_lua_close', \
'_lua_getfield', \
'_lua_gettable', \
'_lua_insert', \
'_lua_isstring', \
'_lua_pcall', \
'_lua_pushstring', \
'_lua_pushvalue', \
'_lua_remove', \
'_lua_replace', \
'_lua_setfield', \
'_lua_settable', \
'_lua_settop', \
'_lua_tolstring', \
'_lua_type', \
'_lua_typename' \
'_lua_typename', \
'_luaopen_math', \
'_luaopen_string', \
'_luaopen_io', \
'_luaopen_table', \
'_luaopen_debug', \
'_luaopen_base' \
]"
else
elif [[ "$1" == "lua-5.2.4" ]]; then
emcc -Ithirdparty/$1 thirdparty/$1/src/liblua.a \
-s WASM=1 -O3 -o dist/glue/glue-$1.js \
-s EXTRA_EXPORTED_RUNTIME_METHODS="['cwrap']" \
-s EXPORTED_RUNTIME_METHODS="['cwrap']" \
-s MODULARIZE=1 \
-s ALLOW_TABLE_GROWTH \
-s EXPORT_NAME="glue" \
Expand All @@ -47,16 +104,68 @@ else
-s WASM_ASYNC_COMPILATION=0 \
-s EXPORTED_FUNCTIONS="[
'_luaL_newstate', \
'_luaL_openlibs', \
'_luaL_loadstring', \
'_lua_close', \
'_lua_getfield', \
'_lua_getglobal', \
'_lua_gettable', \
'_lua_insert', \
'_lua_isstring', \
'_lua_pcallk', \
'_lua_pushstring', \
'_lua_pushvalue', \
'_lua_remove', \
'_lua_replace', \
'_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 \
-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_openlibs', \
'_luaL_loadstring', \
'_lua_close', \
'_lua_copy', \
'_lua_getfield', \
'_lua_getglobal', \
'_lua_gettable', \
'_lua_isstring', \
'_lua_pcallk', \
'_lua_pushstring', \
'_lua_pushvalue', \
'_lua_rotate', \
'_lua_setfield', \
'_lua_settable', \
'_lua_settop', \
'_lua_tolstring', \
'_lua_type', \
'_lua_typename' \
'_lua_typename', \
'_luaopen_math', \
'_luaopen_string', \
'_luaopen_io', \
'_luaopen_table', \
'_luaopen_debug', \
'_luaopen_base' \
]"
fi
4 changes: 3 additions & 1 deletion scripts/download.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
mkdir -p `dirname "$0"`/../thirdparty

curl https://www.lua.org/ftp/lua-5.0.3.tar.gz | tar xvz -C `dirname "$0"`/../thirdparty
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.2.tar.gz | tar xvz -C `dirname "$0"`/../thirdparty

1 change: 1 addition & 0 deletions scripts/setup.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
`dirname "$0"`/download.sh

`dirname "$0"`/build.sh lua-5.0.3
`dirname "$0"`/build.sh lua-5.1.5
`dirname "$0"`/build.sh lua-5.2.4
`dirname "$0"`/build.sh lua-5.3.6
Expand Down
18 changes: 18 additions & 0 deletions simple-test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { LauxLib, Lua, LuaLib } from "./dist/lua";

import * as Lua50 from "./dist/lua.50";
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";

function simpleTest(luaBundle: {lua: Lua, lauxlib: LauxLib, lualib: LuaLib}) {
const state = luaBundle.lauxlib.luaL_newstate();
luaBundle.lualib.luaL_openlibs(state);
}

simpleTest(Lua50);
simpleTest(Lua51);
simpleTest(Lua52);
simpleTest(Lua53);
simpleTest(Lua54);
Loading