Support passing booleans back and forth

This commit is contained in:
Alex Crichton
2017-12-20 10:22:18 -08:00
parent 730ef1926e
commit 294c5e147b
6 changed files with 87 additions and 3 deletions

View File

@ -33,6 +33,7 @@ pub enum Type {
RawConstPtr(syn::Ident),
JsObject,
JsObjectRef,
Boolean,
}
pub struct Struct {
@ -271,6 +272,7 @@ impl Type {
"f64" => {
Type::Integer(ident)
}
"bool" => Type::Boolean,
"String" => Type::String,
"JsObject" => Type::JsObject,
_ => Type::ByValue(ident),
@ -292,6 +294,7 @@ impl Type {
Type::ByMutRef(n) => shared::Type::ByMutRef(n.to_string()),
Type::JsObject => shared::Type::JsObject,
Type::JsObjectRef => shared::Type::JsObjectRef,
Type::Boolean => shared::Type::Boolean,
}
}
}

View File

@ -189,6 +189,12 @@ fn bindgen(export_name: &syn::Lit,
ast::Type::Integer(i) => {
args.push(my_quote! { #ident: #i });
}
ast::Type::Boolean => {
args.push(my_quote! { #ident: u32 });
arg_conversions.push(my_quote! {
let #ident = #ident != 0;
});
}
ast::Type::RawMutPtr(i) => {
args.push(my_quote! { #ident: *mut #i });
}
@ -272,6 +278,10 @@ fn bindgen(export_name: &syn::Lit,
ret_ty = my_quote! { -> #i };
convert_ret = my_quote! { #ret };
}
Some(&ast::Type::Boolean) => {
ret_ty = my_quote! { -> u32 };
convert_ret = my_quote! { #ret as u32 };
}
Some(&ast::Type::RawMutPtr(i)) => {
ret_ty = my_quote! { -> *mut #i };
convert_ret = my_quote! { #ret };
@ -444,6 +454,11 @@ fn bindgen_import(import: &ast::Import, tokens: &mut Tokens) {
abi_arguments.push(my_quote! { #name: #i });
arg_conversions.push(my_quote! {});
}
ast::Type::Boolean => {
abi_argument_names.push(name);
abi_arguments.push(my_quote! { #name: u32 });
arg_conversions.push(my_quote! { let #name = #name as u32; });
}
ast::Type::RawMutPtr(i) => {
abi_argument_names.push(name);
abi_arguments.push(my_quote! { #name: *mut #i });
@ -495,6 +510,10 @@ fn bindgen_import(import: &ast::Import, tokens: &mut Tokens) {
abi_ret = my_quote! { #i };
convert_ret = my_quote! { #ret_ident };
}
Some(ast::Type::Boolean) => {
abi_ret = my_quote! { u32 };
convert_ret = my_quote! { #ret_ident != 0 };
}
Some(ast::Type::RawConstPtr(i)) => {
abi_ret = my_quote! { *const #i };
convert_ret = my_quote! { #ret_ident };