Releases: jprochazk/hebi
v0.4.0
This is a total rewrite of the VM and codegen, which means that the API is now completely different.
The easiest way to get started is to look at the examples.
What's Changed
- Modules by @jprochazk in #19
- Native classes by @jprochazk in #22
- V2 by @jprochazk in #30
Full Changelog: 0.0.1...v0.4.0
v0.3.1
This release includes no breaking changes.
New features
This release introduces methods on builtin types.
let vm = Hebi::new();
// prints `[0, 1, 2, 3]`
vm.eval::<()>(r#"
v := [0,1,2]
v.push(3)
print v
"#).unwrap();
This release only adds a single method on the builtin List
type, push
. The goal was to lay the groundwork for implementing a proper standard library in the future.
v0.3.0
Breaking changes
Hebi::create_function
has been removed. It has been replaced by theGlobals::register_fn
method.Hebi::with_io
(deprecated since0.2.0
) has been removed.
New APIs
Hebi::wrap
andHebi::try_wrap
Globals::register_fn
andGlobals::register_class
New features
This release introduces native class binding.
#[hebi::class]
struct Number {
value: i32
}
#[hebi::methods]
impl Number {
#[init]
pub fn new(value: i32) -> Self {
Self { value }
}
pub fn add(&mut self, value: i32) {
self.value += value;
}
pub fn square(&self) -> i32 {
self.value * self.value
}
}
let vm = Hebi::new();
vm.globals().register_class::<Number>();
vm.eval::<()>(r#"
a := Number(100)
print a.value # prints `100`
a.add(10)
print a.value # prints `110`
"#).unwrap();
Native class methods also support the #[kw]
and #[default]
parameter attributes.
It is also possible to pass a value to the VM instead of constructing it in a script:
// the type must be registered first, otherwise `wrap` will panic
vm.globals().register_class::<Number>();
vm.globals().set("n", vm.wrap(Number { value: 50 }));
vm.eval::<()>(r#"print n.square()"#).unwrap();
The value will be managed by the runtime. If it is no longer in use, it may be dropped at some point. The only time the value is guaranteed to be dropped is when the Hebi
instance is dropped.