Commit 31b0f658 authored by Jürg Rast's avatar Jürg Rast Committed by oroulet

Fixed code generator for structures and enums

parent 018c93bb
......@@ -83,12 +83,15 @@ class {self.name}:
"""
for sfield in self.fields:
uatype = f"ua.{sfield.uatype}"
uatype = f"'ua.{sfield.uatype}'"
if sfield.array:
uatype = f"List[{uatype}]"
if uatype == 'List[ua.Char]':
uatype = 'String'
code += f" {sfield.name}:{uatype} = {sfield.value}\n"
uavalue = sfield.value
if isinstance(uavalue, str) and uavalue.startswith("ua."):
uavalue = f"field(default_factory=lambda: {uavalue})"
code += f" {sfield.name}:{uatype} = {uavalue}\n"
return code
......@@ -168,6 +171,8 @@ class StructGenerator(object):
def _make_registration(self):
code = "\n\n"
for struct in self.model:
if isinstance(struct, EnumType):
continue # No registration required for enums
code += f"ua.register_extension_object('{struct.name}'," \
f" ua.NodeId.from_string('{struct.typeid}'), {struct.name})\n"
return code
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment