Skip to content

Latest commit

 

History

History
55 lines (40 loc) · 1.4 KB

File metadata and controls

55 lines (40 loc) · 1.4 KB

OS

Restrictions:

YOU CANNOT USE EVENTS GLOBALLY.

You cannot yield the "main" coroutine, therefore os.pullevent() cannot just be set globally. Therefore You need to wrap everything you intent to run in the wrapper.

_Modules CANNOT yield outside of their fields

local TestModule = {}
-- ...
coroutine.yield() -- <- Breaks the EventManager, as the module cannot be wrapped
-- ...
return TestModule

How to use

for functions

-- import 
local osEmulator = require("ccOS")

-- create instance
local osInstance = osEmulator()

local testFunction = osInstance:wrap(function()
    os.pullEvent("CustomEvent")
    print("Event got called")
end)

testFunction() -- < Programm yields until event gets invoked, in the instances' thread
osInstance:invoke("CustomEvent") -- < Programm continues -> prints: "Event got called"

for Modules

local osEmulator = require("ccOS")
-- create instance
local osInstance = osEmulator()

local moduleFile = loadfile("pathToFile","t")
local testModule = osInstance:wrap(moduleFile, true, ...)
-- <true> tells the wrapper to wrap all functioncalls, so they run in a coroutine thread, instead of the callers thread
-- <...> as the module will need to be called once, you can provide additional parameters as need

testModule:someFunction(...)
-- the function will now run on the osInstance-Thread, knowing all currently implemented os-Functions