fully compiles
This commit is contained in:
@@ -4,3 +4,8 @@ pub fn dyn_call(part_id: MizeId, method: &str, args: ItemData) -> MizeResult<Ite
|
||||
let mut mize = get_global_mize()?;
|
||||
mize.dyn_call(part_id, method, args)
|
||||
}
|
||||
|
||||
pub fn get_config(name: &str) -> MizeResult<ItemData> {
|
||||
let mut mize = get_global_mize()?;
|
||||
mize.get_config(name)
|
||||
}
|
||||
|
||||
@@ -31,10 +31,10 @@ pub mod prelude {
|
||||
pub use item::{Item, ItemData, IntoItemData};
|
||||
pub use config::*;
|
||||
pub use api::*;
|
||||
pub use super::include_native;
|
||||
pub use mize_macros::*;
|
||||
}
|
||||
pub use flume;
|
||||
pub use tracing;
|
||||
|
||||
|
||||
|
||||
@@ -133,82 +133,3 @@ pub mod platform {
|
||||
Ok("alsdkjf".to_owned())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////// include_native! macro /////////////////////////////////////
|
||||
// A macro to register methods of a foreign type (like clap::Command) with mize.
|
||||
// This generates bindings for the type to be stored in the native_values registry.
|
||||
|
||||
// Usage 1: New simplified syntax (string name, type path, list of method names)
|
||||
// ```ignore
|
||||
// include_native!("Command", clap::Command, [new, arg, subcommand]);
|
||||
// ```
|
||||
//
|
||||
// This expands to:
|
||||
// ```ignore
|
||||
// opt("Command")
|
||||
// .method("new", |args| {
|
||||
// let this = get_config("Command")?.native_mut::<clap::Command>()?;
|
||||
// let result = this.new();
|
||||
// Ok(from_native(result))
|
||||
// })
|
||||
// .method("arg", |args| {
|
||||
// let this = get_config("Command")?.native_mut::<clap::Command>()?;
|
||||
// let result = this.arg();
|
||||
// Ok(from_native(result))
|
||||
// })
|
||||
// .method("subcommand", |args| {
|
||||
// let this = get_config("Command")?.native_mut::<clap::Command>()?;
|
||||
// let result = this.subcommand();
|
||||
// Ok(from_native(result))
|
||||
// });
|
||||
// ```
|
||||
//
|
||||
// Usage 2: Traditional syntax (type path, method signatures in braces)
|
||||
// ```ignore
|
||||
// include_native!(clap::Command, {
|
||||
// fn arg(&mut self, arg: clap::Arg) -> &mut clap::Command;
|
||||
// fn subcommand(&mut self, cmd: clap::Command) -> &mut clap::Command;
|
||||
// });
|
||||
// ```
|
||||
//
|
||||
// This expands to:
|
||||
// ```ignore
|
||||
// opt("clap::Command")
|
||||
// .method("arg", |args| {
|
||||
// let arg = args.arr_nth(0)?.native::<clap::Arg>()?;
|
||||
// let this = get_config("clap::Command")?.native_mut::<clap::Command>()?;
|
||||
// let result = this.arg(arg);
|
||||
// Ok(from_native(result))
|
||||
// })
|
||||
// .method("subcommand", |args| {
|
||||
// let cmd = args.arr_nth(0)?.native::<clap::Command>()?;
|
||||
// let this = get_config("clap::Command")?.native_mut::<clap::Command>()?;
|
||||
// let result = this.subcommand(cmd);
|
||||
// Ok(from_native(result))
|
||||
// });
|
||||
// ```
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! include_native {
|
||||
// New simplified syntax: ("name", type_path, [method1, method2, ...])
|
||||
($name:literal, $type_path:ty, [$($method:ident),* $(,)?]) => {
|
||||
$crate::config::opt($name)
|
||||
$(
|
||||
.method(stringify!($method), |args| {
|
||||
let this = $crate::prelude::get_global_mize()?
|
||||
.get_config($name)?
|
||||
.native_mut::<$type_path>()?;
|
||||
let result = this.$method();
|
||||
Ok($crate::item::ItemData::from_native(result)?)
|
||||
})
|
||||
)*
|
||||
};
|
||||
|
||||
// Traditional syntax: (type_path, { fn method1(...) -> ...; fn method2(...) -> ...; })
|
||||
($type_path:ty, { $($methods:tt)* }) => {
|
||||
$crate::config::opt(stringify!($type_path))
|
||||
// TODO: parse method signatures and generate appropriate bindings
|
||||
// For now, this is a placeholder for the traditional syntax
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user