Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate function bind #2

Merged
merged 18 commits into from
Dec 29, 2023
Prev Previous commit
Next Next commit
wip
  • Loading branch information
seiren-games committed Jul 22, 2023
commit 8b7011d38703667ce70205e7cad06f11a625831d
36 changes: 36 additions & 0 deletions raylib-rs-plain/build.rs
Original file line number Diff line number Diff line change
@@ -65,6 +65,42 @@ fn generate_function(raylib_api:&RaylibApi) {
}

fn c_to_rs_return_type(c_type:&str) -> String {
if c_type == "void" {
return "".to_owned();
}
let mut modifier:String = String::new();
let mut unprocessed_elements:Vec<&str> = Vec::new();
for type_element in c_type.split(" ") {
let mut asterisk_part:String = String::new();
for asterisk in type_element.chars() {
if asterisk != '*' {
continue;
}
if type_element.len() > 1 && !asterisk_part.contains("*") {
asterisk_part += "*mut ";
continue;
}
if c_type.contains("const") {
asterisk_part += "*";
} else {
asterisk_part += "*mut ";
}
}
if !asterisk_part.is_empty() {
modifier = asterisk_part + modifier.as_str();
continue;
}

if type_element == "const " {
modifier += type_element;
continue;
}

unprocessed_elements.push(type_element);
}

return " -> ".to_owned() + modifier.as_str() + unprocessed_elements.join(" ").as_str();

let rs_type:Option<&str> = match c_type {
"void" => Option::None,
_ => Option::Some(c_type),