From 5952a1f709df38bd7b74edd815620f16225dcf8e Mon Sep 17 00:00:00 2001 From: Alex Orlenko Date: Sun, 31 May 2020 12:16:47 +0100 Subject: New `module` feature Don't link module with Lua core (see: http://lua-users.org/wiki/BuildingModules) Example and tests for modules --- examples/module/.cargo/config | 5 +++++ examples/module/Cargo.toml | 20 ++++++++++++++++++++ examples/module/src/lib.rs | 12 ++++++++++++ 3 files changed, 37 insertions(+) create mode 100644 examples/module/.cargo/config create mode 100644 examples/module/Cargo.toml create mode 100644 examples/module/src/lib.rs (limited to 'examples/module') diff --git a/examples/module/.cargo/config b/examples/module/.cargo/config new file mode 100644 index 0000000..15d5d32 --- /dev/null +++ b/examples/module/.cargo/config @@ -0,0 +1,5 @@ +[target.x86_64-apple-darwin] +rustflags = [ + "-C", "link-arg=-undefined", + "-C", "link-arg=dynamic_lookup", +] diff --git a/examples/module/Cargo.toml b/examples/module/Cargo.toml new file mode 100644 index 0000000..ee03306 --- /dev/null +++ b/examples/module/Cargo.toml @@ -0,0 +1,20 @@ +[package] +name = "rust_module" +version = "0.0.0" +authors = ["Aleksandr Orlenko "] +edition = "2018" + +[lib] +crate-type = ["cdylib"] + +[features] +lua54 = ["mlua/lua54"] +lua53 = ["mlua/lua53"] +lua52 = ["mlua/lua52"] +lua51 = ["mlua/lua51"] +luajit = ["mlua/luajit"] +vendored = ["mlua/vendored"] + +[dependencies] +mlua = { path = "../..", features = ["module"] } +mlua_derive = { path = "../../mlua_derive" } diff --git a/examples/module/src/lib.rs b/examples/module/src/lib.rs new file mode 100644 index 0000000..0c742f5 --- /dev/null +++ b/examples/module/src/lib.rs @@ -0,0 +1,12 @@ +use mlua::prelude::*; + +fn sum(_: &Lua, (a, b): (i64, i64)) -> LuaResult { + Ok(a + b) +} + +#[mlua_derive::lua_module] +fn rust_module(lua: &Lua) -> LuaResult { + let exports = lua.create_table()?; + exports.set("sum", lua.create_function(sum)?)?; + Ok(exports) +} -- cgit v1.2.3