package kernel; import cc.OS; import util.EventBus; using lua.Table; /** Class for interacting with the native pullEvent system. **/ class KernelEvents{ public static var instance:KernelEvents; @:allow(kernel.Init) 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); } }