feat: first working version with parameters

This commit is contained in:
2024-04-15 18:46:34 +02:00
parent e29cb11b81
commit 0254bc1ae5
45 changed files with 389 additions and 351 deletions

View File

@@ -17,7 +17,7 @@ wasm-bindgen = "0.2.84"
# logging them with `console.error`. This is great for development, but requires
# all the `std::fmt` and `std::panicking` infrastructure, so isn't great for
# code size when deploying.
plantarium = { version = "0.1.0", path = "../../../../packages/plantarium" }
utils = { version = "0.1.0", path = "../../../../packages/utils" }
serde = { version = "1.0", features = ["derive"] }
serde-wasm-bindgen = "0.4"
console_error_panic_hook = { version = "0.1.7", optional = true }

View File

@@ -1,14 +1,5 @@
mod utils;
use plantarium::{evaluate_parameters, unwrap_int, unwrap_string};
use wasm_bindgen::prelude::*;
// lifted from the `console_log` example
#[wasm_bindgen]
extern "C" {
#[wasm_bindgen(js_namespace = console)]
fn log(s: &str);
}
#[wasm_bindgen]
pub fn get_outputs() -> Vec<String> {
vec!["float".to_string()]
@@ -16,7 +7,6 @@ pub fn get_outputs() -> Vec<String> {
#[wasm_bindgen]
pub fn get_input_types() -> String {
utils::set_panic_hook();
r#"{
"min": { "type": "float", "value": 2 },
"max": { "type": "float", "value": 2 },
@@ -25,24 +15,10 @@ pub fn get_input_types() -> String {
.to_string()
}
struct El {
value: Option<f64>,
array: Option<Vec<f64>>,
nested: Option<Box<El>>,
}
#[rustfmt::skip]
#[wasm_bindgen]
pub fn execute(var_min: JsValue, var_max: JsValue, var_seed: JsValue) -> Vec<f64> {
utils::set_panic_hook();
pub fn execute(args: &[i32]) -> Vec<i32> {
// construct vertices of a triangle
let min= evaluate_parameters(var_min);
// let min = evaluate_parameters(var_min);
return vec![
0.0, 0.0, 0.0,
min, 0.0, 0.0,
min, min, 0.0
];
vec![1, 2, 3, 4, args[0]]
}

View File

@@ -1,10 +0,0 @@
pub fn set_panic_hook() {
// When the `console_error_panic_hook` feature is enabled, we can call the
// `set_panic_hook` function at least once during initialization, and then
// we will get better error messages if our code ever panics.
//
// For more details see
// https://github.com/rustwasm/console_error_panic_hook#readme
#[cfg(feature = "console_error_panic_hook")]
console_error_panic_hook::set_once();
}