Skip to content

draft implementation of include statement and FunctionCall ScadObject#9

Open
RustyJoeM wants to merge 1 commit intoTheZoq2:masterfrom
RustyJoeM:include-statement-and-function-use
Open

draft implementation of include statement and FunctionCall ScadObject#9
RustyJoeM wants to merge 1 commit intoTheZoq2:masterfrom
RustyJoeM:include-statement-and-function-use

Conversation

@RustyJoeM
Copy link
Contributor

I tried to quickly look into docs, but the amount felt a bit scary... :) thus no committed usage example.
Adding code snippet here, to get a feel on how to use this:

    // add include statement to the top of resulting OpenSCAD file:
    let mut scad_file = ScadFile::new();
    scad_file.add_include("SomeCustom.scad".to_string());

    // and someplace where building ScadObjects:
    let fn_name = "SomeScadFunction".to_string();

    // can add items of different types into arguments vector
    let fn_args: FnCallArgs = vec![Box::new(vec2(3.0, 4.0)), Box::new(1.0)];

    // can add items of different types into named arguments vector as well
    let fn_named_args: FnCallNamedArgs = vec![
        ("resolution".to_string(), Box::new(123)),
        ("centered".to_string(), Box::new(false)),
    ];

    let scad_object = scad!(FunctionCall(
        fn_name,
        Some(Rc::new(fn_args)),
        Some(Rc::new(fn_named_args))
    ));

    scad_file.add_object(scad_object);

results in following code neing generated:

    include <SomeCustom.scad>
    SomeScadFunction([3,4], 1, resolution = 123, centered = false);

@TheZoq2
Copy link
Owner

TheZoq2 commented Jan 23, 2021

Sorry for the delay!

Overall, it looks like a nice change, though I'm not sure about all the Box and Rc stuff, do you think there is a way to get rid of it?

Edit: So github will auto close the corresponding issue. Closes #7

@RustyJoeM
Copy link
Contributor Author

As i'm not yet professionally experienced in Rust, "architecture"/design review would be definitely welcome :)

It is needed to allow different types of items to be in the same vector in my current understanding, but...
Maybe it would be better to simplify my proposed API, and remove boxing/rc-ing by hiding from user, - e.g. define add_(named_)parameter() function for params struct and build it step-by-step invoking add_param() with simple references/owned values.

I'll try to make alternative implementation for this and see if it's cleaner/simpler. Will keep you updated...

@TheZoq2
Copy link
Owner

TheZoq2 commented Jan 24, 2021

Yea, I figured that was the case. Like you said, the builder pattern might look nicer here, something like

function
    .param(x)
    .named_param(name, y)
    .build()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants