From 5e870a397369105daef12da741b696700b8cc731 Mon Sep 17 00:00:00 2001 From: Georgiy Sadovnikov Date: Fri, 28 Jun 2024 11:26:18 +0300 Subject: [PATCH] Fixing arrays assign code generation --- tpl/bhl_bind_macro.twig | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/tpl/bhl_bind_macro.twig b/tpl/bhl_bind_macro.twig index 5e37db7..86163b1 100644 --- a/tpl/bhl_bind_macro.twig +++ b/tpl/bhl_bind_macro.twig @@ -411,14 +411,19 @@ Script_{{o.name|norm_name}}.Method_{{m.name}}.ReturnValue(frm, stack {{native}} = ValList.New(frm.vm); {%~ endif -%} var _arr_type = (ArrayTypeSymbol){{value}}.type; - {{native}}.Clear(); + int _native_before_count = {{native}}.Count; for(int i=0;i<_arr_type.ArrCount({{value}});++i) { var _arr_item = _arr_type.ArrGetAt({{value}}, i); {#TODO: get rid of replace hack below#} {{('var ' ~ _self.val2native(type.value, '_arr_item', 'tmp'))|replace({'tmp = tmp' : '', 'var var' : 'var'})}}; - {{native}}.Add(tmp); + if(i < _native_before_count) + {{native}}[i] = tmp; + else + {{native}}.Add(tmp); } + while({{native}}.Count > _arr_type.ArrCount({{value}})) + {{native}}.RemoveAt({{native}}.Count-1); {%- endif -%} {%- if type is instanceof('\\mtgBuiltinType') -%}