mlua icon indicating copy to clipboard operation
mlua copied to clipboard

Derive `FromLua`

Open ModProg opened this issue 2 years ago • 4 comments

While my use case might be a bit unusual (trying to implement the neovim api from lua, to write a plugin with mlua) the feature might have more useful use cases.

While Serialize can provide conversion for some things, mapping a Struct to a table containing Functions is not possible:

#[derive(FromLua)]
struct Api<'lua> {
    pub nvim_get_autocmds: LuaFunction<'lua>,
}

This could be achieved by providing a derive macro for FromLua.

I would be interested in implementing this.

ModProg avatar May 15 '22 12:05 ModProg

mapping a Struct to a table containing Functions is not possible:

Could you explain please? You can implement To/From Lua for structs that contains references to Lua.

Also if you don't want dealing with lifetimes, you could try to use RegistryKey instead and store functions in registry using Lua::create_registry_value

khvzak avatar May 15 '22 18:05 khvzak

mapping a Struct to a table containing Functions is not possible:

Could you explain please? You can implement To/From Lua for structs that contains references to Lua.

I know, and that is what I want to do. But it is only possible manually and not "derivable".

This is not about wanting a new feature, it's just about the derive macro.

ModProg avatar May 15 '22 19:05 ModProg

yes, I think this is a good idea! I need the same thing.

mrxiaozhuox avatar Aug 23 '22 22:08 mrxiaozhuox

I'm interested in working on this, and more. I'm currently writing an issue with more details

Mikadore avatar Nov 29 '22 22:11 Mikadore