Improving bindings for binary operators and static functions

This commit is contained in:
Pavel Shevaev 2023-10-13 18:52:12 +03:00
parent cd57c03761
commit 0e1fd074ed
1 changed files with 16 additions and 7 deletions

View File

@ -1,21 +1,27 @@
{%- macro reg_func_native(o, scope = 'types.ns', this_prefix = '', this_type = null) ~%}
{%- macro reg_func_native(o, scope = 'types.ns', this_prefix = '', this_type = null, fname = null) ~%}
{
var fn =
{{ _self.func_native(o, this_prefix, this_type) }}
{{ _self.func_native(o, fname ? fname|trim('"') : o.name|ns_last, this_prefix, this_type) }}
;
{{scope}}.{{o.name|ns_prefix}}Define(fn);
}
{%- endmacro -%}
{%- macro func_native(o, this_prefix = '', this_type = null) ~%}
{%- macro func_native(o, fname, this_prefix = '', this_type = null) ~%}
new FuncSymbolNative(new Origin(), "{{o.name|ns_last}}",
new FuncSymbolNative(new Origin(), "{{fname|trim('"')}}",
FuncAttrib.None
{%- if has_token(o, 'bhl_coroutine') -%}
FuncAttrib.Coro,
| FuncAttrib.Coro
{%- endif ~%}
{%- if has_token(o, 'bhl_static') -%}
| FuncAttrib.Static
{%- endif ~%}
,
{{ o.returntype|bhl_type_ref }},
{{ count_default_args(o) }},
@ -643,10 +649,13 @@ Script_{{o.name|norm_name}}.Method_{{m.name}}.ReturnValue(frm, stack
{% for m in o.getfuncs %}
{% if has_token(m, 'bhl_native_prefix') %}
{% if has_token(m, 'bhl_static') %}
{{ _self.reg_func_native(m, 'cl', '', o) }}
{{ _self.reg_func_native(m, 'cl', '') }}
{% else %}
{{ _self.reg_func_native(m, 'cl', '__self.', o) }}
{% endif %}
{% if has_token(m, 'bhl_bin_op') %}
{{ _self.reg_func_native(m, 'cl', '', null, token(m, 'bhl_bin_op')) }}
{% endif %}
{% else %}
{{ _self.method_partial(o, m, 'cl') }}
{% endif %}
@ -733,7 +742,7 @@ Script_{{o.name|norm_name}}.Method_{{m.name}}.ReturnValue(frm, stack
#endif
, funcs: new FuncSymbol[] {
{% for m in o.getfuncs %}
{{ _self.func_native(m, '__self.', o) }},
{{ _self.func_native(m, m.name, '__self.', o) }},
{% endfor %}
}
);