Data.lua 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. class "Data"
  2. function Data:Data(...)
  3. local arg = {...}
  4. for k,v in pairs(arg) do
  5. if type(v) == "table" then
  6. if v.__ptr ~= nil then
  7. arg[k] = v.__ptr
  8. end
  9. end
  10. end
  11. if self.__ptr == nil and arg[1] ~= "__skip_ptr__" then
  12. self.__ptr = Polycode.Data(unpack(arg))
  13. end
  14. end
  15. function Data:loadFromFile(fileName)
  16. local retVal = Polycode.Data_loadFromFile(self.__ptr, fileName)
  17. return retVal
  18. end
  19. function Data:getAsString(encoding)
  20. local retVal = Polycode.Data_getAsString(self.__ptr, encoding)
  21. return retVal
  22. end
  23. function Data:setFromString(str, encoding)
  24. local retVal = Polycode.Data_setFromString(self.__ptr, str, encoding)
  25. end
  26. function Data:saveToFile(fileName)
  27. local retVal = Polycode.Data_saveToFile(self.__ptr, fileName)
  28. return retVal
  29. end
  30. function Data:getData()
  31. local retVal = Polycode.Data_getData(self.__ptr)
  32. if retVal == nil then return nil end
  33. local __c = _G["char"]("__skip_ptr__")
  34. __c.__ptr = retVal
  35. return __c
  36. end
  37. function Data:__delete()
  38. if self then Polycode.delete_Data(self.__ptr) end
  39. end