Skip to content

Commit 6623acf

Browse files
committed
reduce table memory
1 parent a2428f3 commit 6623acf

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

crates/luars/src/lua_value/lua_table.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// - Array part for integer keys [1..n]
33
// - Hash part using open addressing (same as Lua 5.4)
44
use super::LuaValue;
5-
use crate::LuaVM;
5+
use crate::{LuaVM, TableId};
66

77
/// Hash node - mimics Lua 5.4's Node structure
88
/// Contains key+value pair
@@ -60,7 +60,7 @@ pub struct LuaTable {
6060

6161
/// Metatable - optional table that defines special behaviors
6262
/// Store as LuaValue (table ID) instead of Rc for ID-based architecture
63-
metatable: Option<LuaValue>,
63+
metatable: Option<TableId>,
6464

6565
/// Metamethod absence flags (like Lua 5.4)
6666
/// A bit set to 1 means the metamethod is NOT present (cached absence)
@@ -252,13 +252,14 @@ impl LuaTable {
252252

253253
/// Get the metatable of this table
254254
pub fn get_metatable(&self) -> Option<LuaValue> {
255-
self.metatable.clone()
255+
self.metatable
256+
.map(|mt_id| LuaValue::table(mt_id))
256257
}
257258

258259
/// Set the metatable of this table
259260
/// Resets tm_flags since the new metatable may have different metamethods
260261
pub fn set_metatable(&mut self, mt: Option<LuaValue>) {
261-
self.metatable = mt;
262+
self.metatable = mt.and_then(|v| v.as_table_id());
262263
// Reset all flags - metamethods need to be re-checked
263264
self.tm_flags = 0;
264265
}

0 commit comments

Comments
 (0)