package kernel; import cc.OS; import lua.Coroutine; import util.EventBus; using lua.Table; /** Class for interacting with the native pullEvent system. **/ class KernelEvents{ public static final instance:KernelEvents = new KernelEvents(); private function new () {} private var eventBus: util.EventBus> = new EventBus(); /** Start pulling events. Blocking. **/ public function startEventLoop() { // Log.info("Starting event loop"); while (true){ var event:Table = OS.pullEventRaw(); var eventName:String = event[1]; if (eventName == "terminate"){ return; } eventBus.emit(eventName,event.toArray()); } } public function on(eventName:String, callback:Array -> Void):EventBusListner> { return eventBus.on(eventName,callback); } public function once(eventName:String, callback:Array -> Void):EventBusListner> { return eventBus.once(eventName,callback); } public function removeListner(id:EventBusListner>) { return eventBus.removeListner(id); } }