Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Support :await() in functions called from Javascript#135

Open
leso-kn wants to merge 1 commit into
ceifa:main from
leso-kn:await-in-js-callbacks
Open

Support :await() in functions called from Javascript #135
leso-kn wants to merge 1 commit into
ceifa:main from
leso-kn:await-in-js-callbacks

Conversation

@leso-kn

@leso-kn leso-kn commented May 24, 2025

Copy link
Copy Markdown

This PR removes the limitation of awaiting promises in Lua functions that are called from Javascript.

Effect
If a Lua function is called from Javascript, it will still return the value returned by the Lua function. However, if the Lua function attempts to yield at any point, a Promise is instead returned to Javascript which either resolves to the return value of the Lua function once it completes or catches if a Lua error occurs.

Technical Explanation
The limitation was solved by calling the function thread via lua_resume() instead of lua_pcallk() and then handing over the thread to Thread.run() (which enables the usage of await) in the case that the returned result is LuaReturn.Yield.

inventionpro and yuri-kiss reacted with thumbs up emoji
@leso-kn leso-kn force-pushed the await-in-js-callbacks branch from 54a4529 to d2fff00 Compare June 12, 2025 13:57

Copy link
Copy Markdown

Could this perhaps be merged sometime soon?

yuri-kiss reacted with thumbs up emoji leso-kn and PaperPrototype reacted with eyes emoji

Copy link
Copy Markdown

pls

@RodrigoDornelles RodrigoDornelles left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need unit tests to ensure that.

yuri-kiss reacted with eyes emoji

leso-kn commented Jan 6, 2026

Copy link
Copy Markdown
Author

@RodrigoDornelles Good call, unit tests added via 2b8eb50 :)

yuri-kiss reacted with hooray emoji yuri-kiss reacted with eyes emoji

Copy link
Copy Markdown

we absolutely need this

leso-kn commented Jan 12, 2026

Copy link
Copy Markdown
Author

@Drago-Cuven If you need a feature early npm offers the possibility to install packages from git branches:

The code review depends on the availability / free-time of the wasmoon maintainers.

# in your project
> npm i git+https://github.com/leso-kn/wasmoon#await-in-js-callbacks
# or
> git clone -b await-in-js-callbacks https://github.com/leso-kn/wasmoon
> cd wasmoon && npm i
> npm run build:wasm # or build:wasm:docker
# then, in your project
> npm i <path/to/cloned/wasmoon>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@RodrigoDornelles RodrigoDornelles Awaiting requested review from RodrigoDornelles

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /