Skip to content

Commit 17f61c9

Browse files
authored
Lua 5.0.3 Bindings (#2)
* Initial attempt for 5.0 See if this fails on CI as well (local build does) * Bump emsdk version * Bump emsdk 2.0 * Removed linker setting from compiler args * Fix removing WASM from linker args instead of compiler args * Rewrite of binding generation & 5.0 support * Removed empty array values * Fixed some unexported functions * More 5.0 compat * Update build.sh * More 5.0 compat * Update build.sh * Removed unused import * Link extra library for 5.0 * Update README.md * Added simple test to check if all functions that are needed are exported correctly * Added missing suffix * Check why build fails on CI * Update simple-test.ts * Update binding-factory.ts * Fixed incorrect semver usage * More semver fixes * Moved some functions to correct versions * Fixed test and 5.0 file name * Fix typo & commit unsaved file * Removed loadstring from 5.0 exports It doesn't exist and we already have a polyfill * Remove luaL_openlibs from 5.0 exports * Improve test
1 parent 79cfb6f commit 17f61c9

18 files changed

+728
-110
lines changed

.github/workflows/ci.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,14 @@ jobs:
1313
steps:
1414
- uses: actions/checkout@v2
1515
- name: Setup emsdk
16-
uses: mymindstorm/setup-emsdk@v7
16+
uses: mymindstorm/setup-emsdk@v11
17+
with:
18+
version: 3.1.9
1719
- name: Use Node.js 12.13.1
1820
uses: actions/setup-node@v1
1921
with:
2022
node-version: 12.13.1
2123
registry-url: "https://registry.npmjs.org"
2224
- run: npm ci
2325
- run: npm run complete-build
26+
- run: npm run test

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,3 +178,4 @@ dist
178178

179179
# End of https://www.toptal.com/developers/gitignore/api/node,c
180180
.DS_Store
181+
.vscode/settings.json

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
## Lua WASM Bindings
22

3-
WASM bindings and binaries for Lua 5.1 to 5.4.
3+
WASM bindings and binaries for Lua 5.0 to 5.4.
44

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

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

package-lock.json

Lines changed: 284 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"lint:prettier": "prettier --check . || (echo 'Run `npm run fix:prettier` to fix it.' && exit 1)",
1717
"lint:eslint": "eslint . --ext .js,.ts",
1818
"fix:prettier": "prettier --write .",
19+
"test": "npx ts-node simple-test.ts",
1920
"preversion": "npm run complete-build",
2021
"postversion": "git push && git push --tags"
2122
},
@@ -29,6 +30,11 @@
2930
"eslint": "^7.21.0",
3031
"eslint-plugin-import": "^2.22.1",
3132
"prettier": "^2.2.1",
33+
"ts-node": "^10.7.0",
3234
"typescript": "^4.2.2"
35+
},
36+
"dependencies": {
37+
"@types/semver": "^7.3.9",
38+
"semver": "^7.3.7"
3339
}
3440
}

scripts/build.sh

Lines changed: 117 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,56 @@ mkdir -p `dirname "$0"`/../dist/glue
66
cd `dirname "$0"`/../thirdparty/$1
77

88
make clean
9-
make generic MYLIBS= MYCFLAGS= CC='emcc -O3 -s WASM=1' AR='emar rcu' RANLIB='emranlib'
9+
10+
if [[ "$1" == "lua-5.0.3" ]]; then
11+
make all MYLIBS= MYCFLAGS= CC='emcc -O3' AR='emar rcu' RANLIB='emranlib'
12+
else
13+
make generic MYLIBS= MYCFLAGS= CC='emcc -O3' AR='emar rcu' RANLIB='emranlib'
14+
fi
1015

1116
cd ../..
1217

13-
if [[ "$1" == "lua-5.1.5" ]]; then
18+
# TODO write a proper script and clean up this mess
19+
20+
if [[ "$1" == "lua-5.0.3" ]]; then
21+
emcc -Ithirdparty/$1 thirdparty/$1/lib/liblua.a thirdparty/$1/lib/liblualib.a \
22+
-s WASM=1 -O3 -o dist/glue/glue-$1.js \
23+
-s EXPORTED_RUNTIME_METHODS="['cwrap']" \
24+
-s MODULARIZE=1 \
25+
-s ALLOW_TABLE_GROWTH \
26+
-s EXPORT_NAME="glue" \
27+
-s ALLOW_MEMORY_GROWTH=1 \
28+
-s STRICT=1 \
29+
-s MALLOC=emmalloc \
30+
-s WASM_ASYNC_COMPILATION=0 \
31+
-s EXPORTED_FUNCTIONS="[
32+
'_luaL_loadbuffer', \
33+
'_lua_close', \
34+
'_lua_gettable', \
35+
'_lua_insert', \
36+
'_lua_isstring', \
37+
'_lua_open', \
38+
'_lua_pcall', \
39+
'_lua_pushstring', \
40+
'_lua_pushvalue', \
41+
'_lua_remove', \
42+
'_lua_replace', \
43+
'_lua_settable', \
44+
'_lua_settop', \
45+
'_lua_tostring', \
46+
'_lua_type', \
47+
'_lua_typename', \
48+
'_luaopen_math', \
49+
'_luaopen_string', \
50+
'_luaopen_io', \
51+
'_luaopen_table', \
52+
'_luaopen_debug', \
53+
'_luaopen_base' \
54+
]"
55+
elif [[ "$1" == "lua-5.1.5" ]]; then
1456
emcc -Ithirdparty/$1 thirdparty/$1/src/liblua.a \
1557
-s WASM=1 -O3 -o dist/glue/glue-$1.js \
16-
-s EXTRA_EXPORTED_RUNTIME_METHODS="['cwrap']" \
58+
-s EXPORTED_RUNTIME_METHODS="['cwrap']" \
1759
-s MODULARIZE=1 \
1860
-s ALLOW_TABLE_GROWTH \
1961
-s EXPORT_NAME="glue" \
@@ -23,21 +65,36 @@ if [[ "$1" == "lua-5.1.5" ]]; then
2365
-s WASM_ASYNC_COMPILATION=0 \
2466
-s EXPORTED_FUNCTIONS="[
2567
'_luaL_newstate', \
26-
'_lua_close', \
2768
'_luaL_openlibs', \
69+
'_luaL_loadbuffer', \
2870
'_luaL_loadstring', \
71+
'_lua_close', \
2972
'_lua_getfield', \
73+
'_lua_gettable', \
74+
'_lua_insert', \
3075
'_lua_isstring', \
3176
'_lua_pcall', \
77+
'_lua_pushstring', \
78+
'_lua_pushvalue', \
79+
'_lua_remove', \
80+
'_lua_replace', \
3281
'_lua_setfield', \
82+
'_lua_settable', \
83+
'_lua_settop', \
3384
'_lua_tolstring', \
3485
'_lua_type', \
35-
'_lua_typename' \
86+
'_lua_typename', \
87+
'_luaopen_math', \
88+
'_luaopen_string', \
89+
'_luaopen_io', \
90+
'_luaopen_table', \
91+
'_luaopen_debug', \
92+
'_luaopen_base' \
3693
]"
37-
else
94+
elif [[ "$1" == "lua-5.2.4" ]]; then
3895
emcc -Ithirdparty/$1 thirdparty/$1/src/liblua.a \
3996
-s WASM=1 -O3 -o dist/glue/glue-$1.js \
40-
-s EXTRA_EXPORTED_RUNTIME_METHODS="['cwrap']" \
97+
-s EXPORTED_RUNTIME_METHODS="['cwrap']" \
4198
-s MODULARIZE=1 \
4299
-s ALLOW_TABLE_GROWTH \
43100
-s EXPORT_NAME="glue" \
@@ -47,16 +104,68 @@ else
47104
-s WASM_ASYNC_COMPILATION=0 \
48105
-s EXPORTED_FUNCTIONS="[
49106
'_luaL_newstate', \
107+
'_luaL_openlibs', \
108+
'_luaL_loadstring', \
50109
'_lua_close', \
110+
'_lua_getfield', \
111+
'_lua_getglobal', \
112+
'_lua_gettable', \
113+
'_lua_insert', \
114+
'_lua_isstring', \
115+
'_lua_pcallk', \
116+
'_lua_pushstring', \
117+
'_lua_pushvalue', \
118+
'_lua_remove', \
119+
'_lua_replace', \
120+
'_lua_setfield', \
121+
'_lua_settable', \
122+
'_lua_settop', \
123+
'_lua_tolstring', \
124+
'_lua_type', \
125+
'_lua_typename', \
126+
'_luaopen_math', \
127+
'_luaopen_string', \
128+
'_luaopen_io', \
129+
'_luaopen_table', \
130+
'_luaopen_debug', \
131+
'_luaopen_base' \
132+
]"
133+
else
134+
emcc -Ithirdparty/$1 thirdparty/$1/src/liblua.a \
135+
-s WASM=1 -O3 -o dist/glue/glue-$1.js \
136+
-s EXPORTED_RUNTIME_METHODS="['cwrap']" \
137+
-s MODULARIZE=1 \
138+
-s ALLOW_TABLE_GROWTH \
139+
-s EXPORT_NAME="glue" \
140+
-s ALLOW_MEMORY_GROWTH=1 \
141+
-s STRICT=1 \
142+
-s MALLOC=emmalloc \
143+
-s WASM_ASYNC_COMPILATION=0 \
144+
-s EXPORTED_FUNCTIONS="[
145+
'_luaL_newstate', \
51146
'_luaL_openlibs', \
52147
'_luaL_loadstring', \
148+
'_lua_close', \
149+
'_lua_copy', \
53150
'_lua_getfield', \
54151
'_lua_getglobal', \
152+
'_lua_gettable', \
55153
'_lua_isstring', \
56154
'_lua_pcallk', \
155+
'_lua_pushstring', \
156+
'_lua_pushvalue', \
157+
'_lua_rotate', \
57158
'_lua_setfield', \
159+
'_lua_settable', \
160+
'_lua_settop', \
58161
'_lua_tolstring', \
59162
'_lua_type', \
60-
'_lua_typename' \
163+
'_lua_typename', \
164+
'_luaopen_math', \
165+
'_luaopen_string', \
166+
'_luaopen_io', \
167+
'_luaopen_table', \
168+
'_luaopen_debug', \
169+
'_luaopen_base' \
61170
]"
62171
fi

scripts/download.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
mkdir -p `dirname "$0"`/../thirdparty
22

3+
curl https://www.lua.org/ftp/lua-5.0.3.tar.gz | tar xvz -C `dirname "$0"`/../thirdparty
34
curl https://www.lua.org/ftp/lua-5.1.5.tar.gz | tar xvz -C `dirname "$0"`/../thirdparty
45
curl https://www.lua.org/ftp/lua-5.2.4.tar.gz | tar xvz -C `dirname "$0"`/../thirdparty
56
curl https://www.lua.org/ftp/lua-5.3.6.tar.gz | tar xvz -C `dirname "$0"`/../thirdparty
6-
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.2.tar.gz | tar xvz -C `dirname "$0"`/../thirdparty
8+

scripts/setup.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
`dirname "$0"`/download.sh
22

3+
`dirname "$0"`/build.sh lua-5.0.3
34
`dirname "$0"`/build.sh lua-5.1.5
45
`dirname "$0"`/build.sh lua-5.2.4
56
`dirname "$0"`/build.sh lua-5.3.6

simple-test.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { LauxLib, Lua, LuaLib } from "./dist/lua";
2+
3+
import * as Lua50 from "./dist/lua.50";
4+
import * as Lua51 from "./dist/lua.51";
5+
import * as Lua52 from "./dist/lua.52";
6+
import * as Lua53 from "./dist/lua.53";
7+
import * as Lua54 from "./dist/lua.54";
8+
9+
function simpleTest(luaBundle: {lua: Lua, lauxlib: LauxLib, lualib: LuaLib}) {
10+
const state = luaBundle.lauxlib.luaL_newstate();
11+
luaBundle.lualib.luaL_openlibs(state);
12+
}
13+
14+
simpleTest(Lua50);
15+
simpleTest(Lua51);
16+
simpleTest(Lua52);
17+
simpleTest(Lua53);
18+
simpleTest(Lua54);

0 commit comments

Comments
 (0)