i have macros
src/lib.rs
use core::mem::transmute;
#[macro_export]
macro_rules! msg {
[$cls:ident $sel:ident] => {
$crate::__msg_send!{$cls, $sel}
};
[$cls:ident $($sel_and_arg:tt)+] => {
$crate::__msg_parse!{$cls $($sel_and_arg)+}
};
}
#[macro_export]
macro_rules! __msg_parse {
{$cls:ident $($sel:ident : $arg:expr)+} => {
$crate::__msg_send!{$cls $($sel)+ $($arg)+}
};
}
#[macro_export]
macro_rules! __msg_send {
{$cls:ident $sel:ident} => {{
let cls = concat!(stringify!($cls), "\0");
let sel = concat!(stringify!($sel), "\0");
$crate::TupleFn::call((cls, sel))
}};
{$cls:ident $($sel:ident)+ $($arg:expr)+} => {{
let cls = concat!(stringify!($cls), "\0");
let sel = concat!($(stringify!($sel), ":"),+, "\0");
$crate::TupleFn::call((cls, sel $(, $arg)*))
}};
}
pub unsafe trait TupleFn<Output> {
fn call(self) -> Output;
}
unsafe impl<A, B, Output> TupleFn<Output> for (A, B) {
fn call(self) -> Output {
let f = unsafe { transmute::<unsafe extern "C" fn(),unsafe extern "C" fn(A, B) -> Output>(objc_msgSend as unsafe extern "C" fn()) };
let (cls, sel) = self;
unsafe { f(cls, sel) }
}
}
unsafe impl<A, B, C, Output> TupleFn<Output> for (A, B, C) {
fn call(self) -> Output {
let f = unsafe { transmute::<unsafe extern "C" fn(),unsafe extern "C" fn(A, B, C) -> Output>(objc_msgSend as unsafe extern "C" fn()) };
let (cls, sel, arg1) = self;
unsafe { f(cls, sel, arg1) }
}
}
#[link(name = "objc")]
unsafe extern "C" {
pub unsafe fn objc_msgSend();
}
the macros work great as seen in the following
src/main.rs
fn main() {
msg![Alphabet A: 1];
}
until we do
src/main.rs
fn main() {
let a = 1;
msg![Alphabet A: a];
}
then i get the error
leftover tokens rust-analyzer(macro-error)
pls somebody help me
p.s. if not obvious this macro is going to be used to interface objective c and eventually create an app, window, etc.