Refactor native function registration and instantiation
Introduces `register_native` for direct registration of `NativeFunction` and `register_native_fn` for convenience from closures. The `Environment::run` method is removed, and its functionality is now handled by `Environment::instantiate`, which packages the linked AST into an invokable `NativeFunction`. This streamlines the execution path and better separates compilation/linking from runtime execution.
This commit is contained in:
@@ -8,7 +8,7 @@ pub fn register(env: &Environment) {
|
||||
ret: StaticType::DateTime,
|
||||
}));
|
||||
|
||||
env.register_native("date", date_ty, Purity::Pure, |args| {
|
||||
env.register_native_fn("date", date_ty, Purity::Pure, |args| {
|
||||
if let Value::Text(s) = &args[0] {
|
||||
// Try parse YYYY-MM-DD
|
||||
if let Ok(dt) = NaiveDate::parse_from_str(s, "%Y-%m-%d") {
|
||||
@@ -32,7 +32,7 @@ pub fn register(env: &Environment) {
|
||||
ret: StaticType::DateTime,
|
||||
}));
|
||||
|
||||
env.register_native("now", now_ty, Purity::SideEffectFree, |_| {
|
||||
env.register_native_fn("now", now_ty, Purity::SideEffectFree, |_| {
|
||||
let ts = chrono::Utc::now().timestamp_millis();
|
||||
Value::DateTime(ts)
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user