summaryrefslogtreecommitdiff
path: root/src/sheet/mod.rs
diff options
context:
space:
mode:
authorNathan Reiner <nathan@nathanreiner.xyz>2024-08-02 00:36:10 +0200
committerNathan Reiner <nathan@nathanreiner.xyz>2024-08-02 00:36:10 +0200
commitfe0938b1de0c46fc2afcaa3dcd6a0f4ec870d21a (patch)
tree8db7509894842395cfb309f00c41b7f4d173888c /src/sheet/mod.rs
parent1e1eb95926f556e666bc20355327abd24d264858 (diff)
add state which is shared with the lua environment
Diffstat (limited to 'src/sheet/mod.rs')
-rw-r--r--src/sheet/mod.rs16
1 files changed, 15 insertions, 1 deletions
diff --git a/src/sheet/mod.rs b/src/sheet/mod.rs
index f67d55e..501b71e 100644
--- a/src/sheet/mod.rs
+++ b/src/sheet/mod.rs
@@ -90,7 +90,7 @@ impl Clone for Sheet {
}
}
-struct SheetLuaRef {
+pub struct SheetLuaRef {
id: SheetId,
}
@@ -98,6 +98,10 @@ impl SheetLuaRef {
pub fn new(id: SheetId) -> Self {
Self { id }
}
+
+ pub fn id(&self) -> SheetId {
+ self.id
+ }
}
impl LuaUserData for SheetLuaRef {
@@ -122,3 +126,13 @@ impl LuaUserData for SheetLuaRef {
})
}
}
+
+impl<'lua> FromLua<'lua> for SheetLuaRef {
+ fn from_lua(value: LuaValue<'lua>, _: &'lua Lua) -> LuaResult<Self> {
+ if let Some(ud) = value.as_userdata() {
+ ud.take()
+ } else {
+ Err(LuaError::runtime("failed to parse sheet"))
+ }
+ }
+}