- Open this repo in devcontainer, e.g. using Github Codespaces. Type or copy/paste following commands to devcontainer's terminal.
As of erdian718/lua (aka ofunc/lua) received no updates since Jul 2019,
it can not be compiled by recent versions of Golang compiler due to enforcement of module mode (say GO111MODULE=on
).
So let's build that Lua from sources, applying necessary patches:
- Clone erdian718/lua's repo to get sources:
git clone --depth=1 https://github.com/erdian718/lua.git
cd
into the folder of erdian718/lua's sources:
cd lua
- Obtain erdian718/lmodhttpclient's sources by cloning its repo next to built-in Lua modules:
git clone --depth=1 https://github.com/erdian718/lmodhttpclient.git
- Init Golang module:
go mod init github.com/ofunc/lua
- Patch sources to be compatible with module mod by running a Sed command:
grep -rl '"ofunc/lua' * | xargs sed -i.bak 's|"ofunc/lua|"github.com/ofunc/lua|g'
- Additionally patch lmodjs's sources by running a Sed command:
sed -i.bak 's@if x := v.Get(LuaKey); x != undefined && x != null {@if x := v.Get(LuaKey); !(x.IsUndefined() || x.IsNull()) {@' lmodjs/mod.go
-
Ensure that your shell terminal is still in
lua
folder after completing all preparation steps. -
Install lmodhttpclient's dependency library
publicsuffix
:
go get golang.org/x/net/publicsuffix
- Make a folder for WASM module, copy there the sources of this example, and
cd
into it:
mkdir main
cd main
cp ../../browser-lmodhttpclient/main.go ./
cp ../../browser-lmodhttpclient/index.html ./
- Compile the example:
GOOS=js GOARCH=wasm go build -o main.wasm main.go
- Copy the glue JS from Golang distribution to example's folder:
cp "$(go env GOROOT)/misc/wasm/wasm_exec.js" .
- Run simple HTTP server to temporarily publish project to Web:
python3 -m http.server
Codespace will show you "Open in Browser" button. Just click that button or obtain web address from "Forwarded Ports" tab.
- As
index.html
and a 10M-sizedmain.wasm
are loaded into browser, refer to browser developer console to see the results.
Perform your own experiments if desired.