Skip to content

Commit cb5816b

Browse files
committed
py_lua_helper: fix get_bool
1 parent ad99211 commit cb5816b

3 files changed

Lines changed: 8 additions & 3 deletions

File tree

python_lua_helper/py_lua_helper.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,12 @@ def get_bool(self, key: str, default: bool = None) -> bool:
394394
try:
395395
value_type = self.get_type(key)
396396
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)
398403
raise ValueError(f"Invalid value type: {value_type}")
399404
except ValueError:
400405
if default is not None:

python_lua_helper/test_example.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@
147147
# Test typed get
148148
print("example.py: === test getting values with specific type from config.sub.types table ===")
149149
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)}")
150+
print(f"example.py: get missing bool value, fallback: cfg['config.sub.types.b1'] = {cfg.get_bool('config.sub.types.b1', True)}")
151151
print(f"example.py: get bool value from int, fallback: cfg['config.sub.types.i'] = {cfg.get_bool('config.sub.types.i', False)}")
152152

153153
print(f"example.py: get int value, no fallback: cfg['config.sub.types.i'] = {cfg.get_int('config.sub.types.i')}")

python_lua_helper/test_example/example.cfg.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ config =
2727
mixed={ 1, "text", true, key="test_value" },
2828
empty_table={ },
2929
types = {
30-
b=true,
30+
b=false,
3131
i=100,
3232
f=99.99,
3333
s="string value",

0 commit comments

Comments
 (0)