Skip to content

Commit

Permalink
feat(api): Mockup how to use and test a Rust function from Lua
Browse files Browse the repository at this point in the history
  • Loading branch information
alerque committed Jun 25, 2024
1 parent f75715f commit 56c593f
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
4 changes: 4 additions & 0 deletions core/sile.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ SILE = {}
--- Fields
-- @section fields

--- Functions implemented in Rust, to be moved to approprate places in the API
-- @table SILE.rusile
SILE._rusile = require("rusile")

--- Machine friendly short-form version.
-- Semver, prefixed with "v", possible postfixed with ".r" followed by VCS version information.
-- @string version
Expand Down
6 changes: 6 additions & 0 deletions rusile/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,11 @@ use mlua::prelude::*;
#[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)?;
Ok(exports)
}

fn foo(lua: &Lua, (): ()) -> LuaResult<LuaString> {
lua.create_string("Hello from rusile")
}
16 changes: 16 additions & 0 deletions spec/rusile_spec.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
SILE = require("core.sile")

describe("rusile", function ()

it("should exist", function ()
assert.is.truthy(SILE._rusile)
end)

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

end)

0 comments on commit 56c593f

Please sign in to comment.