diff --git a/src/content.rs b/src/content.rs index 2663e10..e652414 100644 --- a/src/content.rs +++ b/src/content.rs @@ -12,7 +12,7 @@ pub enum Segment { Word(String), } -#[derive(Debug, Clone)] +#[derive(Clone, Debug)] #[non_exhaustive] pub struct Chunk { pub segments: Vec, diff --git a/src/lib.rs b/src/lib.rs index 8b34ebc..e3d8d7a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -45,6 +45,10 @@ pub fn to_case( } } +pub fn testf(_chunk: impl Into) -> Result { + Ok("some pseudo return data".into()) +} + /// Convert a string to title case following typesetting conventions for a target locale pub fn to_titlecase( chunk: impl Into, diff --git a/src/lua.rs b/src/lua.rs index 5bb6554..eaf16e2 100644 --- a/src/lua.rs +++ b/src/lua.rs @@ -6,6 +6,15 @@ use mlua::prelude::*; pub use crate::types::{Case, Locale, Result, StyleGuide}; +impl FromLua for Chunk { + fn from_lua(value: LuaValue, _: &Lua) -> LuaResult { + match value { + LuaValue::String(s) => Ok(s.to_string_lossy().into()), + _ => todo!(), + } + } +} + #[mlua::lua_module] fn decasify(lua: &Lua) -> LuaResult { let exports = lua.create_table().unwrap(); @@ -22,6 +31,7 @@ fn decasify(lua: &Lua) -> LuaResult { let version = option_env!("VERGEN_GIT_DESCRIBE").unwrap_or_else(|| env!("CARGO_PKG_VERSION")); let version = lua.create_string(version)?; exports.set("version", version).unwrap(); + exports.set("testf", LuaFunction::wrap_raw::<_, (Chunk,)>(testf))?; Ok(exports) }