Adding @bhl_blob support
Publish PHP Package / docker (push) Successful in 6s Details

This commit is contained in:
Pavel Shevaev 2024-11-22 17:45:29 +03:00
parent 635095c3fb
commit 2c87ea219b
2 changed files with 44 additions and 19 deletions

View File

@ -20,7 +20,8 @@ function supported_tokens()
'bhl_get',
'bhl_set',
'bhl_ref_arg',
'bhl_bin_op'
'bhl_bin_op',
'bhl_blob',
];
}
@ -223,6 +224,14 @@ function add_twig_support(\Twig\Environment $twig)
return native_type($type);
}
));
$twig->addFilter(new \Twig\TwigFilter('native_class_name',
function($type)
{
if($type->hasToken('bhl_native_class'))
return $type->getToken('bhl_native_class');
return $type->getName();
}
));
$twig->addFilter(new \Twig\TwigFilter('norm_name',
function($name)
{

View File

@ -354,7 +354,7 @@ Script_{{o.name|norm_name}}.Method_{{m.name}}.ReturnValue(frm, stack
{%- if has_token(arg, 'bhl_ref_arg') ~%}
var dv = stack.Pop();
{{arg_prefix}}{{arg.name}} = dv;
{%- if not has_token(arg.type, 'bhl_custom_rw') -%}
{%- if not has_token(arg.type, 'bhl_custom_rw') and not has_token(arg.type, 'bhl_blob') -%}
{{ _self.val2native(arg.type, 'dv', arg_prefix ~ 'ref_' ~ arg.name, true) }};
{%- endif ~%}
{%- else ~%}
@ -533,12 +533,14 @@ Script_{{o.name|norm_name}}.Method_{{m.name}}.ReturnValue(frm, stack
{%- if type is instanceof('\\mtgUserType') -%}
{%- if type is instanceof('\\mtgMetaEnum') -%}
{{native}} = ({{token_or(type, 'bhl_native_class', type.name)}})((int){{value}}._num)
{{native}} = ({{type|native_class_name}})((int){{value}}._num)
{%- else -%}
{%- if has_token(type, 'bhl_custom_rw') -%}
var tmp = new {{token_or(type, 'bhl_native_class', type.name)}}(); {{value}}.Decode(ref tmp); {{native}} = tmp
var tmp = new {{type|native_class_name}}(); {{value}}.Decode(ref tmp); {{native}} = tmp
{%- elseif has_token(type, 'bhl_blob') -%}
{{native}} = {{value}}.GetBlob<{{type|native_class_name}}>()
{%- else -%}
{{native}} = ({{token_or(type, 'bhl_native_class', type.name)}}){{value}}._obj
{{native}} = ({{type|native_class_name}}){{value}}._obj
{%- endif -%}
{%- endif -%}
{%- endif -%}
@ -593,6 +595,8 @@ Script_{{o.name|norm_name}}.Method_{{m.name}}.ReturnValue(frm, stack
{%- else -%}
{%- if has_token(type, 'bhl_custom_rw') -%}
{{value}}.Encode({{native}})
{%- elseif has_token(type, 'bhl_blob') -%}
{{value}}.SetBlob({{native}}, Types_{{type.name|norm_name}}.Value)
{%- else -%}
{{value}}.SetObj({{native}}, Types_{{type.name|norm_name}}.Value)
{%- endif -%}
@ -644,7 +648,7 @@ Script_{{o.name|norm_name}}.Method_{{m.name}}.ReturnValue(frm, stack
{
var en = new EnumSymbolNative(new Origin(), "{{o.name|ns_last}}"
#if !BHL_FRONT
, typeof({{token_or(o, 'bhl_native_class', o.name)}})
, typeof({{o|native_class_name}})
#else
, null
#endif
@ -677,14 +681,16 @@ Script_{{o.name|norm_name}}.Method_{{m.name}}.ReturnValue(frm, stack
{% if not has_token(o, 'bhl_no_new') ~%}
static void ctor_{{o.name|norm_name}}(VM.Frame frm, ref Val v, IType type) {
#if !BHL_FRONT
var o = new {{token_or(o, 'bhl_native_class', o.name)}}({{token_or(o, 'bhl_native_class_params', '')}});
{%if has_token(o, 'bhl_custom_rw') %}
v.Encode(o);
{% else %}
var o = new {{o|native_class_name}}({{token_or(o, 'bhl_native_class_params', '')}});
{% if has_token(o, 'POD') %}
o.Reset();
o.Reset(); //resetting POD
{% endif %}
{% if has_token(o, 'bhl_custom_rw') %}
v.Encode(o);
{% elseif has_token(o, 'bhl_blob') %}
v.SetBlob(ref o, type);
{% else %}
v.SetObj(o, type);
{% endif %}
#endif
@ -713,20 +719,24 @@ Script_{{o.name|norm_name}}.Method_{{m.name}}.ReturnValue(frm, stack
creator: ctor_{{o.name|norm_name}}
{% endif ~%}
#if !BHL_FRONT
, native_type: typeof({{token_or(o, 'bhl_native_class', o.name)}})
, native_type: typeof({{o|native_class_name}})
{% if has_token(o, 'bhl_custom_rw') %}
, native_object_getter: (v) => {
var tmp = new {{token_or(o, 'bhl_native_class', o.name)}}();
var tmp = new {{o|native_class_name}}();
v.Decode(ref tmp);
return tmp;
}
{% elseif has_token(o, 'bhl_blob') %}
, native_object_getter: (v) => {
return v.GetBlob<{{o|native_class_name}}>();
}
{% endif %}
#endif
);
{{scope}}.{{o.name|ns_prefix}}Define(cl);
{% if has_token(o, 'POD') and not has_token(o, 'bhl_custom_rw') %}
{{Warn("POD boxing '" ~ o.name ~ "'")}}
{% if has_token(o, 'POD') and not has_token(o, 'bhl_custom_rw') and not has_token(o, 'bhl_blob') %}
{{Warn("POD boxing '" ~ o.name ~ " (use @bhl_custom_rw or @bhl_blob)'")}}
{% endif %}
{% for f in o.getfields %}
@ -754,7 +764,7 @@ Script_{{o.name|norm_name}}.Method_{{m.name}}.ReturnValue(frm, stack
{%- macro class_field(o, f) -%}
{% set class = token_or(o, 'bhl_native_class', o.name) %}
{% set class = o|native_class_name %}
{
{% if token_or(f, 'bhl_get', 1) != 0 ~%}
@ -763,8 +773,10 @@ Script_{{o.name|norm_name}}.Method_{{m.name}}.ReturnValue(frm, stack
{%~ if has_token(o, 'bhl_custom_rw') ~%}
{{class}} f = new {{class}}();
ctx.Decode(ref f);
{%- elseif has_token(o, 'bhl_blob') ~%}
ref var f = ref ctx.GetBlob<{{class}}>();
{%- else ~%}
var f = ({{class}})ctx.obj;
var f = ({{class}})ctx._obj;
{%- endif ~%}
{% if token(f, 'bhl_get') == 2 %}
@ -787,6 +799,8 @@ Script_{{o.name|norm_name}}.Method_{{m.name}}.ReturnValue(frm, stack
{%~ if has_token(o, 'bhl_custom_rw') ~%}
{{class}} f = new {{class}}();
ctx.Decode(ref f);
{%- elseif has_token(o, 'bhl_blob') ~%}
ref var f = ref ctx.GetBlob<{{class}}>();
{%- else ~%}
var f = ({{class}})ctx.obj;
{%- endif ~%}
@ -804,6 +818,8 @@ Script_{{o.name|norm_name}}.Method_{{m.name}}.ReturnValue(frm, stack
{%~ if has_token(o, 'bhl_custom_rw') ~%}
ctx.Encode(f);
{%~ elseif has_token(o, 'bhl_blob') ~%}
//nothing for blob
{%- else ~%}
ctx.SetObj(f, ctx.type);
{%- endif ~%}
@ -843,7 +859,7 @@ Script_{{o.name|norm_name}}.Method_{{m.name}}.ReturnValue(frm, stack
var ifs = new InterfaceSymbolNative(new Origin(), "{{o.name|ns_last}}", proxy_inherits: null
#if !BHL_FRONT
, native_type: typeof({{token_or(o, 'bhl_native_class', o.name)}})
, native_type: typeof({{o|native_class_name}})
#else
, native_type: null
#endif