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') -%}