Config.lua 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. return retVal
  45. end
  46. function Config:__delete()
  47. Polycore.__ptr_lookup[self.__ptr] = nil
  48. Polycore.delete_Config(self.__ptr)
  49. end