sample of using closure subroutines
This commit is contained in:
parent
a6ca0b7508
commit
7afab7df0a
|
@ -9,6 +9,12 @@ dependencies = [
|
|||
"rust-guile",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "lazy_static"
|
||||
version = "1.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
|
||||
|
||||
[[package]]
|
||||
name = "pkg-config"
|
||||
version = "0.3.26"
|
||||
|
@ -37,6 +43,7 @@ dependencies = [
|
|||
name = "rust-guile"
|
||||
version = "0.1.6"
|
||||
dependencies = [
|
||||
"lazy_static",
|
||||
"pkg-config",
|
||||
"thiserror",
|
||||
]
|
||||
|
|
|
@ -1,11 +1,16 @@
|
|||
use std::{sync::{atomic::{AtomicU8, Ordering}, Arc}};
|
||||
|
||||
use guile_goblins_rs::start_scm;
|
||||
use rust_guile::api::GuileApi;
|
||||
use rust_guile::api::{GuileApi, subroutines::register_subroutine};
|
||||
fn main() {
|
||||
let counter = Box::leak(Box::new(AtomicU8::new(0)));
|
||||
// We want to run the contents of repl-init.scm before starting the repl, mostly to activate readline.
|
||||
let to_run = |api: GuileApi| {
|
||||
api.load_script("./repl-init.scm");
|
||||
register_subroutine("idk", |a| {
|
||||
println!("i'm a closure subroutine that's been called {} times.", counter.fetch_add(1, Ordering::Relaxed));
|
||||
a
|
||||
});
|
||||
};
|
||||
start_scm(vec![], to_run); // start guile with no args = repl
|
||||
// note execution stops here, because guile exits the process.
|
||||
|
|
Loading…
Reference in New Issue