Make tables indexable

This commit is contained in:
Sofia 2026-03-21 15:17:16 +02:00
parent ce3ee7a273
commit 10bc804a01

View File

@ -125,7 +125,8 @@ impl Debug for Constant {
} }
} }
pub type Table = Rc<RefCell<HashMap<IndexableValue, Value>>>; pub type Table = Rc<RefCell<TableMap>>;
pub type TableMap = HashMap<IndexableValue, Value>;
#[derive(Clone)] #[derive(Clone)]
pub enum Value { pub enum Value {
@ -151,7 +152,7 @@ impl Value {
} }
Value::Function(closure) => Ok(IndexableValue::Function(closure.prototype)), Value::Function(closure) => Ok(IndexableValue::Function(closure.prototype)),
Value::Nil => Err(RuntimeError::InvalidTableIndex(self)), Value::Nil => Err(RuntimeError::InvalidTableIndex(self)),
Value::Table { .. } => Err(RuntimeError::InvalidTableIndex(self)), Value::Table { contents, .. } => Ok(IndexableValue::Table(contents.as_ptr())),
} }
} }
@ -621,6 +622,7 @@ pub enum IndexableValue {
Bool(LuaBool), Bool(LuaBool),
RustFunction(String), RustFunction(String),
Function(u32), Function(u32),
Table(*mut TableMap),
} }
impl From<&str> for IndexableValue { impl From<&str> for IndexableValue {