Skip to content

Commit ad99211

Browse files
committed
py_lua_helper: added get_list method
1 parent 3500c3e commit ad99211

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

python_lua_helper/py_lua_helper.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,13 @@ def get_bool(self, key: str, default: bool = None) -> bool:
401401
return bool(default)
402402
raise
403403

404+
def get_list(self, key: str) -> List:
405+
"""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"""
406+
result = []
407+
for i in self.get_table_seq(key):
408+
result.append(self.get(f"{key}.{i}"))
409+
return result
410+
404411
def get_table_start(self, key: str) -> int:
405412
"""Get start indexed element index of table if variable is a table and indexed (keyless) elements present, 0 if no indexed elements present"""
406413
if key in self._metadata:

python_lua_helper/test_example.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,9 @@
141141
for i in cfg.get_table_seq('config.sub.loader_args'):
142142
print(f"example.py: cfg['config.sub.loader_args.{i}'] = {cfg.get(f'config.sub.loader_args.{i}', 'NOT_FOUND')}")
143143

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+
144147
# Test typed get
145148
print("example.py: === test getting values with specific type from config.sub.types table ===")
146149
print(f"example.py: get bool value, no fallback: cfg['config.sub.types.b'] = {cfg.get_bool('config.sub.types.b')}")

0 commit comments

Comments
 (0)