Python: Fix access to globals when there's more than one

The getter for the global didn't capture the correct global_class,
just the last iteration.

This fixes the broken printer demo.
This commit is contained in:
Simon Hausmann 2024-07-11 21:59:36 +02:00
parent 86cde942b7
commit 0b6381d012
3 changed files with 15 additions and 5 deletions

View file

@ -178,11 +178,15 @@ def _build_class(compdef):
for global_name in compdef.globals:
global_class = _build_global_class(compdef, global_name)
def global_getter(self):
wrapper = global_class()
setattr(wrapper, "__instance__", self.__instance__)
return wrapper
properties_and_callbacks[global_name] = property(global_getter)
def mk_global(global_class):
def global_getter(self):
wrapper = global_class()
setattr(wrapper, "__instance__", self.__instance__)
return wrapper
return property(global_getter)
properties_and_callbacks[global_name] = mk_global(global_class)
return type("SlintClassWrapper", (Component,), properties_and_callbacks)

View file

@ -45,6 +45,8 @@ def test_load_file_wrapper():
assert instance.MyGlobal.minus_one(100) == 99
assert instance.SecondGlobal.second == "second"
del instance

View file

@ -9,6 +9,10 @@ export global MyGlobal {
}
}
export global SecondGlobal {
out property <string> second: "second";
}
export component App inherits Window {
in-out property <string> hello: "World";
callback say-hello(string) -> string;