Config.lua 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. class "Config"
  2. function Config:Config(...)
  3. for k,v in pairs(arg) do
  4. if type(v) == "table" then
  5. if v.__ptr ~= nil then
  6. arg[k] = v.__ptr
  7. end
  8. end
  9. end
  10. if self.__ptr == nil and arg[1] ~= "__skip_ptr__" then
  11. self.__ptr = Polycore.Config(unpack(arg))
  12. Polycore.__ptr_lookup[self.__ptr] = self
  13. end
  14. end
  15. function Config:loadConfig(configNamespace, fileName)
  16. local retVal = Polycore.Config_loadConfig(self.__ptr, configNamespace, fileName)
  17. end
  18. function Config:saveConfig(configNamespace, fileName)
  19. local retVal = Polycore.Config_saveConfig(self.__ptr, configNamespace, fileName)
  20. end
  21. function Config:getEntry(configNamespace, key)
  22. local retVal = Polycore.Config_getEntry(self.__ptr, configNamespace, key)
  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] = ConfigEntry("__skip_ptr__")
  28. Polycore.__ptr_lookup[retVal].__ptr = retVal
  29. return Polycore.__ptr_lookup[retVal]
  30. end
  31. end
  32. function Config:setStringValue(configNamespace, key, value)
  33. local retVal = Polycore.Config_setStringValue(self.__ptr, configNamespace, key, value)
  34. end
  35. function Config:setNumericValue(configNamespace, key, value)
  36. local retVal = Polycore.Config_setNumericValue(self.__ptr, configNamespace, key, value)
  37. end
  38. function Config:getNumericValue(configNamespace, key)
  39. local retVal = Polycore.Config_getNumericValue(self.__ptr, configNamespace, key)
  40. return retVal
  41. end
  42. function Config:getStringValue(configNamespace, key)
  43. local retVal = Polycore.Config_getStringValue(self.__ptr, configNamespace, key)
  44. if retVal == nil then return nil end
  45. if Polycore.__ptr_lookup[retVal] ~= nil then
  46. return Polycore.__ptr_lookup[retVal]
  47. else
  48. Polycore.__ptr_lookup[retVal] = String("__skip_ptr__")
  49. Polycore.__ptr_lookup[retVal].__ptr = retVal
  50. return Polycore.__ptr_lookup[retVal]
  51. end
  52. end
  53. function Config:__delete()
  54. Polycore.__ptr_lookup[self.__ptr] = nil
  55. Polycore.delete_Config(self.__ptr)
  56. end