Open Joakker opened 3 months ago
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
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
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
Entity
is imported through use bevy::prelude::*;
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)
}
}
Nope, exactly the same error
Oh I see the LuaEntity type is not in scope, can you import that
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
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
orbevy_script_api
. I had to import all of those to getLuaProxy
to work properly
Oh try the main branch of the library, it should be a public import there, but it's still unreleased
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?
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 implementIntoLua
.A way of circumventing this specific problem is to call the
Entity::to_bits
method in lua, then have the function take anumber
as argument, which then is transformed back withEntity::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.