feat: create scoped language functions from native calls

This commit is contained in:
2026-10-21 02:19:30 +08:00
parent be9a032647
commit 2b5539cd06
4 changed files with 17 additions and 2 deletions
+14
View File
@@ -58,6 +58,20 @@ impl<'a> NativeContext<'a> {
self.allocate(crate::Record)
}
/// Build a language function under this native scope using validated code.
pub fn new_function(
&mut self,
name: impl Into<String>,
code: ObjectRef,
globals: ObjectRef,
) -> Result<ObjectRef, VmError> {
let function = self
.store
.new_function(name, code, globals, vec![], vec![])?;
self.roots.push(function);
Ok(function)
}
pub fn new_dict(&mut self) -> Result<ObjectRef, VmError> {
let object = self.store.new_dict()?;
self.roots.push(object);