summaryrefslogtreecommitdiff
path: root/matrix-stdlib/src/io.rs
diff options
context:
space:
mode:
authorFreya Murphy <freya@freyacat.org>2024-02-23 11:32:47 -0500
committerFreya Murphy <freya@freyacat.org>2024-02-23 11:32:47 -0500
commita888c09bd54de77fb2004754a0e14ce14a906232 (patch)
treec5b20b4be32feec7a3430f1191e1f735ea51ca57 /matrix-stdlib/src/io.rs
parentindexing and field access (diff)
downloadmatrix-a888c09bd54de77fb2004754a0e14ce14a906232.tar.gz
matrix-a888c09bd54de77fb2004754a0e14ce14a906232.tar.bz2
matrix-a888c09bd54de77fb2004754a0e14ce14a906232.zip
more changes
Diffstat (limited to 'matrix-stdlib/src/io.rs')
-rw-r--r--matrix-stdlib/src/io.rs36
1 files changed, 36 insertions, 0 deletions
diff --git a/matrix-stdlib/src/io.rs b/matrix-stdlib/src/io.rs
new file mode 100644
index 0000000..288e99e
--- /dev/null
+++ b/matrix-stdlib/src/io.rs
@@ -0,0 +1,36 @@
+use matrix::{value::Value, self, vm::Vm, Result};
+use matrix_macros::native_func;
+
+#[native_func(1, true)]
+fn print(_vm: &mut Vm, args: Vec<Value>) -> Result<Value> {
+ let [values] = args.try_into().unwrap();
+ if let Value::List(list) = values {
+ for (i, value) in list.iter().enumerate() {
+ print!("{}", value.boring_print());
+ if i != 0 {
+ print!(" ");
+ }
+ }
+ }
+ Ok(Value::Nil)
+}
+
+#[native_func(1, true)]
+fn println(_vm: &mut Vm, args: Vec<Value>) -> Result<Value> {
+ let [values] = args.try_into().unwrap();
+ if let Value::List(list) = values {
+ for (i, value) in list.iter().enumerate() {
+ print!("{}", value.boring_print());
+ if i != 0 {
+ print!(" ");
+ }
+ }
+ }
+ print!("\n");
+ Ok(Value::Nil)
+}
+
+pub fn load(vm: &mut Vm) {
+ vm.load_native_fn(print());
+ vm.load_native_fn(println());
+}