diff --git a/tpl/bhl_bind_macro.twig b/tpl/bhl_bind_macro.twig index 2fe0698..3345a9a 100644 --- a/tpl/bhl_bind_macro.twig +++ b/tpl/bhl_bind_macro.twig @@ -956,18 +956,7 @@ public partial class Script_{{u.object.name}} { //assign global static types {%- for u in units -%} {%- if u.object is instanceof('\\mtgMetaStruct') or u.object is instanceof('\\mtgMetaInterface') ~%} - { - var tmp = types.T("{{u.object.name}}").Get(); - if(tmp == null) - throw new System.Exception("Type '{{u.object.name}}' not resolved"); - {%- if u.object is instanceof('\\mtgMetaStruct') ~%} - (tmp as ClassSymbolNative)?.Setup(); - {%- endif ~%} - {%- if u.object is instanceof('\\mtgMetaInterface') ~%} - (tmp as InterfaceSymbolNative)?.Setup(); - {%- endif ~%} - Types_{{u.object.name|norm_name}}.Value = tmp; - } + Types_{{u.object.name|norm_name}}.Value = SetupType(types, "{{u.object.name}}"); {%- endif -%} {%- endfor -%} diff --git a/tpl/codegen_register.twig b/tpl/codegen_register.twig index 7054fdd..3a34d69 100644 --- a/tpl/codegen_register.twig +++ b/tpl/codegen_register.twig @@ -45,6 +45,20 @@ public static void RegisterBegin(Types types) {%~ endfor -%} } +static IType SetupType(Types types, string name) +{ + var tmp = types.T(name).Get(); + if(tmp == null) + throw new System.Exception("Type '" + name + "' not resolved"); + + if(tmp is ClassSymbolNative csn) + csn.Setup(); + else if(tmp is InterfaceSymbolNative isn) + isn.Setup(); + + return tmp; +} + public static void RegisterEnd(Types types) { {{ macro.setup_global_types(meta.units) }}