Skip to content

Commit

Permalink
fixup! test(api): Mockup how to test a Rust function from Lua
Browse files Browse the repository at this point in the history
  • Loading branch information
alerque committed Jul 2, 2024
1 parent 3d2dc55 commit 5c1e88a
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
10 changes: 5 additions & 5 deletions rusile/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ use sile::rusile_demo;
#[mlua::lua_module]
fn rusile(lua: &Lua) -> LuaResult<LuaTable> {
let exports = lua.create_table().unwrap();
let foo: LuaFunction = lua.create_function(foo).unwrap();
exports.set("foo", foo)?;
let demo: LuaFunction = lua.create_function(demo).unwrap();
exports.set("demo", demo)?;
Ok(exports)
}

fn foo(lua: &Lua, (): ()) -> LuaResult<LuaString> {
let s = rusile_demo();
lua.create_string(s)
fn demo(lua: &Lua, (): ()) -> LuaResult<LuaString> {
let res = rusile_demo().unwrap();
lua.create_string(res)
}
4 changes: 2 additions & 2 deletions spec/rusile_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ describe("rusile", function ()
assert.is.truthy(SILE._rusile)
end)

describe("foo ", function ()
describe("demo ", function ()
it("should return a test string", function ()
local str = "Hello from rusile"
assert.is.equal(str, SILE._rusile.foo())
assert.is.equal(str, SILE._rusile.demo())
end)
end)

Expand Down
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,6 @@ fn paths_to_strings(paths: Vec<PathBuf>) -> Vec<String> {
paths.iter().map(path_to_string).collect()
}

pub fn rusile_demo() -> String {
"Hello from rusile".to_string()
pub fn rusile_demo() -> Result<String> {
Ok("Hello from rusile".to_string())
}

0 comments on commit 5c1e88a

Please sign in to comment.