-
-
Notifications
You must be signed in to change notification settings - Fork 98
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[NFY] Wrap semver::Version as Lua type
- Loading branch information
Showing
2 changed files
with
43 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,44 @@ | ||
use mlua::prelude::*; | ||
use semver::Version; | ||
use std::ops::Deref; | ||
|
||
pub fn foo() -> crate::Result<()> { | ||
eprintln!("Run"); | ||
Ok(()) | ||
#[derive(Debug)] | ||
pub struct Semver { | ||
pub version: Option<Version>, | ||
} | ||
|
||
impl Semver { | ||
pub fn new(version: &str) -> crate::Result<Self> { | ||
Ok(Self { | ||
version: Some(Version::parse(version)?), | ||
}) | ||
} | ||
} | ||
|
||
pub fn semver(version: &str) -> crate::Result<Semver> { | ||
Ok(Semver::new(version)?) | ||
Check failure on line 19 in src/types/semver.rs GitHub Actions / clippyquestion mark operator is useless here
|
||
} | ||
|
||
impl Deref for Semver { | ||
type Target = Option<Version>; | ||
fn deref(&self) -> &Option<Version> { | ||
&self.version | ||
} | ||
} | ||
|
||
impl IntoLua for Semver { | ||
#[inline] | ||
fn into_lua(self, lua: &Lua) -> LuaResult<LuaValue> { | ||
let semver = lua.create_table()?; | ||
let mt = lua.create_table()?; | ||
let ts = lua.create_function(|_, luaself: LuaTable| { | ||
dbg!(luaself); | ||
Ok("apply of") | ||
})?; | ||
mt.set("__tostring", ts)?; | ||
semver.set_metatable(Some(mt)); | ||
let dodad = lua.create_string("abra kad").unwrap(); | ||
semver.set("dodad", dodad).unwrap(); | ||
Ok(LuaValue::Table(semver)) | ||
} | ||
} |