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!