初始化工程
This commit is contained in:
23
Config/Tools/Luban/Templates/common/cpp/enum.sbn
Normal file
23
Config/Tools/Luban/Templates/common/cpp/enum.sbn
Normal file
@@ -0,0 +1,23 @@
|
||||
{{~
|
||||
comment = __enum.comment
|
||||
items = __enum.items
|
||||
~}}
|
||||
{{namespace_with_grace_begin __namespace}}
|
||||
{{~if comment != '' ~}}
|
||||
/// <summary>
|
||||
/// {{escape_comment comment}}
|
||||
/// </summary>
|
||||
{{~end~}}
|
||||
enum class {{__name}}
|
||||
{
|
||||
{{~ for item in items ~}}
|
||||
{{~if item.comment != '' ~}}
|
||||
/// <summary>
|
||||
/// {{escape_comment item.comment_or_alias}}
|
||||
/// </summary>
|
||||
{{~end~}}
|
||||
{{format_enum_item_name __code_style item.name}} = {{item.value}},
|
||||
{{~end~}}
|
||||
};
|
||||
|
||||
{{namespace_with_grace_end __namespace}}
|
||||
28
Config/Tools/Luban/Templates/common/cs/enum.sbn
Normal file
28
Config/Tools/Luban/Templates/common/cs/enum.sbn
Normal file
@@ -0,0 +1,28 @@
|
||||
{{~
|
||||
comment = __enum.comment
|
||||
items = __enum.items
|
||||
~}}
|
||||
|
||||
|
||||
{{namespace_with_grace_begin __namespace_with_top_module}}
|
||||
{{~if comment != '' ~}}
|
||||
/// <summary>
|
||||
/// {{escape_comment comment}}
|
||||
/// </summary>
|
||||
{{~end~}}
|
||||
{{~if __enum.is_flags~}}
|
||||
[System.Flags]
|
||||
{{~end~}}
|
||||
public enum {{__name}}
|
||||
{
|
||||
{{~ for item in items ~}}
|
||||
{{~if item.comment != '' ~}}
|
||||
/// <summary>
|
||||
/// {{escape_comment item.comment_or_alias}}
|
||||
/// </summary>
|
||||
{{~end~}}
|
||||
{{format_enum_item_name __code_style item.name}} = {{item.value}},
|
||||
{{~end~}}
|
||||
}
|
||||
|
||||
{{namespace_with_grace_end __namespace_with_top_module}}
|
||||
30
Config/Tools/Luban/Templates/common/dart/enum.sbn
Normal file
30
Config/Tools/Luban/Templates/common/dart/enum.sbn
Normal file
@@ -0,0 +1,30 @@
|
||||
{{~if __this.comment != '' ~}}
|
||||
//{{escape_comment __this.comment}}
|
||||
{{~end~}}
|
||||
enum {{__name}}
|
||||
{
|
||||
{{~if !has_enum_item __this~}}
|
||||
empty_placeholder(0);
|
||||
{{~else~}}
|
||||
{{~if !__this.has_zero_value_item ~}}
|
||||
None(0),
|
||||
{{~end~}}
|
||||
{{~end~}}
|
||||
|
||||
|
||||
{{~ for item in __this.items ~}}
|
||||
{{~if item.comment_or_alias != '' ~}}
|
||||
//{{escape_comment item.comment_or_alias}}
|
||||
{{~end~}}
|
||||
{{item.name}}({{item.int_value}}) {{is_last_enum_item __this item.int_value ? ';' : ','}}
|
||||
|
||||
{{~end~}}
|
||||
final int value;
|
||||
|
||||
const {{__name}}(this.value);
|
||||
|
||||
static {{__name}} fromValue(int value)
|
||||
{
|
||||
return {{__name}}.values.firstWhere((element) => element.value == value, orElse: () => fromValue(0));
|
||||
}
|
||||
}
|
||||
19
Config/Tools/Luban/Templates/common/go/enum.sbn
Normal file
19
Config/Tools/Luban/Templates/common/go/enum.sbn
Normal file
@@ -0,0 +1,19 @@
|
||||
{{~if ___top_module != ''~}}
|
||||
package {{__top_module}};
|
||||
{{~end~}}
|
||||
|
||||
{{~if __this.comment != '' ~}}
|
||||
/**
|
||||
* {{escape_comment __this.comment}}
|
||||
*/
|
||||
{{~end~}}
|
||||
const (
|
||||
{{~ for item in __this.items ~}}
|
||||
{{~if item.comment_or_alias != '' ~}}
|
||||
/**
|
||||
* {{escape_comment item.comment_or_alias}}
|
||||
*/
|
||||
{{~end~}}
|
||||
{{full_name __this}}_{{item.name}} = {{item.int_value}};
|
||||
{{~end~}}
|
||||
)
|
||||
19
Config/Tools/Luban/Templates/common/java/enum.sbn
Normal file
19
Config/Tools/Luban/Templates/common/java/enum.sbn
Normal file
@@ -0,0 +1,19 @@
|
||||
{{~if __namespace_with_top_module != ''~}}
|
||||
package {{__namespace_with_top_module}};
|
||||
{{~end~}}
|
||||
|
||||
{{~if __this.comment != '' ~}}
|
||||
/**
|
||||
* {{escape_comment __this.comment}}
|
||||
*/
|
||||
{{~end~}}
|
||||
public final class {{__name}} {
|
||||
{{~ for item in __this.items ~}}
|
||||
{{~if item.comment_or_alias != '' ~}}
|
||||
/**
|
||||
* {{escape_comment item.comment_or_alias}}
|
||||
*/
|
||||
{{~end~}}
|
||||
public static final int {{item.name}} = {{item.int_value}};
|
||||
{{~end~}}
|
||||
}
|
||||
2
Config/Tools/Luban/Templates/common/php/enum.sbn
Normal file
2
Config/Tools/Luban/Templates/common/php/enum.sbn
Normal file
@@ -0,0 +1,2 @@
|
||||
|
||||
|
||||
14
Config/Tools/Luban/Templates/common/rs/macros/Cargo.toml.sbn
Normal file
14
Config/Tools/Luban/Templates/common/rs/macros/Cargo.toml.sbn
Normal file
@@ -0,0 +1,14 @@
|
||||
[package]
|
||||
name = "macros"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
quote = "1.0.36"
|
||||
syn = "2.0.60"
|
||||
proc-macro2 = "1.0.82"
|
||||
|
||||
[lib]
|
||||
proc-macro = true
|
||||
65
Config/Tools/Luban/Templates/common/rs/macros/src/lib.rs.sbn
Normal file
65
Config/Tools/Luban/Templates/common/rs/macros/src/lib.rs.sbn
Normal file
@@ -0,0 +1,65 @@
|
||||
#[macro_use]
|
||||
extern crate quote;
|
||||
|
||||
use proc_macro::TokenStream;
|
||||
use proc_macro2;
|
||||
use quote::{format_ident, quote, ToTokens};
|
||||
use syn::{parse_macro_input, Data, DeriveInput};
|
||||
|
||||
#[proc_macro_derive(TryIntoBase)]
|
||||
pub fn base_try_from(item: TokenStream) -> TokenStream {
|
||||
let derive_input = parse_macro_input!(item as DeriveInput);
|
||||
let ty_name = &derive_input.ident;
|
||||
|
||||
match derive_input.data {
|
||||
Data::Struct(_) => {}
|
||||
_ => panic!("base_try_from can only be used on structs or enums"),
|
||||
}
|
||||
|
||||
let expanded = quote! {
|
||||
impl<'a> TryFrom<&'a AbstractBase> for &'a #ty_name {
|
||||
type Error = String;
|
||||
|
||||
fn try_from(value: &'a AbstractBase) -> Result<Self, Self::Error> {
|
||||
let r = value.downcast_ref::<#ty_name>();
|
||||
if let Some(v) = r {
|
||||
return Ok(v);
|
||||
}
|
||||
|
||||
Err(concat!("can not into to ", stringify!(#ty_name)).to_string())
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
TokenStream::from(expanded)
|
||||
}
|
||||
|
||||
#[proc_macro_derive(EnumFromNum)]
|
||||
pub fn enum_from_num(input: TokenStream) -> TokenStream {
|
||||
let input = parse_macro_input!(input as DeriveInput);
|
||||
let ty_name = &input.ident;
|
||||
|
||||
|
||||
let tokens = vec![
|
||||
format_ident!("i64"),
|
||||
format_ident!("i16"),
|
||||
format_ident!("i8"),
|
||||
format_ident!("isize"),
|
||||
format_ident!("u64"),
|
||||
format_ident!("u32"),
|
||||
format_ident!("u16"),
|
||||
format_ident!("u8"),
|
||||
format_ident!("usize"),
|
||||
format_ident!("f64"),
|
||||
format_ident!("f32"),
|
||||
];
|
||||
quote! {
|
||||
#(
|
||||
impl From<#tokens> for #ty_name {
|
||||
fn from(value: #tokens) -> Self {
|
||||
(value as i32).into()
|
||||
}
|
||||
}
|
||||
)*
|
||||
}.into()
|
||||
}
|
||||
2
Config/Tools/Luban/Templates/common/ts/enum.sbn
Normal file
2
Config/Tools/Luban/Templates/common/ts/enum.sbn
Normal file
@@ -0,0 +1,2 @@
|
||||
|
||||
|
||||
Reference in New Issue
Block a user