wasmoon icon indicating copy to clipboard operation
wasmoon copied to clipboard

Support `:await()` in functions called from Javascript

Open leso-kn opened this issue 10 months ago • 1 comments

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 avatar May 24 '25 17:05 leso-kn

Could this perhaps be merged sometime soon?

Succubyss avatar Nov 25 '25 19:11 Succubyss