Skip to content

wasmoon 2.0 - #131

Open
ceifa wants to merge 91 commits into
mainfrom
new-apis-2
Open

ceifa wants to merge 91 commits into
mainfrom
new-apis-2

Conversation

@ceifa

@ceifa ceifa commented Jan 18, 2025 •

Copy link
Copy Markdown
Owner

Fixes #21 #83 #127 #149 #148 #143 #134
Tried to fix #61, but emscripten have a very limited support for deno

@ceifa ceifa changed the title Change public API and improve CLI to be more close to the original Lua CLI wasmoon 2.0 Feb 18, 2025
@yuri-kiss

Copy link
Copy Markdown

is there any reason this hasn't recieved any attention

@Drago-Cuven

Copy link
Copy Markdown

should def be merged.

ceifa and others added 30 commits September 5, 2026 16:10
Quality cleanups from review, no behavior change:
- collapse awaitInterruptible into settleOrInterrupt
- share one settled-value marshaller (Thread.pushReturnValues; marshalResolved/marshalRejected)
- centralize the abort/timeout classification in async.limitError
- remove the syncDepth field, derivable from stackCanSuspend via one withSuspensionDisabled helper
- extract the shared per-yield handling (throwIfLimitReached, handleHostYield) from the two run loops
- drop the dead await-hook L parameter and inline the single-use heap-slice wrappers

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012hBeqdFnHzBUQ7zLRVYQxx
Snapshot of the working tree at /home/ceifa/Projects/wasmoon, on top of 55c7d96, pushed
as-is for review. Not built or tested as part of this commit.
JSPI is now the only way an :await() suspends; the coroutine yielding engine and the
`async` load option are gone. On a platform without JSPI everything else still runs and
an :await() raises an error naming the versions that have it.

- fix the C stack pointer leak: a run started inside another run's JS callback that
  outlived it left the idle stack pointer lower for good, and after ~100 of those the
  instance trapped with "memory access out of bounds"
- a Lua function called from JS is always synchronous; state.callAsync(fn, args, options)
  runs it as a run of its own, and promise next/catch/finally call their Lua reactions
  through it
- a top level coroutine.yield() without an onYield handler gives the event loop a turn
  every time again
- engines: node >= 26; CI runs Node 26 without the JSPI flag or the engine matrix
With `inject`, `async(fn)` returns a function that runs `fn` as a run of its own and
hands back a promise of its first result: what `async function` is to JS. A callback
wrapped in it can await when a JS API calls it synchronously, which a bare Lua function
cannot now that calls from JS are always synchronous.

The wrapper is a Lua closure over `fn`, compiled on first use, and the arguments of a
call move between Lua stacks without becoming JS values.
- state.async(fn, options) replaces callAsync: it returns the asynchronous counterpart
  of a Lua function, the mirror of async(fn) in Lua, ready to hand to whatever takes a
  callback
- inject takes the names to define (['Promise', 'async']), so async and Promise no
  longer come with the null sentinel
- asynchronous runs of a function start under the same limits as a doString, the
  state's instruction budget included, with the function timeout on top
- LuaRuntime.canAwait tells whether the platform can await, before loading anything
- onAsyncError receives the error of an async(fn) call nothing was waiting on, which
  is otherwise an unhandled rejection
- a function that returns nothing or nil resolves to undefined, as a run does, and the
  await error names async(fn) and state.async(fn)
utils/create-bindings.js now writes src/bindings.gen.ts and the emcc export list instead of printing blocks to paste, and build:wasm runs it. LuaModule extends the generated class, so each binding is declared once instead of in three hand-kept lists.

No change to the bindings, their types or the wasm: the generated declarations match the hand-written ones, and glue.wasm and both glues come out byte for byte the same.
copy/proxy/opaque/raw replace decorate, defineType and defineClass replace
registerTypeExtension and its priorities, and a function is no longer
guessed to be a class. LuaLimits (timeout, maxInstructions, signal) is the
one shape for state.limits and for a run's options, and applies to every
run, including a call of a Lua function and one made from inside another.
declarative marshalling, one limits vocabulary
chai 6.3.0, mocha 12.0.3, oxfmt 0.79.0, oxlint 1.94.0, playwright 1.65.1, rolldown 1.3.3, tslib 2.9.1 and @types/node 26.6.6 in the lockfile, plus npm audit fix for the transitive brace-expansion and serialize-javascript.
FS.filesystems is gone, so mounts reach NODEFS through the module instead, which the build now
exports. FS.analyzePath is gone under STRICT, so exists() does the same lookup itself.

The glue no longer declares EmscriptenEH, which the unwind brand plugin patched. It was never
thrown in 6.0.4 either, only declared: with SUPPORT_LONGJMP=wasm every unwind is a
WebAssembly.Exception, so the brand never did anything and goes with the plugin.

The docker fallback of build:wasm ran the untagged emsdk image and is pinned to the version CI
installs, so a local build makes the glue CI tests.

The glue drops from 86.8 to 79 KB.
It was on a commit between releases. CI now checks the submodule sits on a release tag of
lua/lua, so it cannot drift back to one.
Update dependencies, Emscripten 7.0.0 and Lua 5.5.1
The generated constructor spelled out this.exported( 147 times and this.wrapWithStringArguments( 37 times, and a minifier has to leave a method name alone. Two locals in the constructor take their place, so the named stores stay as they were and dist/index.js goes from 113.4 kB to 110.7 kB.

The README size table was stale (108 + 194) and now carries the measured numbers.
Shorten the generated bindings in the bundle
Add fs: 'none', load each glue on demand and fetch the wasm alongside it
Fall back to jsDelivr and check the wasm against this build's hash
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

5 participants