mirror of
https://github.com/zed-industries/zed.git
synced 2024-11-08 07:35:01 +03:00
Add support for variadic functions
This commit is contained in:
parent
17d15b2f08
commit
805c86b781
@ -19,6 +19,17 @@ pub fn bind(args: TokenStream, function: TokenStream) -> TokenStream {
|
||||
let inner_fn_name = format_ident!("{}", inner_fn.sig.ident);
|
||||
let outer_fn_name = format_ident!("__{}", inner_fn_name);
|
||||
|
||||
let variadic = inner_fn.sig.inputs.len();
|
||||
let mut args = vec![];
|
||||
for i in 0..variadic {
|
||||
let ident = format_ident!("__{}_arg_{}", inner_fn_name, i);
|
||||
args.push(ident);
|
||||
}
|
||||
|
||||
let args = quote! {
|
||||
( #(args ,) )*
|
||||
};
|
||||
|
||||
TokenStream::from(quote! {
|
||||
#[no_mangle]
|
||||
#inner_fn
|
||||
@ -30,8 +41,8 @@ pub fn bind(args: TokenStream, function: TokenStream) -> TokenStream {
|
||||
let data = unsafe { buffer.to_vec() };
|
||||
|
||||
// operation
|
||||
let argument = ::plugin::bincode::deserialize(&data).unwrap();
|
||||
let result = #inner_fn_name(argument);
|
||||
let #args = ::plugin::bincode::deserialize(&data).unwrap();
|
||||
let result = #inner_fn_name #args;
|
||||
let new_data: Result<Vec<u8>, _> = ::plugin::bincode::serialize(&result);
|
||||
let new_data = new_data.unwrap();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user