Event.lua 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. class "Event"
  2. COMPLETE_EVENT = 0
  3. CHANGE_EVENT = 1
  4. function Event:Event(...)
  5. for k,v in pairs(arg) do
  6. if type(v) == "table" then
  7. if v.__ptr ~= nil then
  8. arg[k] = v.__ptr
  9. end
  10. end
  11. end
  12. if self.__ptr == nil and arg[1] ~= "__skip_ptr__" then
  13. self.__ptr = Polycore.Event(unpack(arg))
  14. Polycore.__ptr_lookup[self.__ptr] = self
  15. end
  16. end
  17. function Event:getEventCode()
  18. local retVal = Polycore.Event_getEventCode(self.__ptr)
  19. return retVal
  20. end
  21. function Event:getDispatcher()
  22. local retVal = Polycore.Event_getDispatcher(self.__ptr)
  23. if retVal == nil then return nil end
  24. if Polycore.__ptr_lookup[retVal] ~= nil then
  25. return Polycore.__ptr_lookup[retVal]
  26. else
  27. Polycore.__ptr_lookup[retVal] = EventDispatcher("__skip_ptr__")
  28. Polycore.__ptr_lookup[retVal].__ptr = retVal
  29. return Polycore.__ptr_lookup[retVal]
  30. end
  31. end
  32. function Event:setEventCode(eventCode)
  33. local retVal = Polycore.Event_setEventCode(self.__ptr, eventCode)
  34. end
  35. function Event:setDispatcher(dispatcher)
  36. local retVal = Polycore.Event_setDispatcher(self.__ptr, dispatcher.__ptr)
  37. end
  38. function Event:getEventType()
  39. local retVal = Polycore.Event_getEventType(self.__ptr)
  40. if retVal == nil then return nil end
  41. if Polycore.__ptr_lookup[retVal] ~= nil then
  42. return Polycore.__ptr_lookup[retVal]
  43. else
  44. Polycore.__ptr_lookup[retVal] = String("__skip_ptr__")
  45. Polycore.__ptr_lookup[retVal].__ptr = retVal
  46. return Polycore.__ptr_lookup[retVal]
  47. end
  48. end
  49. function Event:__delete()
  50. Polycore.__ptr_lookup[self.__ptr] = nil
  51. Polycore.delete_Event(self.__ptr)
  52. end