cs_accessor_interface (and similar tokens) now support pre-existing C# interfaces
This commit is contained in:
parent
728d6b2cf9
commit
f7d0b5f61f
|
@ -136,10 +136,10 @@ function _add_twig_support(\Twig\Environment $twig)
|
|||
return get_diff_related_units($o);
|
||||
}
|
||||
));
|
||||
$twig->addFunction(new \Twig\TwigFunction('get_all_accessor_interfaces',
|
||||
$twig->addFunction(new \Twig\TwigFunction('get_all_declarable_accessor_interfaces',
|
||||
function($o)
|
||||
{
|
||||
return get_all_accessor_interfaces($o);
|
||||
return get_all_declarable_accessor_interfaces($o);
|
||||
}
|
||||
));
|
||||
$twig->addFunction(new \Twig\TwigFunction('get_accessor_interfaces',
|
||||
|
@ -536,9 +536,26 @@ class AccessorInterface
|
|||
}
|
||||
}
|
||||
|
||||
//NOTE: by default, accessor interface declarations will be generated in the autogen bundle.
|
||||
//If you want your metagen struct to implement some existing C# inteface
|
||||
//use quotes and prefix the fully-qualified interface name with "!", e.g. like this:
|
||||
//
|
||||
// ticket : string @cs_accessor_interface:"!BitGames.ServerIntegration.IRpcWithAuth"
|
||||
//
|
||||
function get_accessor_interfaces(\mtgMetaStruct $struct)
|
||||
{
|
||||
return get_accessor_interfaces_ex($struct, /* declarable_only = */ false);
|
||||
}
|
||||
|
||||
function get_accessor_interfaces_declarable(\mtgMetaStruct $struct)
|
||||
{
|
||||
return get_accessor_interfaces_ex($struct, /* declarable_only = */ true);
|
||||
}
|
||||
|
||||
function get_accessor_interfaces_ex(\mtgMetaStruct $struct, $declarable_only)
|
||||
{
|
||||
$ifs = array();
|
||||
$external_mark = '"!';
|
||||
foreach($struct->getFields() as $field)
|
||||
{
|
||||
$is_accessor = $field->hasToken('cs_accessor_interface');
|
||||
|
@ -558,6 +575,14 @@ function get_accessor_interfaces(\mtgMetaStruct $struct)
|
|||
elseif($is_propgetset)
|
||||
$ai->cs_interface_name = $field->getToken('cs_propgetset_interface');
|
||||
|
||||
$is_external = strpos($ai->cs_interface_name, $external_mark) === 0;
|
||||
if($is_external)
|
||||
{
|
||||
$ai->cs_interface_name = trim($ai->cs_interface_name, $external_mark);
|
||||
if($declarable_only)
|
||||
continue;
|
||||
}
|
||||
|
||||
if(array_key_exists($ai->getUID(), $ifs))
|
||||
$ai = $ifs[$ai->getUID()];
|
||||
|
||||
|
@ -578,17 +603,17 @@ function get_accessor_interfaces(\mtgMetaStruct $struct)
|
|||
return $ifs;
|
||||
}
|
||||
|
||||
function get_all_accessor_interfaces(\mtgMetaInfo $info)
|
||||
function get_all_declarable_accessor_interfaces(\mtgMetaInfo $info)
|
||||
{
|
||||
$all = array();
|
||||
foreach($info->getUnits() as $unit)
|
||||
{
|
||||
if($unit->object instanceof \mtgMetaStruct)
|
||||
$all = array_merge($all, get_accessor_interfaces($unit->object));
|
||||
$all = array_merge($all, get_accessor_interfaces_declarable($unit->object));
|
||||
else if($unit->object instanceof \mtgMetaRPC)
|
||||
{
|
||||
$all = array_merge($all, get_accessor_interfaces($unit->object->getReq()));
|
||||
$all = array_merge($all, get_accessor_interfaces($unit->object->getRsp()));
|
||||
$all = array_merge($all, get_accessor_interfaces_declarable($unit->object->getReq()));
|
||||
$all = array_merge($all, get_accessor_interfaces_declarable($unit->object->getRsp()));
|
||||
}
|
||||
}
|
||||
return $all;
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
{%- endif ~%}
|
||||
{%- endfor ~%}
|
||||
|
||||
{%- for ai in get_all_accessor_interfaces(meta) ~%}
|
||||
{%- for ai in get_all_declarable_accessor_interfaces(meta) ~%}
|
||||
{{ _self.decl_accessor_interface(ai) }}
|
||||
{%- endfor ~%}
|
||||
|
||||
|
|
Loading…
Reference in New Issue