Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

leso-kn
Copy link

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

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.

@leso-kn leso-kn force-pushed the await-in-js-callbacks branch from 54a4529 to d2fff00 Compare June 12, 2025 13:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant