diff --git a/src/adana_script/compute.rs b/src/adana_script/compute.rs index 397c9aa..f805792 100644 --- a/src/adana_script/compute.rs +++ b/src/adana_script/compute.rs @@ -530,6 +530,9 @@ fn compute_recur( } TreeNodeValue::StructAccess { struc, key } => match (struc, key) { (Value::Variable(v), key @ Primitive::String(k)) => { + if cfg!(test) { + dbg!(&ctx); + } let struc = ctx .get(v) .context("struct not found in context")? @@ -631,6 +634,7 @@ fn compute_recur( if matches!( *maybe_fn, Primitive::Function { parameters: _, exprs: _ } + | Primitive::NativeLibrary(_) ) { scope_ctx.insert(k.to_string(), p.clone()); } @@ -718,6 +722,7 @@ fn compute_recur( let slb = shared_lib.as_ref().to_path_buf(); let fun = move |v, extra_ctx| { cloned_ctx.extend(extra_ctx); + println!("goes in"); compute_lazy(v, &mut cloned_ctx, &slb) }; unsafe { diff --git a/src/adana_script/tests/dynload.rs b/src/adana_script/tests/dynload.rs index 2671993..fdc58e2 100644 --- a/src/adana_script/tests/dynload.rs +++ b/src/adana_script/tests/dynload.rs @@ -42,3 +42,23 @@ fn callback_dynamic_lib_test() { dbg!(ctx); println!("{res:?}"); } + +#[test] +#[serial] +fn complex_callback_dynamic_lib_test() { + let file_path = r#" + lib = require("libplugin_example.so") + callback = (input) => {lib.hello(input,"Nordine!","ca", "va?")} + text = lib.callback(callback) + "#; + let mut ctx = BTreeMap::new(); + let res = compute(file_path, &mut ctx, "dynamic_lib").unwrap(); + + assert_eq!( + Primitive::String("Hello Hello Nordine! ca va?".to_string()), + ctx["text"].read().unwrap().clone() + ); + + dbg!(ctx); + println!("{res:?}"); +}