lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


That's an option as well. I think I'm currently opinionated towards somehow putting the Lua thread to sleep, and since it doesn't seem like Lua supports that the way I want it to I'll probably just do it with OS threads pretending to be coroutines. Although it'll be slightly more complex to implement I think that's superseded by the increase in ease of use and intuitiveness it provides for the scripts.

On November 2, 2023 4:06:25 PM EDT, "Gé Weijers" <ge@weijers.org> wrote:
>
>The way I have designed my code is to add a non-blocking I/O class
>(userdata), which owns the file descriptor, and when you call the 'read'
>method you pass a callback function that is only called if no data is
>available (i.e. the operation would block). The function is called with the
>file descriptor and returns 'true' if the read should be retried, 'false'
>if you want the operation to fail. The code uses lua_callk to invoke the
>callback, it handles yields correctly, and yes, it's a bit painful to code
>this but it's definitely doable.
>
>The advantage of this approach is that it keeps the details of coroutine
>management completely outside of my C code, and I can use different
>strategies for different Lua programs.
>
>