mlua
mlua copied to clipboard
Crate that implements FromLua and ToLua without specifying/packaging a Lua version?
Hello, I am making a crate that implements an mlua compatibility layer with another crate I maintain, so that me and others can create separate mlua apps and use that.
Basically, I have crate full-moon
, and would like to create a full-moon-lua-types
crate, so that anyone who uses full-moon can use the lua-types crate to add plugin support and such. This is necessary for selene to implement custom plugins.
However, I cannot simply depend on mlua, since I need to specify a version. I can specify a version, of course, but then I believe it will try to package the source code, or other weirdness.
Is there any way to get what I want?
crates like bevy_mod_scripting or tealr just forward the lua version features. https://github.com/lenscas/tealr/blob/master/Cargo.toml#L27
if all your plugin crates need to use a specific lua version, then, just rely on that feature. if different plugins might need different lua versions, then forward all those features via your crate and they can pick and choose.
The (Lua) source code is only packaged with vendored
or luau
option.
I'd love to move some types def to a new crate, but I'm afraid the current definition of ToLua
and FromLua
does not allow to do this:
pub trait ToLua<'lua> {
fn to_lua(self, lua: &'lua Lua) -> Result<Value<'lua>>;
}
pub trait FromLua<'lua>: Sized {
fn from_lua(lua_value: Value<'lua>, lua: &'lua Lua) -> Result<Self>;
}
As it has &Lua
argument which is defined in the mlua
crate.
The (Lua) source code is only packaged with vendored or luau option.
Ouch, I am using luau 🙂
I think it will end up fine in the long run for me. I'll leave this issue up in case you think this is something worth solving
crates like bevy_mod_scripting or tealr just forward the lua version features. https://github.com/lenscas/tealr/blob/master/Cargo.toml#L27
if all your plugin crates need to use a specific lua version, then, just rely on that feature. if different plugins might need different lua versions, then forward all those features via your crate and they can pick and choose.
bit late, but part of that is because tealr's own api has to change depending on the lua version enabled in mlua. If I didn't then I could still only target basically 1 lua version or only allow things to be used that is common in all lua versions. Not great either way.
I also don't think that just forwarding the features will work for other libraries. Tealr has the benefit of basically being a wrapper around mlua to give new features. But full-moon
doesn't sound like a library that wraps around mlua but would rather be used along side it. So, just reexposing the same features means it is up to the user to keep them equal. Doesn't sound great to me.