feat: add mlua integration

This commit is contained in:
noib3 2022-08-08 00:28:29 +02:00
parent 456d44793f
commit 71e8f28ad6
No known key found for this signature in database
GPG key ID: 7AF92216C504A017
9 changed files with 67 additions and 3 deletions

View file

@ -0,0 +1,11 @@
[target.x86_64-apple-darwin]
rustflags = [
"-C", "link-arg=-undefined",
"-C", "link-arg=dynamic_lookup",
]
[target.aarch64-apple-darwin]
rustflags = [
"-C", "link-arg=-undefined",
"-C", "link-arg=dynamic_lookup",
]

11
examples/mlua/Cargo.toml Normal file
View file

@ -0,0 +1,11 @@
[package]
name = "lua"
version = "0.1.0"
edition = "2021"
[lib]
crate-type = ["cdylib"]
[dependencies]
nvim-oxi = { path = "../../nvim-oxi", features = ["mlua"] }
mlua = { version = "0.8", features = ["luajit"] }

4
examples/mlua/README.md Normal file
View file

@ -0,0 +1,4 @@
# mlua
`require("lua").greetings()` will print `"Hello from Rust.."` followed by
`"..and goodbye from Lua!"`.

17
examples/mlua/src/lib.rs Normal file
View file

@ -0,0 +1,17 @@
use mlua::prelude::LuaFunction;
use nvim_oxi::{self as oxi, Dictionary, Function};
fn greetings(_: ()) -> oxi::Result<()> {
oxi::print!("Hello from Rust..");
let lua = oxi::mlua::lua();
let print = lua.globals().get::<_, LuaFunction>("print")?;
print.call("..and goodbye from Lua!")?;
Ok(())
}
#[oxi::module]
fn lua() -> oxi::Result<Dictionary> {
Ok(Dictionary::from_iter([("greetings", Function::from_fn(greetings))]))
}