From a8ebe821be1f3cb60b25e9bdf4243cbf5150b576 Mon Sep 17 00:00:00 2001 From: Pavel Shevaev Date: Thu, 4 Jul 2024 16:35:05 +0300 Subject: [PATCH] Improving setting up of array-like native values for cases when they are null --- tpl/bhl_bind_macro.twig | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/tpl/bhl_bind_macro.twig b/tpl/bhl_bind_macro.twig index 86163b1..8b8d292 100644 --- a/tpl/bhl_bind_macro.twig +++ b/tpl/bhl_bind_macro.twig @@ -407,11 +407,22 @@ Script_{{o.name|norm_name}}.Method_{{m.name}}.ReturnValue(frm, stack {%- endif -%} {%- if type is instanceof('\\mtgArrType') -%} + var _arr_type = (ArrayTypeSymbol){{value}}.type; + int _native_before_count = 0; + {%- if type == 'any[]'-%} {{native}} = ValList.New(frm.vm); + {%~ else ~%} + try + { + _native_before_count = {{native}}.Count; + } + catch(NullReferenceException) + { + {{native}} = new(); + } {%~ endif -%} - var _arr_type = (ArrayTypeSymbol){{value}}.type; - int _native_before_count = {{native}}.Count; + for(int i=0;i<_arr_type.ArrCount({{value}});++i) { var _arr_item = _arr_type.ArrGetAt({{value}}, i);