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

My Attempt At A Routine Manager Api

Started by MudkipTheEpic, 09 September 2013 - 07:47 PM
MudkipTheEpic #1
Posted 09 September 2013 - 09:47 PM
My Attempt at a Routine Manager API


Hello. This is my attempt of making a routine manager API that is completely OO:


pastebin get un8xGz0b manager


Load it just like a regular API:


Docs:



os.loadAPI("manager")


Spoiler


--#Function parameter=something means the parameter is optional, and defaults to it.

--#Example:
--#foo(bar=foobar)

--#In foo, bar is optional and defaults to foobar


mgr=manager:new(main=function() pcall(loadfile("rom/programs/shell")) end,...)
--#Creates a new routine manager with the main function being main, and anything after it is main's args.

mgr:addCo(func,...)
--#Adds a routine to mgr as func called with the arguments supplied after it.

success=mgr:run(...=coroutine.yield())
--#OR 
success=mgr(...=coroutine.yield())
--#Runs one cycle of the manager with the args, if present, otherwise it pulls an event.

mgr:run_forever()

--#Runs the manager until mgr:run returns false
--#Almost equal to while mgr:run() do end

co=mgr["pool"][1]
--#OR (shorthand)
co=mgr[1]

co:resume(...)
--#If args are present, it adds that as an event to co's buffer. Either way, it pulls the first event from co's buffer to use.

co:passEvent(...)
--#Adds an event of the args to co's buffer.

co:kill()
--#Sets co's status to dead.

status=co.status
--#Get's co's status and sets status to it.

co.isPaused=bool
--#Sets if co is paused or not

--#End Of Docs



Example programs coming "soon!"


Please leave constructive critisism!
PixelToast #2
Posted 09 September 2013 - 10:34 PM
this is interesting, possibly make a github for it?
MudkipTheEpic #3
Posted 10 September 2013 - 05:57 PM
Great idea! I'll do it when I get home, on the way to get X-rays.