Comments (4)
Ok so after searching a couple hours, I understood that I was supposed to use mlua. Here is a small example :
// You must add `mlua` as a dependency in your Cargo.toml file.
use mlua::prelude::{LuaFunction, LuaTable};
use nvim_oxi::{self as oxi, Dictionary, Function};
// I don't understand yet what is this `_none` parameter.
// I added it and it's working but I guess I'll need to understand why at some point.
fn mlua_test(_none: ()) -> oxi::Result<()> {
// You must also add feature `mlua` for nvim_oxi to your `Cargo.toml` as well.
let lua = oxi::mlua::lua();
// `lua.globals()` returns a reference to the global table of the Lua state.
// `LuaFunction` is the type of what you `get` from the global table.
// In this case it's a Lua function.
let require = lua.globals().get::<_, LuaFunction>("require")?;
// You can call this fuction like this to get the `telescope.builtin` table.
let telescope_builtin: LuaTable = require.call("telescope.builtin")?;
// I think that you get the point now.
let find_files = telescope_builtin.get::<_, LuaFunction>("find_files")?;
find_files.call(())?;
Ok(())
}
#[oxi::module]
pub fn my_module() -> oxi::Result<Dictionary> {
let mlua_test = Function::from_fn(mlua_test);
Ok(Dictionary::from_iter([("mlua_test", mlua_test)]))
}
After installing it, you can do:
nvim -c "lua require'my_module'.mlua_test()"
I guess that you can go there for more in depth mlua usage -> https://github.com/mlua-rs/mlua
from nvim-oxi.
// I don't understand yet what is this
_none
parameter.
You need to add it because Function::from_fn()
accepts a closure (or a function in this case) whose argument implements Poppable
. If your function doesn't take any arguments you can just use ()
, just like you did.
from nvim-oxi.
Hello ! I've got the same question. 😄
Moreover I think that it would be a good example.
from nvim-oxi.
I'll close this as completed but feel free to re-open it if you still have questions.
from nvim-oxi.
Related Issues (20)
- Issue when trying to use the api example open_window() command. HOT 5
- Trying to use oxi::api::call_function() but I'm not sure how to map into a dictionary HOT 1
- This crate is causing neovim to crash on the latest commit HOT 4
- Test complete API
- The libuv example doesn't work HOT 2
- Can't locate `lua_pushlstring`
- Simple code error, help! HOT 1
- How to perform the api of nvim in other processes HOT 1
- [Windows][Powershell7] cannot find type `PathBuf` in this scope HOT 3
- [Windows][Powershell7] linking with `link.exe` failed: exit code: 1120 HOT 5
- [Ubuntu] Error while calling lua chunk... undefined symbol: luaopen_... HOT 1
- support derive
- Crash when loading the example plugin on Windows HOT 29
- Test macro doesn't seem to pick up on failures HOT 6
- nvim_oxi::api::types::Mode doesn't allow for Remap ("m") mode HOT 2
- Add Installation Instructions HOT 1
- Variance issue for `Function`
- Doesn't detect panics properly
- Buffer.set_text() does not play nicely inside of a MutexGuard HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nvim-oxi.