-
-
Notifications
You must be signed in to change notification settings - Fork 496
Description
Is your feature request related to a problem? Please describe.
While Lua is fast we are still bound to limitations that can make it hard to do some expensive calculations for things like path finding or dealing with running a SCM virtual machine (Sphene). It would be much nicer if this code could be moved into a separate thread and therefore prevent freezes.
Lua itself doesn't support multi-threading but is has been shown here that there is definitely a way to do so.
Describe the solution you'd like
I'd like for new functions to be exposed that allow for a thread to be created and for data to be transmitted between them. In line with the example of LÖVE I propose the following functions to be added at least:
- createThread(filePath) ( OOP: Thread(filePath) )
Creates a new thread and returns the newly created thread.
Parameters:- file: Path to a file to be ran in the thread or a string containing Lua code.
- killThread(thread) ( OOP: thread:kill() )
Terminates a thread forcefully, ending its execution.
Parameters:- thread: The thread to be terminated.
- startThread(thread) ( OOP: thread:start() )
Starts the thread.
Parameters:- thread: The thread to be started.
- isThreadRunning(thread) ( OOP: thread:isRunning() )
Returns true if the thread is running and false if not.
Parameters:- thread: The thread to be checked.
- sendThreadMessage(thread, value) ( OOP: thread:sendMessage(value) )
Sends a message to the thread.
Parameters:- thread: The thread to send the message to.
- value: The value to send to the thread.
- receiveThreadMessage() ( OOP: Thread.receiveMessage() )
Receives a message from the message queue for the thread in which this is executed. Although this could also be a event (perhaps both?). Returns the thread that has sends the message and the value of that message. - getThreadMessageCount() ( OOP: Thread.getMessageCount() )
Returns the amount of messages in the message queue for the thread in which this is executed.
Please note that this is an initial thought and that this API should be heavily discussed and adjusted where possible.
Describe alternatives you've considered
Using coroutines but you can only run one at once so it can slow down execution even more if improperly used. Coroutines work better for things like task scheduling.