Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crate that implements FromLua and ToLua without specifying/packaging a Lua version? #202

Open
Kampfkarren opened this issue Sep 8, 2022 · 4 comments

Comments

@Kampfkarren
Copy link

Kampfkarren commented Sep 8, 2022

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?

@coderedart
Copy link

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.

@khvzak
Copy link
Member

khvzak commented Sep 8, 2022

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.

@Kampfkarren
Copy link
Author

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

@lenscas
Copy link

lenscas commented Dec 21, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants