Python-Lua-Helper 1.0.1__tar.gz → 1.2.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.
- {python_lua_helper-1.0.1 → python_lua_helper-1.2.0}/PKG-INFO +1 -1
- {python_lua_helper-1.0.1 → python_lua_helper-1.2.0}/lua/lua-windows-i686 +0 -0
- {python_lua_helper-1.0.1 → python_lua_helper-1.2.0}/lua/lua-windows-x86_64 +0 -0
- {python_lua_helper-1.0.1 → python_lua_helper-1.2.0}/python_lua_helper/py_lua_helper.py +46 -3
- {python_lua_helper-1.0.1 → python_lua_helper-1.2.0}/python_lua_helper/test_example/example.cfg.lua +8 -1
- python_lua_helper-1.2.0/python_lua_helper/test_example.py +160 -0
- python_lua_helper-1.0.1/python_lua_helper/test_example.py +0 -124
- {python_lua_helper-1.0.1 → python_lua_helper-1.2.0}/.gitignore +0 -0
- {python_lua_helper-1.0.1 → python_lua_helper-1.2.0}/LICENSE +0 -0
- {python_lua_helper-1.0.1 → python_lua_helper-1.2.0}/hatch_build.py +0 -0
- {python_lua_helper-1.0.1 → python_lua_helper-1.2.0}/lua/build-mingw.sh +0 -0
- {python_lua_helper-1.0.1 → python_lua_helper-1.2.0}/lua/build.patch +0 -0
- {python_lua_helper-1.0.1 → python_lua_helper-1.2.0}/lua/lua-5.4.8.sha256 +0 -0
- {python_lua_helper-1.0.1 → python_lua_helper-1.2.0}/pyproject.toml +0 -0
- {python_lua_helper-1.0.1 → python_lua_helper-1.2.0}/python_lua_helper/__init__.py +0 -0
- {python_lua_helper-1.0.1 → python_lua_helper-1.2.0}/python_lua_helper/loader.lua +0 -0
- {python_lua_helper-1.0.1 → python_lua_helper-1.2.0}/python_lua_helper/test_example/example.post.lua +0 -0
- {python_lua_helper-1.0.1 → python_lua_helper-1.2.0}/python_lua_helper/test_example/example.pre.lua +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: Python-Lua-Helper
|
|
3
|
-
Version: 1.0
|
|
3
|
+
Version: 1.2.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>
|
|
Binary file
|
|
Binary file
|
|
@@ -299,7 +299,6 @@ class PyLuaHelper:
|
|
|
299
299
|
self._variables[filename] = f.read().decode(
|
|
300
300
|
"utf-8", errors="ignore"
|
|
301
301
|
)
|
|
302
|
-
|
|
303
302
|
# Read metadata
|
|
304
303
|
with open(os.path.join(self.meta_dir, filename), "rb") as f:
|
|
305
304
|
self._metadata[filename] = f.read().decode("utf-8", errors="ignore")
|
|
@@ -343,14 +342,36 @@ class PyLuaHelper:
|
|
|
343
342
|
"""Get list of (name, value) tuples."""
|
|
344
343
|
return list(self._variables.items())
|
|
345
344
|
|
|
345
|
+
def is_table(self, key: str) -> bool:
|
|
346
|
+
"""Check variable is a table, return true or false"""
|
|
347
|
+
if key in self._metadata:
|
|
348
|
+
match = re.match(r"^table.*", self._metadata[key])
|
|
349
|
+
if match:
|
|
350
|
+
return True
|
|
351
|
+
return False
|
|
352
|
+
|
|
353
|
+
def get_type(self, key: str) -> str:
|
|
354
|
+
"""Get variable type"""
|
|
355
|
+
if self.is_table(key):
|
|
356
|
+
return "table"
|
|
357
|
+
if key in self._metadata and re.match(r"^string.*", self._metadata[key]):
|
|
358
|
+
return "string"
|
|
359
|
+
return self._metadata.get(key, "none")
|
|
360
|
+
|
|
346
361
|
def get(self, key: str, default: str = None) -> str:
|
|
347
362
|
"""Get variable value with default."""
|
|
363
|
+
# cannot get value of table directly, so, return default
|
|
364
|
+
if self.is_table(key):
|
|
365
|
+
return default
|
|
348
366
|
return self._variables.get(key, default)
|
|
349
367
|
|
|
350
368
|
def get_int(self, key: str, default: int = None) -> int:
|
|
351
369
|
"""Get variable value as integer with defaults on type conversion error."""
|
|
352
370
|
try:
|
|
353
|
-
|
|
371
|
+
value_type = self.get_type(key)
|
|
372
|
+
if value_type == "number":
|
|
373
|
+
return int(self._variables.get(key, default))
|
|
374
|
+
raise ValueError(f"Invalid value type: {value_type}")
|
|
354
375
|
except ValueError:
|
|
355
376
|
if default is not None:
|
|
356
377
|
return int(default)
|
|
@@ -359,12 +380,34 @@ class PyLuaHelper:
|
|
|
359
380
|
def get_float(self, key: str, default: float = None) -> float:
|
|
360
381
|
"""Get variable value as float with defaults on type conversion error."""
|
|
361
382
|
try:
|
|
362
|
-
|
|
383
|
+
value_type = self.get_type(key)
|
|
384
|
+
if value_type == "number":
|
|
385
|
+
return float(self._variables.get(key, default))
|
|
386
|
+
raise ValueError(f"Invalid value type: {value_type}")
|
|
363
387
|
except ValueError:
|
|
364
388
|
if default is not None:
|
|
365
389
|
return float(default)
|
|
366
390
|
raise
|
|
367
391
|
|
|
392
|
+
def get_bool(self, key: str, default: bool = None) -> bool:
|
|
393
|
+
"""Get variable value as bool with defaults on type conversion error."""
|
|
394
|
+
try:
|
|
395
|
+
value_type = self.get_type(key)
|
|
396
|
+
if value_type == "boolean":
|
|
397
|
+
return bool(self._variables.get(key, default))
|
|
398
|
+
raise ValueError(f"Invalid value type: {value_type}")
|
|
399
|
+
except ValueError:
|
|
400
|
+
if default is not None:
|
|
401
|
+
return bool(default)
|
|
402
|
+
raise
|
|
403
|
+
|
|
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
|
+
|
|
368
411
|
def get_table_start(self, key: str) -> int:
|
|
369
412
|
"""Get start indexed element index of table if variable is a table and indexed (keyless) elements present, 0 if no indexed elements present"""
|
|
370
413
|
if key in self._metadata:
|
{python_lua_helper-1.0.1 → python_lua_helper-1.2.0}/python_lua_helper/test_example/example.cfg.lua
RENAMED
|
@@ -24,7 +24,14 @@ config =
|
|
|
24
24
|
extra_1=loader.extra[1],
|
|
25
25
|
extra_2=loader.extra[2],
|
|
26
26
|
loader_args=loader.args,
|
|
27
|
-
mixed={ 1, "text", true, key="test_value" }
|
|
27
|
+
mixed={ 1, "text", true, key="test_value" },
|
|
28
|
+
empty_table={ },
|
|
29
|
+
types = {
|
|
30
|
+
b=true,
|
|
31
|
+
i=100,
|
|
32
|
+
f=99.99,
|
|
33
|
+
s="string value",
|
|
34
|
+
}
|
|
28
35
|
},
|
|
29
36
|
paths=
|
|
30
37
|
{
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
|
|
3
|
+
import os
|
|
4
|
+
import sys
|
|
5
|
+
from py_lua_helper import PyLuaHelper
|
|
6
|
+
|
|
7
|
+
# Get script directory
|
|
8
|
+
script_dir = os.path.dirname(os.path.abspath(__file__))
|
|
9
|
+
|
|
10
|
+
print("example.py: creating PyLuaHelper instance")
|
|
11
|
+
|
|
12
|
+
# Create PyLuaHelper instance with same parameters as example.bash
|
|
13
|
+
cfg = PyLuaHelper(
|
|
14
|
+
lua_config_script=os.path.join(script_dir, "test_example", "example.cfg.lua"),
|
|
15
|
+
export_vars=["config.sub", "config.paths", "config.empty", "wrong.table", "empty"],
|
|
16
|
+
extra_strings=["test1", "test2"],
|
|
17
|
+
pre_script=os.path.join(script_dir, "test_example", "example.pre.lua"),
|
|
18
|
+
post_script=os.path.join(script_dir, "test_example", "example.post.lua"),
|
|
19
|
+
work_dir=script_dir,
|
|
20
|
+
lua_args=sys.argv[1:]
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
print("example.py: PyLuaHelper complete")
|
|
24
|
+
print(f"example.py: my own cmdline params={sys.argv[1:]}")
|
|
25
|
+
print("")
|
|
26
|
+
print("example.py: names of all global variables exported from lua script:")
|
|
27
|
+
print(cfg.keys())
|
|
28
|
+
print("")
|
|
29
|
+
|
|
30
|
+
# Check variable availability
|
|
31
|
+
print("example.py: === value availability tests ===")
|
|
32
|
+
print("example.py: check for config.empty variable availability is ", end="")
|
|
33
|
+
try:
|
|
34
|
+
if "config.empty" in cfg:
|
|
35
|
+
print("passed, but should fail !!!")
|
|
36
|
+
else:
|
|
37
|
+
print("failed, as expected")
|
|
38
|
+
except Exception:
|
|
39
|
+
print("failed (exception)")
|
|
40
|
+
|
|
41
|
+
print("example.py: check for wrong.table variable availability is ", end="")
|
|
42
|
+
try:
|
|
43
|
+
if "wrong.table" in cfg:
|
|
44
|
+
print("passed, but should fail !!!")
|
|
45
|
+
else:
|
|
46
|
+
print("failed, as expected")
|
|
47
|
+
except Exception:
|
|
48
|
+
print("failed (exception)")
|
|
49
|
+
|
|
50
|
+
print("example.py: check for empty variable availability is ", end="")
|
|
51
|
+
try:
|
|
52
|
+
if "empty" in cfg:
|
|
53
|
+
print("passed, but should fail !!!")
|
|
54
|
+
else:
|
|
55
|
+
print("failed, as expected")
|
|
56
|
+
except Exception:
|
|
57
|
+
print("failed (exception)")
|
|
58
|
+
|
|
59
|
+
print("example.py: check for config.value variable availability is ", end="")
|
|
60
|
+
try:
|
|
61
|
+
if "config.value" in cfg:
|
|
62
|
+
print("passed, but should fail !!!")
|
|
63
|
+
else:
|
|
64
|
+
print("failed, as expected")
|
|
65
|
+
except Exception:
|
|
66
|
+
print("failed (exception)")
|
|
67
|
+
|
|
68
|
+
print("example.py: check for config.sub.string variable availability is ", end="")
|
|
69
|
+
try:
|
|
70
|
+
if "config.sub.string" in cfg:
|
|
71
|
+
print("passed, as expected")
|
|
72
|
+
else:
|
|
73
|
+
print("failed, but should pass !!!")
|
|
74
|
+
except Exception:
|
|
75
|
+
print("failed (exception)")
|
|
76
|
+
|
|
77
|
+
print("example.py: check for config.sub variable availability is ", end="")
|
|
78
|
+
try:
|
|
79
|
+
if "config.sub" in cfg:
|
|
80
|
+
print("passed, as expected")
|
|
81
|
+
else:
|
|
82
|
+
print("failed, but should pass !!!")
|
|
83
|
+
except Exception:
|
|
84
|
+
print("failed (exception)")
|
|
85
|
+
|
|
86
|
+
print("example.py: === value query tests ===")
|
|
87
|
+
print(f"example.py: not selected for export, should return fallback (NOT_FOUND): cfg['config.value'] = {cfg.get('config.value', 'NOT_FOUND')}, type = {cfg.get_type('config.value')}")
|
|
88
|
+
print(f"example.py: not found in config, should return fallback (NOT_FOUND): cfg['config.empty'] = {cfg.get('config.empty', 'NOT_FOUND')}, type = {cfg.get_type('config.empty')}")
|
|
89
|
+
print(f"example.py: cfg['config.paths.tempdir'] = {cfg.get('config.paths.tempdir', 'NOT_FOUND')}, type = {cfg.get_type('config.paths.tempdir')}")
|
|
90
|
+
print(f"example.py: cfg['config.paths.workdir'] = {cfg.get('config.paths.workdir', 'NOT_FOUND')}, type = {cfg.get_type('config.paths.workdir')}")
|
|
91
|
+
print(f"example.py: cfg['config.paths.dynpath'] = {cfg.get('config.paths.dynpath', 'NOT_FOUND')}, type = {cfg.get_type('config.paths.dynpath')}")
|
|
92
|
+
print(f"example.py: cfg['config.paths.tempdir_raw'] = {cfg.get('config.paths.tempdir_raw', 'NOT_FOUND')}, type = {cfg.get_type('config.paths.tempdir_raw')}")
|
|
93
|
+
print(f"example.py: cfg['config.paths.workdir_raw'] = {cfg.get('config.paths.workdir_raw', 'NOT_FOUND')}, type = {cfg.get_type('config.paths.workdir_raw')}")
|
|
94
|
+
print(f"example.py: cfg['config.paths.dynpath_raw'] = {cfg.get('config.paths.dynpath_raw', 'NOT_FOUND')}, type = {cfg.get_type('config.paths.dynpath_raw')}")
|
|
95
|
+
print(f"example.py: cfg['config.sub.lua_v1'] = {cfg.get('config.sub.lua_v1', 'NOT_FOUND')}, type = {cfg.get_type('config.sub.lua_v1')}")
|
|
96
|
+
print(f"example.py: cfg['config.sub.lua_v2'] = {cfg.get('config.sub.lua_v2', 'NOT_FOUND')}, type = {cfg.get_type('config.sub.lua_v2')}")
|
|
97
|
+
print(f"example.py: cfg['config.sub.lua_v3'] = {cfg.get('config.sub.lua_v3', 'NOT_FOUND')}, type = {cfg.get_type('config.sub.lua_v3')}")
|
|
98
|
+
print(f"example.py: cfg['config.sub.lua_num'] = {cfg.get('config.sub.lua_num', 'NOT_FOUND')}, type = {cfg.get_type('config.sub.lua_num')}")
|
|
99
|
+
print(f"example.py: cfg['config.sub.extra_1'] = {cfg.get('config.sub.extra_1', 'NOT_FOUND')}, type = {cfg.get_type('config.sub.extra_1')}")
|
|
100
|
+
print(f"example.py: cfg['config.sub.extra_2'] = {cfg.get('config.sub.extra_2', 'NOT_FOUND')}, type = {cfg.get_type('config.sub.extra_2')}")
|
|
101
|
+
print(f"example.py: cfg['config.sub.number1'] = {cfg.get('config.sub.number1', 'NOT_FOUND')}, type = {cfg.get_type('config.sub.number1')}")
|
|
102
|
+
print(f"example.py: cfg['config.sub.number2'] = {cfg.get('config.sub.number2', 'NOT_FOUND')}, type = {cfg.get_type('config.sub.number2')}")
|
|
103
|
+
print(f"example.py: cfg['config.sub.string'] = {cfg.get('config.sub.string', 'NOT_FOUND')}, type = {cfg.get_type('config.sub.string')}")
|
|
104
|
+
print(f"example.py: cfg['config.sub.problematic_string'] = {cfg.get('config.sub.problematic_string', 'NOT_FOUND')}, type = {cfg.get_type('config.sub.problematic_string')}")
|
|
105
|
+
print(f"example.py: cfg['config.sub.non_latin_string'] = {cfg.get('config.sub.non_latin_string', 'NOT_FOUND')}, type = {cfg.get_type('config.sub.non_latin_string')}")
|
|
106
|
+
|
|
107
|
+
# Test table access
|
|
108
|
+
print("example.py: === table tests for cfg['config.sub.sub'] ===")
|
|
109
|
+
print(f"example.py: cfg.is_table('config.sub.sub') = {cfg.is_table('config.sub.sub')}, type = {cfg.get_type('config.sub.sub')}")
|
|
110
|
+
print(f"example.py: table value should return fallback (NOT_FOUND): cfg['config.sub.sub'] = {cfg.get('config.sub.sub', 'NOT_FOUND')}")
|
|
111
|
+
print(f"example.py: table value as int should return fallback (-1): cfg['config.sub.sub'] = {cfg.get_int('config.sub.sub',-1)}")
|
|
112
|
+
print(f"example.py: table value as int should return fallback (-1.6 as int == -1): cfg['config.sub.sub'] = {cfg.get_int('config.sub.sub',-1.6)}")
|
|
113
|
+
print(f"example.py: table value as float should return fallback (-1.5): cfg['config.sub.sub'] = {cfg.get_float('config.sub.sub',-1.5)}")
|
|
114
|
+
print("example.py: === table's value tests for cfg['config.sub.sub'] ===")
|
|
115
|
+
print(f"example.py: cfg['config.sub.sub.message'] = {cfg.get('config.sub.sub.message', 'NOT_FOUND')}, type = {cfg.get_type('config.sub.sub.message')}")
|
|
116
|
+
print(f"example.py: cfg['config.sub.sub.message2'] = {cfg.get('config.sub.sub.message2', 'NOT_FOUND')}, type = {cfg.get_type('config.sub.sub.message2')}")
|
|
117
|
+
print(f"example.py: cfg['config.sub.multiline_string'] = {cfg.get('config.sub.multiline_string', 'NOT_FOUND')}")
|
|
118
|
+
|
|
119
|
+
# Test empty table access
|
|
120
|
+
print("example.py: === empty table tests for cfg['config.sub.empty_table'] ===")
|
|
121
|
+
print(f"example.py: cfg.is_table('config.sub.empty_table') = {cfg.is_table('config.sub.empty_table')}, type = {cfg.get_type('config.sub.empty_table')}")
|
|
122
|
+
print(f"example.py: table value should return fallback (NOT_FOUND): cfg['config.sub.empty_table'] = {cfg.get('config.sub.empty_table', 'NOT_FOUND')}")
|
|
123
|
+
print(f"example.py: table start for cfg['config.sub.empty_table'] = {cfg.get_table_start('config.sub.empty_table')}")
|
|
124
|
+
print(f"example.py: table end for cfg['config.sub.empty_table'] = {cfg.get_table_end('config.sub.empty_table')}")
|
|
125
|
+
|
|
126
|
+
# Test mixed table access (indexed and named elements)
|
|
127
|
+
print("example.py: === mixed table tests for cfg['config.sub.mixed'] ===")
|
|
128
|
+
print(f"example.py: cfg.is_table('config.sub.mixed') = {cfg.is_table('config.sub.mixed')}, type = {cfg.get_type('config.sub.mixed')}")
|
|
129
|
+
print(f"example.py: table start for config.sub.mixed: {cfg.get_table_start('config.sub.mixed')}")
|
|
130
|
+
print(f"example.py: table end for config.sub.mixed: {cfg.get_table_end('config.sub.mixed')}")
|
|
131
|
+
print(f"example.py: table indices sequence for config.sub.mixed: {cfg.get_table_seq('config.sub.mixed')}")
|
|
132
|
+
print(f"example.py: cfg['config.sub.mixed.1'] = {cfg.get('config.sub.mixed.1', 'NOT_FOUND')}")
|
|
133
|
+
print(f"example.py: cfg['config.sub.mixed.2'] = {cfg.get('config.sub.mixed.2', 'NOT_FOUND')}")
|
|
134
|
+
print(f"example.py: cfg['config.sub.mixed.3'] = {cfg.get('config.sub.mixed.3', 'NOT_FOUND')}")
|
|
135
|
+
print(f"example.py: cfg['config.sub.mixed.4'] = {cfg.get('config.sub.mixed.4', 'NOT_FOUND')}")
|
|
136
|
+
print(f"example.py: cfg['config.sub.mixed.key'] = {cfg.get('config.sub.mixed.key', 'NOT_FOUND')}")
|
|
137
|
+
|
|
138
|
+
# Show extra cmdline parameters passed to lua script as loader.args table and assigned to config.sub.loader_args
|
|
139
|
+
print("example.py: === test passing extra params (or cmdline args) into lua config ===")
|
|
140
|
+
print(f"example.py: config.sub.loader_args indices sequence: {cfg.get_table_seq('config.sub.loader_args')}")
|
|
141
|
+
for i in cfg.get_table_seq('config.sub.loader_args'):
|
|
142
|
+
print(f"example.py: cfg['config.sub.loader_args.{i}'] = {cfg.get(f'config.sub.loader_args.{i}', 'NOT_FOUND')}")
|
|
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
|
+
|
|
147
|
+
# Test typed get
|
|
148
|
+
print("example.py: === test getting values with specific type from config.sub.types table ===")
|
|
149
|
+
print(f"example.py: get bool value, no fallback: cfg['config.sub.types.b'] = {cfg.get_bool('config.sub.types.b')}")
|
|
150
|
+
print(f"example.py: get missing bool value, fallback: cfg['config.sub.types.b1'] = {cfg.get_bool('config.sub.types.b1', False)}")
|
|
151
|
+
print(f"example.py: get bool value from int, fallback: cfg['config.sub.types.i'] = {cfg.get_bool('config.sub.types.i', False)}")
|
|
152
|
+
|
|
153
|
+
print(f"example.py: get int value, no fallback: cfg['config.sub.types.i'] = {cfg.get_int('config.sub.types.i')}")
|
|
154
|
+
print(f"example.py: get missing int value, fallback: cfg['config.sub.types.i1'] = {cfg.get_int('config.sub.types.i1', -1)}")
|
|
155
|
+
print(f"example.py: get missing int value, fallback from float num: cfg['config.sub.types.i1'] = {cfg.get_int('config.sub.types.i1', -2.6)}")
|
|
156
|
+
print(f"example.py: get int value from bool, fallback: cfg['config.sub.types.b'] = {cfg.get_int('config.sub.types.b', -1)}")
|
|
157
|
+
|
|
158
|
+
print(f"example.py: get float value, no fallback: cfg['config.sub.types.f'] = {cfg.get_float('config.sub.types.f')}")
|
|
159
|
+
print(f"example.py: get missing float value, fallback: cfg['config.sub.types.f1'] = {cfg.get_float('config.sub.types.f1', -1.1)}")
|
|
160
|
+
print(f"example.py: get float value from bool, fallback: cfg['config.sub.types.b'] = {cfg.get_float('config.sub.types.b', -1.1)}")
|
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env python3
|
|
2
|
-
|
|
3
|
-
import os
|
|
4
|
-
import sys
|
|
5
|
-
from py_lua_helper import PyLuaHelper
|
|
6
|
-
|
|
7
|
-
# Get script directory
|
|
8
|
-
script_dir = os.path.dirname(os.path.abspath(__file__))
|
|
9
|
-
|
|
10
|
-
print("example.py: creating PyLuaHelper instance")
|
|
11
|
-
|
|
12
|
-
# Create PyLuaHelper instance with same parameters as example.bash
|
|
13
|
-
cfg = PyLuaHelper(
|
|
14
|
-
lua_config_script=os.path.join(script_dir, "test_example", "example.cfg.lua"),
|
|
15
|
-
export_vars=["config.sub", "config.paths", "config.empty", "wrong.table", "empty"],
|
|
16
|
-
extra_strings=["test1", "test2"],
|
|
17
|
-
pre_script=os.path.join(script_dir, "test_example", "example.pre.lua"),
|
|
18
|
-
post_script=os.path.join(script_dir, "test_example", "example.post.lua"),
|
|
19
|
-
work_dir=script_dir,
|
|
20
|
-
lua_args=sys.argv[1:]
|
|
21
|
-
)
|
|
22
|
-
|
|
23
|
-
print("example.py: PyLuaHelper complete")
|
|
24
|
-
print(f"example.py: my own cmdline params={sys.argv[1:]}")
|
|
25
|
-
print("")
|
|
26
|
-
print("example.py: names of all global variables exported from lua script:")
|
|
27
|
-
print(cfg.keys())
|
|
28
|
-
print("")
|
|
29
|
-
|
|
30
|
-
# Check variable availability
|
|
31
|
-
print("example.py: check for config.empty variable availability is ", end="")
|
|
32
|
-
try:
|
|
33
|
-
if "config.empty" in cfg:
|
|
34
|
-
print("passed, but should fail !!!")
|
|
35
|
-
else:
|
|
36
|
-
print("failed, as expected")
|
|
37
|
-
except Exception:
|
|
38
|
-
print("failed, as expected")
|
|
39
|
-
|
|
40
|
-
print("example.py: check for wrong.table variable availability is ", end="")
|
|
41
|
-
try:
|
|
42
|
-
if "wrong.table" in cfg:
|
|
43
|
-
print("passed, but should fail !!!")
|
|
44
|
-
else:
|
|
45
|
-
print("failed, as expected")
|
|
46
|
-
except Exception:
|
|
47
|
-
print("failed, as expected")
|
|
48
|
-
|
|
49
|
-
print("example.py: check for empty variable availability is ", end="")
|
|
50
|
-
try:
|
|
51
|
-
if "empty" in cfg:
|
|
52
|
-
print("passed, but should fail !!!")
|
|
53
|
-
else:
|
|
54
|
-
print("failed, as expected")
|
|
55
|
-
except Exception:
|
|
56
|
-
print("failed, as expected")
|
|
57
|
-
|
|
58
|
-
print("example.py: check for config.value variable availability is ", end="")
|
|
59
|
-
try:
|
|
60
|
-
if "config.value" in cfg:
|
|
61
|
-
print("passed, but should fail !!!")
|
|
62
|
-
else:
|
|
63
|
-
print("failed, as expected")
|
|
64
|
-
except Exception:
|
|
65
|
-
print("failed, as expected")
|
|
66
|
-
|
|
67
|
-
print("example.py: check for config.sub.string variable availability is ", end="")
|
|
68
|
-
try:
|
|
69
|
-
if "config.sub.string" in cfg:
|
|
70
|
-
print("passed, as expected")
|
|
71
|
-
else:
|
|
72
|
-
print("failed, but should pass !!!")
|
|
73
|
-
except Exception:
|
|
74
|
-
print("failed, but should pass !!!")
|
|
75
|
-
|
|
76
|
-
print("example.py: check for config.sub variable availability is ", end="")
|
|
77
|
-
try:
|
|
78
|
-
if "config.sub" in cfg:
|
|
79
|
-
print("passed, as expected")
|
|
80
|
-
else:
|
|
81
|
-
print("failed, but should pass !!!")
|
|
82
|
-
except Exception:
|
|
83
|
-
print("failed, but should pass !!!")
|
|
84
|
-
|
|
85
|
-
print(f"example.py: config.value is not selected for export, so cfg['config.value'] = {cfg.get('config.value', 'NOT_FOUND')}")
|
|
86
|
-
print(f"example.py: config.empty is not found in lua config file, so cfg['config.empty'] = {cfg.get('config.empty', 'NOT_FOUND')}")
|
|
87
|
-
print(f"example.py: cfg['config.paths.tempdir'] = {cfg.get('config.paths.tempdir', 'NOT_FOUND')}")
|
|
88
|
-
print(f"example.py: cfg['config.paths.workdir'] = {cfg.get('config.paths.workdir', 'NOT_FOUND')}")
|
|
89
|
-
print(f"example.py: cfg['config.paths.dynpath'] = {cfg.get('config.paths.dynpath', 'NOT_FOUND')}")
|
|
90
|
-
print(f"example.py: cfg['config.paths.tempdir_raw'] = {cfg.get('config.paths.tempdir_raw', 'NOT_FOUND')}")
|
|
91
|
-
print(f"example.py: cfg['config.paths.workdir_raw'] = {cfg.get('config.paths.workdir_raw', 'NOT_FOUND')}")
|
|
92
|
-
print(f"example.py: cfg['config.paths.dynpath_raw'] = {cfg.get('config.paths.dynpath_raw', 'NOT_FOUND')}")
|
|
93
|
-
print(f"example.py: cfg['config.sub.lua_v1'] = {cfg.get('config.sub.lua_v1', 'NOT_FOUND')}")
|
|
94
|
-
print(f"example.py: cfg['config.sub.lua_v2'] = {cfg.get('config.sub.lua_v2', 'NOT_FOUND')}")
|
|
95
|
-
print(f"example.py: cfg['config.sub.lua_v3'] = {cfg.get('config.sub.lua_v3', 'NOT_FOUND')}")
|
|
96
|
-
print(f"example.py: cfg['config.sub.lua_num'] = {cfg.get('config.sub.lua_num', 'NOT_FOUND')}")
|
|
97
|
-
print(f"example.py: cfg['config.sub.extra_1'] = {cfg.get('config.sub.extra_1', 'NOT_FOUND')}")
|
|
98
|
-
print(f"example.py: cfg['config.sub.extra_2'] = {cfg.get('config.sub.extra_2', 'NOT_FOUND')}")
|
|
99
|
-
print(f"example.py: cfg['config.sub.number1'] = {cfg.get('config.sub.number1', 'NOT_FOUND')}")
|
|
100
|
-
print(f"example.py: cfg['config.sub.string'] = {cfg.get('config.sub.string', 'NOT_FOUND')}")
|
|
101
|
-
print(f"example.py: cfg['config.sub.problematic_string'] = {cfg.get('config.sub.problematic_string', 'NOT_FOUND')}")
|
|
102
|
-
print(f"example.py: cfg['config.sub.non_latin_string'] = {cfg.get('config.sub.non_latin_string', 'NOT_FOUND')}")
|
|
103
|
-
print(f"example.py: (should be empty regardless of fallback value, because it is a container: cfg['config.sub.sub']) = {cfg.get('config.sub.sub', 'NOT_FOUND')}")
|
|
104
|
-
print(f"example.py: cfg['config.sub.sub'] as int with fallback value -1) = {cfg.get_int('config.sub.sub',-1)}")
|
|
105
|
-
print(f"example.py: cfg['config.sub.sub'] as int with fallback value -1.6) = {cfg.get_int('config.sub.sub',-1.6)}")
|
|
106
|
-
print(f"example.py: cfg['config.sub.sub'] as float with fallback value -1.5) = {cfg.get_float('config.sub.sub',-1.5)}")
|
|
107
|
-
print(f"example.py: cfg['config.sub.sub.message'] = {cfg.get('config.sub.sub.message', 'NOT_FOUND')}")
|
|
108
|
-
print(f"example.py: cfg['config.sub.sub.message2'] = {cfg.get('config.sub.sub.message2', 'NOT_FOUND')}")
|
|
109
|
-
print(f"example.py: cfg['config.sub.multiline_string'] = {cfg.get('config.sub.multiline_string', 'NOT_FOUND')}")
|
|
110
|
-
|
|
111
|
-
# Test mixed table access (indexed and named elements)
|
|
112
|
-
print(f"example.py: table start for config.sub.mixed: {cfg.get_table_start('config.sub.mixed')}")
|
|
113
|
-
print(f"example.py: table end for config.sub.mixed: {cfg.get_table_end('config.sub.mixed')}")
|
|
114
|
-
print(f"example.py: table indices sequence for config.sub.mixed: {cfg.get_table_seq('config.sub.mixed')}")
|
|
115
|
-
print(f"example.py: cfg['config.sub.mixed.1'] = {cfg.get('config.sub.mixed.1', 'NOT_FOUND')}")
|
|
116
|
-
print(f"example.py: cfg['config.sub.mixed.2'] = {cfg.get('config.sub.mixed.2', 'NOT_FOUND')}")
|
|
117
|
-
print(f"example.py: cfg['config.sub.mixed.3'] = {cfg.get('config.sub.mixed.3', 'NOT_FOUND')}")
|
|
118
|
-
print(f"example.py: cfg['config.sub.mixed.4'] = {cfg.get('config.sub.mixed.4', 'NOT_FOUND')}")
|
|
119
|
-
print(f"example.py: cfg['config.sub.mixed.key'] = {cfg.get('config.sub.mixed.key', 'NOT_FOUND')}")
|
|
120
|
-
|
|
121
|
-
# Show extra cmdline parameters passed to lua script as loader.args table and assigned to config.sub.loader_args
|
|
122
|
-
print(f"example.py: config.sub.loader_args indices sequence: {cfg.get_table_seq('config.sub.loader_args')}")
|
|
123
|
-
for i in cfg.get_table_seq('config.sub.loader_args'):
|
|
124
|
-
print(f"example.py: cfg['config.sub.loader_args.{i}'] = {cfg.get(f'config.sub.loader_args.{i}', 'NOT_FOUND')}")
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{python_lua_helper-1.0.1 → python_lua_helper-1.2.0}/python_lua_helper/test_example/example.post.lua
RENAMED
|
File without changes
|
{python_lua_helper-1.0.1 → python_lua_helper-1.2.0}/python_lua_helper/test_example/example.pre.lua
RENAMED
|
File without changes
|