Skip to content

Commit

Permalink
remove extra import, fix lua to_string
Browse files Browse the repository at this point in the history
  • Loading branch information
makspll committed Jan 11, 2025
1 parent f7ce25b commit 7343b31
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
1 change: 1 addition & 0 deletions assets/scripts/game_of_life.lua
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ end
function on_click(x,y)
-- get the settings
world.info("Lua: Clicked at x: " .. x .. " y: " .. y)
print(entity)
local life_state = fetch_life_state()
local cells = life_state.cells

Expand Down
3 changes: 1 addition & 2 deletions crates/bevy_mod_scripting_functions/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use ::bevy::prelude::*;
use test_functions::register_test_functions;
#[cfg(feature = "bevy_bindings")]
pub mod bevy_bindings;
pub mod core;
Expand All @@ -16,7 +15,7 @@ impl Plugin for ScriptFunctionsPlugin {
register_bevy_bindings(app);
register_core_functions(app);
#[cfg(feature = "test_functions")]
register_test_functions(app);
test_functions::register_test_functions(app);

// TODO: if bevy ever does this itself we should remove this
app.world_mut().register_component::<Parent>();
Expand Down
19 changes: 14 additions & 5 deletions crates/languages/bevy_mod_scripting_lua/src/bindings/reference.rs
Original file line number Diff line number Diff line change
Expand Up @@ -395,13 +395,22 @@ impl UserData for LuaReflectReference {
)?))
});

m.add_meta_function(MetaMethod::ToString, |_, ()| {
m.add_meta_function(MetaMethod::ToString, |_, self_: LuaReflectReference| {
let world = ThreadWorldContainer.get_world();
let reflect_reference: ReflectReference = self_.into();

let func = lookup_function(world, [TypeId::of::<ReflectReference>()], "display")
.expect("No 'display' function registered for a ReflectReference");

Ok(LuaScriptValue(ScriptValue::Function(func)))
let func = lookup_function(
world.clone(),
[TypeId::of::<ReflectReference>()],
"display_ref",
)
.expect("No 'display' function registered for a ReflectReference");
let out = func.call(
vec![ScriptValue::Reference(reflect_reference)],
world,
LUA_CALLER_CONTEXT,
)?;
Ok(LuaScriptValue(out))
// let mut display_func =
// lookup_dynamic_function_typed::<ReflectReference>(lua, "display_ref")
// .expect("No 'display' function registered for a ReflectReference");
Expand Down

0 comments on commit 7343b31

Please sign in to comment.