Python-Lua-Helper 1.1.0__tar.gz → 1.3.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: Python-Lua-Helper
3
- Version: 1.1.0
3
+ Version: 1.3.0
4
4
  Summary: Lua configuration system for your Python projects.
5
5
  Project-URL: Repository, https://github.com/DarkCaster/Python-Lua-Helper.git
6
6
  Author-email: DarkCaster <dark.caster@outlook.com>
@@ -394,13 +394,25 @@ class PyLuaHelper:
394
394
  try:
395
395
  value_type = self.get_type(key)
396
396
  if value_type == "boolean":
397
- return bool(self._variables.get(key, default))
397
+ value = self._variables.get(key)
398
+ if value == "true":
399
+ value = True
400
+ elif value == "false":
401
+ value = False
402
+ return bool(value)
398
403
  raise ValueError(f"Invalid value type: {value_type}")
399
404
  except ValueError:
400
405
  if default is not None:
401
406
  return bool(default)
402
407
  raise
403
408
 
409
+ def get_list(self, key: str) -> List:
410
+ """Get indexed elements of table as list of strings if variable is a table and indexed (keyless) elements present, empty list if no elements present or variable is not a table"""
411
+ result = []
412
+ for i in self.get_table_seq(key):
413
+ result.append(self.get(f"{key}.{i}"))
414
+ return result
415
+
404
416
  def get_table_start(self, key: str) -> int:
405
417
  """Get start indexed element index of table if variable is a table and indexed (keyless) elements present, 0 if no indexed elements present"""
406
418
  if key in self._metadata:
@@ -27,7 +27,7 @@ config =
27
27
  mixed={ 1, "text", true, key="test_value" },
28
28
  empty_table={ },
29
29
  types = {
30
- b=true,
30
+ b=false,
31
31
  i=100,
32
32
  f=99.99,
33
33
  s="string value",
@@ -141,10 +141,13 @@ print(f"example.py: config.sub.loader_args indices sequence: {cfg.get_table_seq(
141
141
  for i in cfg.get_table_seq('config.sub.loader_args'):
142
142
  print(f"example.py: cfg['config.sub.loader_args.{i}'] = {cfg.get(f'config.sub.loader_args.{i}', 'NOT_FOUND')}")
143
143
 
144
+ print("example.py: === getting extra params (or cmdline args) as list ===")
145
+ print(f"example.py: {cfg.get_list('config.sub.loader_args')}")
146
+
144
147
  # Test typed get
145
148
  print("example.py: === test getting values with specific type from config.sub.types table ===")
146
149
  print(f"example.py: get bool value, no fallback: cfg['config.sub.types.b'] = {cfg.get_bool('config.sub.types.b')}")
147
- print(f"example.py: get missing bool value, fallback: cfg['config.sub.types.b1'] = {cfg.get_bool('config.sub.types.b1', False)}")
150
+ print(f"example.py: get missing bool value, fallback: cfg['config.sub.types.b1'] = {cfg.get_bool('config.sub.types.b1', True)}")
148
151
  print(f"example.py: get bool value from int, fallback: cfg['config.sub.types.i'] = {cfg.get_bool('config.sub.types.i', False)}")
149
152
 
150
153
  print(f"example.py: get int value, no fallback: cfg['config.sub.types.i'] = {cfg.get_int('config.sub.types.i')}")