From 8fe3ffc8e054f487e96cabc693bb3c93e3f20d2b Mon Sep 17 00:00:00 2001 From: Sofia Date: Fri, 20 Mar 2026 19:28:49 +0200 Subject: [PATCH] Fix concat --- src/vm/value.rs | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/src/vm/value.rs b/src/vm/value.rs index bf1d4e2..8332dbd 100644 --- a/src/vm/value.rs +++ b/src/vm/value.rs @@ -1,4 +1,9 @@ -use std::{cell::RefCell, collections::HashMap, fmt::Debug, rc::Rc}; +use std::{ + cell::RefCell, + collections::HashMap, + fmt::{Debug, Display}, + rc::Rc, +}; use crate::{ ast::{BinaryOperator, UnaryOperator}, @@ -31,7 +36,7 @@ impl LuaFloat { impl Debug for LuaFloat { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - self.0.fmt(f) + Debug::fmt(&self.0, f) } } @@ -40,7 +45,7 @@ pub struct LuaInteger(pub i64); impl Debug for LuaInteger { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - self.0.fmt(f) + Debug::fmt(&self.0, f) } } @@ -61,7 +66,7 @@ pub struct LuaBool(pub bool); impl Debug for LuaBool { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - self.0.fmt(f) + Debug::fmt(&self.0, f) } } @@ -184,13 +189,30 @@ impl From<&str> for Value { } } +impl Display for Value { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + Value::String(value) => Display::fmt(value, f), + Value::Float(vmfloat) => Display::fmt(&vmfloat.lua_number().0, f), + Value::Integer(lua_integer) => Display::fmt(&lua_integer.0, f), + Value::Boolean(lua_bool) => Display::fmt(&lua_bool.0, f), + Value::RustFunction(ref_cell) => { + write!(f, "", ref_cell.borrow().as_indexable()) + } + Value::Function(closure) => write!(f, "", closure.prototype), + Value::Nil => write!(f, "nil"), + Value::Table(_) => write!(f, ""), + } + } +} + impl Value { pub fn concat(&self, other: &Value) -> Result { match (self, other) { ( Value::String(_) | Value::Integer(_) | Value::Boolean(_), Value::String(_) | Value::Integer(_) | Value::Boolean(_), - ) => Ok(Value::String(format!("{:?}{:?}", self, other))), + ) => Ok(Value::String(format!("{}{}", self, other))), ( Value::Float(_) | Value::Integer(_) | Value::Boolean(_), Value::Float(_) | Value::Integer(_) | Value::Boolean(_),