Repository navigation
Conversation
nil reads as undefined wherever it comes from, so a JS default parameter applies to a nil argument and a Lua function that returns nothing gives the same value sync and async. null is only what the injected sentinel reads back as. Every entry point gives back the first result, and returns: 'all' asks for all of them as a LuaMultiReturn: doString, doFile, their Sync twins, state.async and state.call. state.call is now call(target, args, options): the synchronous counterpart of state.async, taking a global's name or a Lua function. It no longer leaves its results on the state's stack.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
One convention for the values that cross between Lua and JS. Breaking.
What changes
nilisundefined, everywhere. It used to read asnull, except where it did not: a Lua function that returned nothing gavenullwhen called directly andundefinedthroughstate.async.nullis now only what the injectednullsentinel reads back as, so withinjectthe two stay apart in both directions. Without it a JSnullstill becomesnil, and reads back asundefined.The first result by default,
returns: 'all'for every one of them.doString,doFile,doStringSync,doFileSync,state.asyncandstate.callall take it, and give back aLuaMultiReturn.state.call(target, args, options)replacescall(name, ...args). It is the synchronous counterpart ofstate.async: the target is a global's name or a Lua function, and the options are those of a run plusreturns.Migrating
value === nullon something read from Luavalue === undefinedstate.call('f', a, b)→LuaMultiReturnstate.call('f', [a, b], { returns: 'all' })thread.call(...)on a thread other than the statethread.runSync(argCount)The old variadic
callthrows aTypeErrorthat says how to write it, rather than misreading its arguments.Worth a look in review
callmoved fromThreadtoLuaState, since a function target needs the state's function extension.callnow runs underlimits.functionTimeoutandlimits.maxInstructions, likestate.asyncdoes. Before,call(name)honoured neither.callleft its results on the state's stack on every call; the new one rewinds. A test now holds it to that.thread.runandthread.runSyncstill give back every value on the stack. They are the stack level API, and the README says so.Verification
npm run lint:nofix,npm test(444 passing, 429 before) andnpm run luatestspass locally on a wasm built with emsdk 6.0.4. The new overloads were type checked from a consumer's side againstdist/index.d.ts. The benchmarks were not run.