Config.lua 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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 Polycore.__ptr_lookup[retVal] ~= nil then
  24. return Polycore.__ptr_lookup[retVal]
  25. else
  26. Polycore.__ptr_lookup[retVal] = ConfigEntry("__skip_ptr__")
  27. Polycore.__ptr_lookup[retVal].__ptr = retVal
  28. return Polycore.__ptr_lookup[retVal]
  29. end
  30. end
  31. function Config:setStringValue(configNamespace, key, value)
  32. local retVal = Polycore.Config_setStringValue(self.__ptr, configNamespace, key, value)
  33. end
  34. function Config:setNumericValue(configNamespace, key, value)
  35. local retVal = Polycore.Config_setNumericValue(self.__ptr, configNamespace, key, value)
  36. end
  37. function Config:getNumericValue(configNamespace, key)
  38. local retVal = Polycore.Config_getNumericValue(self.__ptr, configNamespace, key)
  39. return retVal
  40. end
  41. function Config:getStringValue(configNamespace, key)
  42. local retVal = Polycore.Config_getStringValue(self.__ptr, configNamespace, key)
  43. return retVal
  44. end
  45. function Config:__delete()
  46. Polycore.__ptr_lookup[self.__ptr] = nil
  47. Polycore.delete_Config(self.__ptr)
  48. end