From 4cbbff259ca0ab18c0be46a15ca9e84b24804a6f Mon Sep 17 00:00:00 2001 From: ConnorSkees <39542938+ConnorSkees@users.noreply.github.com> Date: Sat, 25 Jan 2020 23:33:45 -0500 Subject: [PATCH] Implement basic builtin functions --- src/builtin/color.rs | 11 +++++++++++ src/builtin/mod.rs | 11 ++++++++--- src/value.rs | 2 +- 3 files changed, 20 insertions(+), 4 deletions(-) create mode 100644 src/builtin/color.rs diff --git a/src/builtin/color.rs b/src/builtin/color.rs new file mode 100644 index 0000000..8d317cb --- /dev/null +++ b/src/builtin/color.rs @@ -0,0 +1,11 @@ +use std::collections::BTreeMap; + +use super::Builtin; +use crate::value::Value; + +pub(crate) fn register(f: &mut BTreeMap) { + f.insert("rgb".to_owned(), Box::new(|args| { + let red = args.get("red"); + todo!() + })); +} \ No newline at end of file diff --git a/src/builtin/mod.rs b/src/builtin/mod.rs index c8bafb9..25f2eee 100644 --- a/src/builtin/mod.rs +++ b/src/builtin/mod.rs @@ -1,15 +1,20 @@ use lazy_static::lazy_static; use std::collections::BTreeMap; +use crate::args::CallArgs; use crate::common::Scope; use crate::function::Function; use crate::value::Value; -pub(crate) type Builtin = dyn Fn(&Scope) -> Value + Send + Sync; +mod color; + +pub(crate) type Builtin = Box Value + Send + Sync>; lazy_static! { - pub(crate) static ref GLOBAL_FUNCTIONS: BTreeMap = { - let m = BTreeMap::new(); + pub(crate) static ref GLOBAL_FUNCTIONS: BTreeMap = { + let mut m = BTreeMap::new(); + color::register(&mut m); m }; } + diff --git a/src/value.rs b/src/value.rs index a744135..6d8fa58 100644 --- a/src/value.rs +++ b/src/value.rs @@ -279,7 +279,7 @@ impl Value { let func = match scope.functions.get(&s) { Some(f) => f, None => match GLOBAL_FUNCTIONS.get(&s) { - Some(f) => f, + Some(f) => return Some(f(&args)), None => todo!("called undefined function"), }, };