This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Cyclonit's profile picture

CycloProcess

Started by Cyclonit, 13 December 2012 - 05:36 AM
Cyclonit #1
Posted 13 December 2012 - 06:36 AM
Hi,

This small API adds process-like coroutines, which will be managed by a central run() function. Every process is required to have a main function, expecting the process' table as parameter. The table will contain the PID, name and several functions (queueEvent, …) which add the actual process-like behaviour.

Events are devided into global events and private events. Whilst global events will be received by every process, private events will only be send to the respective process. The process' queueEvent(…) function creates a private event and will thus not interfere with other processes.

To allow interaction inbetween different processes, processes may send events to other processes. They therefor have access to the process-table and may call another process' queueEvent function.

Attention: This API has not been tested a lot and can be considered a EARLY beta. When everything works fine, I'll start adding new features (pausing, …).

If you find any bugs or have any ideas/suggestions please let me know! =)

Download


Example Programs:
I strongly suggest to take a look in this two little program. It shows how parallel
processing of two functions is done.
ParallelTest


Functions:
registerListener(event, func)
Registers a listener for the specified event. The listener will be called everytime the event is triggered and receive the event's parameters.

removeListener(event, listener)
Removes a listener from the specified event.

setEventFilter(pid, events)
Sets the process' event filter to the given table. Processes wont receive events, which are not mentioned in the filter, if a filter is set.

createProcess(name, func)
Creates a new process. The used function will be called once using the process' table for it being able to identify itself.

getProcesses()
Returns the process table.

run()
Manages the event queue and will call processes/listeners when a respective event occured.


Changelog:

12.12.2012
First Beta Release: v0.1
I have yet to thoroughly test the API and will try to further optimize the
code.
anonimo182 #2
Posted 13 December 2012 - 03:47 PM
This is a very nice/good API, imagine the possibilities that open with this!