CoreMutex.lua 847 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. class "CoreMutex"
  2. function CoreMutex:__getvar(name)
  3. if name == "mutexID" then
  4. return Polycode.CoreMutex_get_mutexID(self.__ptr)
  5. end
  6. end
  7. function CoreMutex:__setvar(name,value)
  8. if name == "mutexID" then
  9. Polycode.CoreMutex_set_mutexID(self.__ptr, value)
  10. return true
  11. end
  12. return false
  13. end
  14. function CoreMutex:CoreMutex(...)
  15. local arg = {...}
  16. for k,v in pairs(arg) do
  17. if type(v) == "table" then
  18. if v.__ptr ~= nil then
  19. arg[k] = v.__ptr
  20. end
  21. end
  22. end
  23. if self.__ptr == nil and arg[1] ~= "__skip_ptr__" then
  24. self.__ptr = Polycode.CoreMutex(unpack(arg))
  25. end
  26. end
  27. function CoreMutex:lock()
  28. local retVal = Polycode.CoreMutex_lock(self.__ptr)
  29. end
  30. function CoreMutex:unlock()
  31. local retVal = Polycode.CoreMutex_unlock(self.__ptr)
  32. end
  33. function CoreMutex:__delete()
  34. if self then Polycode.delete_CoreMutex(self.__ptr) end
  35. end