diff --git a/Assets/CodeGen/BMapBinder/ExpFctsRender/templates/expfcts.rs.jinja b/Assets/CodeGen/BMapBinder/ExpFctsRender/templates/expfcts.rs.jinja index e69de29..fbb0b74 100644 --- a/Assets/CodeGen/BMapBinder/ExpFctsRender/templates/expfcts.rs.jinja +++ b/Assets/CodeGen/BMapBinder/ExpFctsRender/templates/expfcts.rs.jinja @@ -0,0 +1,14 @@ +{%- for fct in payload.fcts %} +/// {{ fct.fct_name }} +/// +/// # Parameters +/// +{%- for param in fct.fct_params %} +/// - `{{ param.var_name }}`: Direction: {% if param.is_input -%} input {%- else -%} output {%- endif %}. C++ type: `{{ param.var_type.to_c_type() }}`. {{ param.var_desc }} +{%- endfor %} +/// +/// # Return +/// +/// True if no error, otherwise False. +pub unsafe fn {{ fct.fct_name }}() -> bool; +{%- endfor %} diff --git a/Assets/CodeGen/EnumsMigration/EnumsRender/template_render.py b/Assets/CodeGen/EnumsMigration/EnumsRender/template_render.py index 7285f6f..8974bb9 100644 --- a/Assets/CodeGen/EnumsMigration/EnumsRender/template_render.py +++ b/Assets/CodeGen/EnumsMigration/EnumsRender/template_render.py @@ -83,6 +83,25 @@ class RenderUtils: """ return RenderUtils.REGEX_CS_TO_LITERAL_NUMBER.sub("", numstr, 1) + @staticmethod + def to_rs_num_literal(numstr: str) -> str: + """ + Convert given string into Rust number literal style. + + Number literal declaration in Rust is slightly different with C++. + C++ support U and L but Rust use another complete suffix mode to decide the type of numeric literal (u32, i32 and etc). + However, Rust can properly deduce the correct type of number literal, + so we just need simply remove any suffix. + + This function is only served for C# code generation. + + :param numstr: The captured number. + :return: The Rust style number string. + """ + # We reuse existing function + return RenderUtils.to_py_num_literal(numstr) + + REGEX_PY_EXT_HUMANRDABLE_ENTRY_NAME: typing.ClassVar[re.Pattern] = re.compile("^[a-zA-Z0-9]+_") @staticmethod diff --git a/Assets/CodeGen/EnumsMigration/EnumsRender/templates/generic.rs.jinja b/Assets/CodeGen/EnumsMigration/EnumsRender/templates/generic.rs.jinja index e69de29..c76af08 100644 --- a/Assets/CodeGen/EnumsMigration/EnumsRender/templates/generic.rs.jinja +++ b/Assets/CodeGen/EnumsMigration/EnumsRender/templates/generic.rs.jinja @@ -0,0 +1,32 @@ +{%- for benum in payload.iter_enums() %} +{%- if benum.get_enum_comment() is not none %} +{{ benum.get_enum_comment() | block_comment('/// ') }} +{%- endif %} +{%- if not benum.get_use_flags() %} +#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] +#[repr({% if benum.get_can_unsigned() -%} u32 {%- else -%} i32 {%- endif %})] +pub enum {{ benum.get_enum_name() }} { + {%- for entry in benum.iter_entries() %} + {%- if entry.get_entry_comment() is not none %} + /// {{ entry.get_entry_comment() | line_comment }} + {%- endif %} + {{ entry.get_entry_name() }} {%- if entry.get_entry_value() is not none %} = {{ utils.to_py_num_literal(entry.get_entry_value()) }} {%- endif %}, + {%- endfor %} +} +{%- else %} +#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] +#[repr(transparent)] +pub struct {{ benum.get_enum_name() }}({% if benum.get_can_unsigned() -%} u32 {%- else -%} i32 {%- endif %}); + +bitflags! { + impl {{ benum.get_enum_name() }}: {% if benum.get_can_unsigned() -%} u32 {%- else -%} i32 {%- endif %} { + {%- for entry in benum.iter_entries() %} + {%- if entry.get_entry_comment() is not none %} + /// {{ entry.get_entry_comment() | line_comment }} + {%- endif %} + const {{ entry.get_entry_name() }} {%- if entry.get_entry_value() is not none %} = {{ utils.to_py_num_literal(entry.get_entry_value()) }} {%- endif %}; + {%- endfor %} + } +} +{%- endif %} +{%- endfor %}