mlua icon indicating copy to clipboard operation
mlua copied to clipboard

Implement LuaThread::close()

Open radiantgurl opened this issue 11 months ago • 6 comments

Implementation of a close function, marking a thread as finalized.

radiantgurl avatar Jan 23 '25 20:01 radiantgurl

There is Thread::reset with does exactly the same.

khvzak avatar Jan 24 '25 15:01 khvzak

There is Thread::reset with does exactly the same.

It requires a function, which we don't have.

This new function, close is meant to mimic coroutine.close, marking it as finished.

Im assuming Thread::reset marks it as resumable again right?

radiantgurl avatar Jan 24 '25 15:01 radiantgurl

is meant to mimic coroutine.close, marking it as finished.

I don't think it's mlua goal to replicate functionality of Lua standard library.

The idea behind Thread::reset is to provide support of re-using an existing coroutine without creating a new one. And it's used in mlua async implementation to keep a pool of "async" coroutines to avoid extra GC collections and allocations for temporary objects.

khvzak avatar Jan 24 '25 16:01 khvzak

I don't think it's mlua goal to replicate functionality of Lua standard library. I'm currently attempting to use .close() to make sure a thread cannot be resumed again, and that .status() returns Finished

radiantgurl avatar Jan 24 '25 18:01 radiantgurl

Implementation of a close function, marking a thread as finalized.

I actually just came across this limitation when trying to implement Roblox’s task.close in pure rust+mlua. Currently worked around using lua.globals() and getting coroutine.close and then calling it with the thread as argument but it’s a workaround

cheesycod avatar Jun 08 '25 17:06 cheesycod

Implementation of a close function, marking a thread as finalized.

I actually just came across this limitation when trying to implement Roblox’s task.close in pure rust+mlua. Currently worked around using lua.globals() and getting coroutine.close and then calling it with the thread as argument but it’s a workaround

It's currently being used in my own project, here's my implementation of it: https://github.com/rblx-godot/rblx-godot/blob/9222b4e0c0890c34e916180b1933a6564c917c84/src/core/scheduler.rs#L381

radiantgurl avatar Jun 09 '25 14:06 radiantgurl