Separate register into different methods

This commit is contained in:
wrenge 2023-02-13 13:52:37 +03:00
parent e4ab175143
commit 62f61e4674
3 changed files with 56 additions and 1 deletions

View File

@ -220,6 +220,44 @@ function add_twig_support(\Twig\Environment $twig)
return $arr;
}
));
$twig->addFunction(new \Twig\TwigFunction('slice_units',
function(array $units, $max)
{
$pages = paginate(sizeof($units), $max);
$sliced = array();
$units_keys = array_keys($units);
foreach($pages as $idx => $page)
{
$slice = array();
for($i = $page[0];$i<$page[1];++$i)
{
$slice[] = $units[$units_keys[$i]];
}
$sliced[$idx] = $slice;
}
return $sliced;
}
));
}
function paginate($total, $step)
{
//pages are returned as an array where each element is in interval [N, Y)
$pages = array();
$steps = (int)($total/$step);
$rest = $total % $step;
for($i=1;$i<=$steps;++$i)
$pages[] = array(($i-1)*$step, $i*$step);
if($rest != 0)
$pages[] = array(($i-1)*$step, ($i-1)*$step + $rest);
return $pages;
}
function ns_last($name)

View File

@ -27,10 +27,12 @@ public static void Register(Types types)
BHL_Types.Type_GenericArray = new GenericArrayTypeSymbol(new Proxy<IType>());
{% block register %}
{{ macro.reg_units(meta.units) }}
{{ macro.call_reg_units(slice_units(meta.units, 20)) }}
{% endblock %}
}
{{ macro.decl_reg_units(slice_units(meta.units, 20)) }}
}
} //namespace bhl

View File

@ -977,6 +977,21 @@ public partial class Script_{{u.object.name}} {
{%- endmacro -%}
{%- macro call_reg_units(sliced_units) ~%}
{%- for idx,units in sliced_units -%}
Register_{{idx}}(types);
{%~ endfor -%}
{%- endmacro -%}
{%- macro decl_reg_units(sliced_units) ~%}
{%- for idx,units in sliced_units -%}
public static void Register_{{idx}}(Types types)
{
{{ _self.reg_units(units) }}
}
{%~ endfor -%}
{%- endmacro -%}
{%- macro reg_units(units) ~%}
{%- for u in units -%}