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

Expose the proxy types for Bevy builtins #122

Open
Joakker opened this issue May 18, 2024 · 10 comments
Open

Expose the proxy types for Bevy builtins #122

Joakker opened this issue May 18, 2024 · 10 comments

Comments

@Joakker
Copy link
Contributor

Joakker commented May 18, 2024

I'm trying to create a lua function that takes an entity as argument to perform actions on it from rust. However, the compiler complains that the Entity type doesn't implement IntoLua.

A way of circumventing this specific problem is to call the Entity::to_bits method in lua, then have the function take a number as argument, which then is transformed back with Entity::from_bits in rust, but I feel like it's too much boilerplate for something that could be solved by simply exposing the implementation to the user.

@makspll
Copy link
Owner

makspll commented May 18, 2024

This is already the case, you might be confusing the dummy types in the generated provider files with the proxies which are generated by the macro. All proxies have a Lua prefix in the type name, for entity this is "LuaEntity" which you can use in your code to interact with the Builtins

@Joakker
Copy link
Contributor Author

Joakker commented May 18, 2024

I may have expressed myself wrong. Here's what I want to do

#[derive(..., Reflect, LuaProxy)]
#[reflect(LuaProxyable)]
#[proxy(
    derive(clone),
   function[
        r#"
            // Error: LuaEntity not in this scope!
            #[lua(kind = "MutatingMethod")]
            fn add(&mut self, #[proxy] character: Entity) { self.0.push(character) }
        "#
   ]
)]
pub struct GarrisonedCharacter(Vec<LuaEntity>)

I tried using just the Entity, but LuaProxy complains that Entity doesn't implement IntoLua, so I can't use either

@makspll
Copy link
Owner

makspll commented May 18, 2024

Hmm this should already work, is the Entity type imported and in scope? What's the exact error? And can you try proxying without an inlined body? (I.e. implement this function in rust fully)

Edit: oh but in your actual struct you should be working with Entities not LuaEntities

@Joakker
Copy link
Contributor Author

Joakker commented May 19, 2024

image

Entity is imported through use bevy::prelude::*;

@makspll
Copy link
Owner

makspll commented May 19, 2024

Try:

#[derive(..., Reflect, LuaProxy)]
#[reflect(LuaProxyable)]
#[proxy(
    derive(clone),
   function[
        r#"
            #[lua(kind = "MutatingMethod")]
           fn(&mut self, #[proxy] entity: Entity)
        "#
   ]
)]
pub struct GarrisonedCharacter(Vec<Entity>)

Impl GarrisonedCharacter {

   pub fn add(&mut self, entity: Entity) {
        self.0.push(entity)
   }
}

@Joakker
Copy link
Contributor Author

Joakker commented May 19, 2024

Nope, exactly the same error
image

@makspll
Copy link
Owner

makspll commented May 19, 2024

Oh I see the LuaEntity type is not in scope, can you import that

@Joakker
Copy link
Contributor Author

Joakker commented May 19, 2024

I can't. That's exactly what I was asking about, since LuaEntity doesn't seem to appear in bevy_mod_scripting, bevy_mod_scripting_lua, bevy_mod_scripting_lua, bevy_mod_scripting_core or bevy_script_api. I had to import all of those to get LuaProxy to work properly

@makspll
Copy link
Owner

makspll commented May 19, 2024

I can't. That's exactly what I was asking about, since LuaEntity doesn't seem to appear in bevy_mod_scripting, bevy_mod_scripting_lua, bevy_mod_scripting_lua, bevy_mod_scripting_core or bevy_script_api. I had to import all of those to get LuaProxy to work properly

Oh try the main branch of the library, it should be a public import there, but it's still unreleased

@Joakker
Copy link
Contributor Author

Joakker commented May 19, 2024

Ok, that seems to have worked, thank you 😄

However, the LuaProxy macro is still complaining that Entity doesn't implement FromLua. Any insight on how to deal with this?
image

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

2 participants