1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// Copyright (c) 2020-2022 Weird Constructor <weirdconstructor@gmail.com>
// This is a part of WLambda. See README.md and COPYING for details.
/*!
Provides a convenience macro for creating OO interfaces from
Rust. See `set_vval_method` macro.
*/
/// This macro helps with exporting something with a more OO interface
/// instead of using a VValUserData trait implementation.
///
///```
/// use wlambda::*;
/// use wlambda::set_vval_method;
///
/// let mut ctx = EvalContext::new_default();
///
/// let some_ref = std::rc::Rc::new(std::cell::RefCell::new(10));
/// let obj = VVal::map();
///
/// set_vval_method!(obj, some_ref, get_it, None, None, _env, _argc, {
/// Ok(VVal::Int(*some_ref.borrow()))
/// });
///
/// ctx.set_global_var("I", &obj);
///
/// assert_eq!(ctx.eval("I.get_it[]").unwrap().s(), "10");
/// *some_ref.borrow_mut() += 11;
/// assert_eq!(ctx.eval("I.get_it[]").unwrap().s(), "21");
///```