Skip to content

Commit

Permalink
fixup! [NFY] Wrap semver::Version as Lua type
Browse files Browse the repository at this point in the history
  • Loading branch information
alerque committed Oct 10, 2024
1 parent c955bbf commit 9bf56fa
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
5 changes: 4 additions & 1 deletion rusile/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ use mlua::prelude::*;
fn rusile(lua: &Lua) -> LuaResult<LuaTable> {
let exports = lua.create_table().unwrap();
exports.set("demo", LuaFunction::wrap_raw(sile::rusile_demo))?;
exports.set("semver", LuaTable::wrap(sile::types::semver::Semver))?;
//exports.set(
// "semver",
// LuaFunction::wrap_raw(sile::types::semver::Semver::new),
//)?;
Ok(exports)
}
23 changes: 16 additions & 7 deletions src/types/semver.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,29 @@
use mlua::prelude::*;
use semver::Version;
use std::ops::Deref;

pub struct Semver {
version: Version,
pub version: Version,
}

impl Semver {
pub fn new(version: &str) -> crate::Result<Self> {
let version = Version::parse(version)?;
Ok(Semver { version })
}
}

impl Deref for Semver {
type Target = Version;
fn deref(&self) -> &Version {
&self.version
}
}

impl IntoLua for Semver {
#[inline]
fn into_lua(self, lua: &Lua) -> LuaResult<LuaValue> {
let semver = lua.create_table()?;
Ok(LuaValue::Table(semver))
//"just an str".into_lua(lua)
}
}

pub fn foo() -> crate::Result<()> {
eprintln!("Run");
Ok(())
}

0 comments on commit 9bf56fa

Please sign in to comment.