fltk-rs / fl2rust

A fluid (fltk ui designer) file to Rust transpiler
MIT License
52 stars 3 forks source link

Function #9

Closed 1sra3l closed 2 years ago

1sra3l commented 2 years ago

Hi I am trying to understand fl2rust returning Function as pub fn I think here is where things really happen

                "Function" => {
                    let return_type = false;
                    if words.len() > 2 {
                        for i in 0..words.len() {
                            let name = utils::unbracket(&words[1]).to_string();
                            if words[i] == "return_type" {
                                // does this not just work?
                                ast.ident = format!(
                                    "{} -> {}",
                                    name,
                                    utils::unbracket(&words[i + 1]).to_string()
                                );
                                ast.typ = TokenType::Function;
                                break;
                            } else {
                                ast.ident = name.clone();
                                ast.typ = TokenType::Function;
                            }
                        }
                        parent.push(format!("Function {}", ast.ident.clone()));
                    }
                }

Is is commented out because it does not work, or because of this specifically:

if !elem.ident.contains("-> Self") {
//...
}

Could this be changed to:

if !elem.ident.contains("->") {
//...
}

To support writing functions in FLUID?

MoAlyousef commented 2 years ago

Hello Currently Function's assume they're a constructor, and would generate a struct, that's why they return Self. For the moment, standalone functions and struct methods aren't supported (ie it would require much more code changes).

1sra3l commented 2 years ago

Ok thanks! If I get really interested in this at some point I may really look through the code and re-open this if I have anything useful to add