Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local events={
- }
- function addEvent(name)
- if events[name]==nil then
- events[name]={
- }
- else
- return false,"This event already exists."
- end
- end
- function addEventHandler(event,func)
- if events[event]==nil then
- events[event]={
- }
- -- return true,"Event did not yet exist, event was added"
- end
- events[event][#events[event]+1]={
- ["func"]=func,
- }
- end
- function removeEventHandler(event,func)
- if events[event]==nil then
- return false,"There is no such event"
- end
- for id,data in pairs(events[event]) do
- if data.func==func then
- events[event][id]=nil
- return true,"Event handler succesfully removed"
- end
- end
- return false,("No handlers for that function")
- end
- function removeEvent(event)
- if events[event]==nil then
- return false,"No such event exists."
- end
- events[evenf]=nil
- return true,"Event (and it's handlers) succesfully removed"
- end
- function triggerEvent(event, ... )
- if events[event]==nil then
- return false,"No such event exists"
- end
- for id, data in pairs(events[event]) do
- data.func(...)
- end
- end
- local computerCraft={
- "char","key","key_up","paste","timer","alarm","task_complete","redstone","terminate","disk","disk_eject","peripheral","peripheral_detach","rednet_message","modem_message","http_success","http_failure","mouse_click","mouse_up","mouse_scroll","mouse_drag","monitor_touch","monitor_resize","term_resize","turtle_inventory"
- }
- function setupComputercraftEvents()
- for _,event in ipairs(computerCraft) do
- addEvent(event)
- end
- end
- function handleCCEvents()
- local event,a1,a2,a3,a4,a5=os.pullEvent()
- triggerEvent(event,a1,a2,a3,a4,a5)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement