some more restorations

This commit is contained in:
Sebastian Moser
2026-10-23 11:29:39 +02:00
parent 48f7ee2e35
commit 9e5ceaf0f9
14 changed files with 1170 additions and 9179 deletions

172
core/src/lib.rs Normal file
View File

@@ -0,0 +1,172 @@
#![allow(warnings)]
use std::cell::RefCell;
use std::fmt::format;
#[macro_export]
macro_rules! out {
($($arg:tt)*) => {
// format_args! handles string interpolation safely at compile time
if let Err(e) = $crate::write_to_mize_stdout(format_args!($($arg)*)) {
// Choose your error handling behavior here (panic, print to stderr, or ignore)
eprintln!("out! macro failed to write!!");
}
};
}
pub fn write_to_mize_stdout(args: std::fmt::Arguments) -> MizeResult<()> {
println!("{}", format_args!(args));
Ok(())
}
pub mod prelude {
pub use super::*;
pub use instance::Mize;
pub use error::MizeError;
pub use crate::mize_err;
pub use error::MizeResult;
pub use item::{Item, ItemData, IntoItemData};
pub use config::*;
}
pub use flume;
// the core part has the code that can run on any platform
pub mod config;
pub mod error;
pub mod id;
pub mod instance;
pub mod item;
pub mod memstore;
pub mod proto;
pub mod types;
pub mod c_api;
pub use async_trait::async_trait;
pub use ciborium;
pub use error::MizeError;
pub use error::MizeResult;
pub use instance::Mize;
pub use instance::{
MizePart,
};
pub use mize_macros::*;
use std::path::PathBuf;
// platform specific stuff
pub mod platform {
use crate::{Mize, MizeResult};
#[cfg(feature = "target-js")]
pub mod js;
#[cfg(feature = "target-os")]
pub mod os;
pub fn init(mize: &mut Mize) -> MizeResult<()> {
#[cfg(feature = "target-os")] {
os::os_instance_init(mize)?;
}
#[cfg(feature = "target-js")] {
js::wasm_instance_init(mize)?;
}
Ok(())
}
pub fn load_part(mize: &mut Mize, part_name: &str, path: Option<String>) -> MizeResult<()> {
#[cfg(feature = "target-os")] {
os::load_part(mize, part_name, path)?;
}
Ok(())
}
pub fn fetch_part(mize: &mut Mize, part_name: &str) -> MizeResult<String> {
#[cfg(feature = "target-os")] {
os::fetch_part(mize, part_name)?;
}
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::c_api::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
};
}