From 607fe4cdd5916ec28550ebb9b5202846f4c17099 Mon Sep 17 00:00:00 2001 From: Caleb Maclennan Date: Sat, 12 Oct 2024 02:10:16 +0300 Subject: [PATCH] fixup! [NFY] Wrap semver::Version as Lua type --- rusile/src/lib.rs | 3 ++- src/types/semver.rs | 21 ++++++++++++++------- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/rusile/src/lib.rs b/rusile/src/lib.rs index 5f1fead73..59113907c 100644 --- a/rusile/src/lib.rs +++ b/rusile/src/lib.rs @@ -6,9 +6,10 @@ use mlua::prelude::*; #[mlua::lua_module] fn rusile(lua: &Lua) -> LuaResult { - let exports = lua.create_table().unwrap(); + let exports = lua.create_table()?; exports.set("demo", LuaFunction::wrap_raw(sile::rusile_demo))?; let x = sile::types::semver::Semver::new("3.2.1-rc0+foo")?; exports.set("x", x)?; + //exports.set("semver", LuaFunction::wrap_raw(sile::types::semver::semver))?; Ok(exports) } diff --git a/src/types/semver.rs b/src/types/semver.rs index 7fec4ff62..ceb626aa4 100644 --- a/src/types/semver.rs +++ b/src/types/semver.rs @@ -4,13 +4,13 @@ use std::ops::Deref; #[derive(Debug)] pub struct Semver { - pub version: Option, + pub version: Version, } impl Semver { pub fn new(version: &str) -> crate::Result { Ok(Self { - version: Some(Version::parse(version)?), + version: Version::parse(version)?, }) } } @@ -20,8 +20,8 @@ pub fn semver(version: &str) -> crate::Result { } impl Deref for Semver { - type Target = Option; - fn deref(&self) -> &Option { + type Target = Version; + fn deref(&self) -> &Version { &self.version } } @@ -33,12 +33,19 @@ impl IntoLua for Semver { let mt = lua.create_table()?; let ts = lua.create_function(|_, luaself: LuaTable| { dbg!(luaself); - Ok("apply of") + Ok("stahoeu") + //Ok(format!( + // "{}.{}.{}", + // luaself.get("major")?, + // luaself.get("minor")?, + // luaself.get("patch")? + //)) })?; mt.set("__tostring", ts)?; semver.set_metatable(Some(mt)); - let dodad = lua.create_string("abra kad").unwrap(); - semver.set("dodad", dodad).unwrap(); + semver.set("major", self.version.major)?; + semver.set("minor", self.version.minor)?; + semver.set("patch", self.version.patch)?; Ok(LuaValue::Table(semver)) } }