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

Can't run wrappers example #64

Closed
LaserWitch opened this issue Aug 20, 2023 · 5 comments
Closed

Can't run wrappers example #64

LaserWitch opened this issue Aug 20, 2023 · 5 comments

Comments

@LaserWitch
Copy link
Contributor

LaserWitch commented Aug 20, 2023

I've cloned the repository locally and tried to run the wrappers example from it with cargo run --example wrappers --features="lua lua54 lua_script_api". I get this result after the initial startup info line

ERROR bevy_mod_scripting_lua: Runtime error in script `script.lua` callback error
stack traceback:
        [C]: in field 'make_ref_to_my_resource'
        [string "script.lua"]:3: in function 'once'
caused by: error converting Lua nil to userdata
After script run: MyThing {
    usize: 420,
    string: "I live in the bevy world, you can't touch me!",
}

I've tried this test on both the main branch and the 0.11 branch with the same result

If I read the code correctly, I believe it's supposed to error in the second script run, but not the first. It appears that the issue comes from

fn "make_ref_to_my_resource" => |ctx,()| {
    let globals = ctx.globals();
    let lua_world : LuaWorld = globals.("world")?; //This lineA

I changed it to

let lua_world_o = globals.get("world");
info!("{:#?}",lua_world_o);
let lua_world  :LuaWorld = lua_world_o.unwrap();

and got

wrappers: 
INFO wrappers: Err(
    FromLuaConversionError {
        from: "nil",
        to: "userdata",
        message: None,
    },
)
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: FromLuaConversionError { from: "nil", to: "userdata", message: None }', examples/wrappers.rs:69:52
)

Getting access to the world like this is really the thing I need most out of the crate right now, so any help would be very appreciated.

@makspll
Copy link
Owner

makspll commented Aug 20, 2023

Hi I'll have a look! I was just looking at finalizing and releasing: #63, so if there is an issue in that example it will be fixed on main very soon.

@makspll
Copy link
Owner

makspll commented Aug 20, 2023

I think the issue is that "world" as a global has been moved into the BevyAPIProvider, which needs to be installed as in the bevy api examples

@LaserWitch
Copy link
Contributor Author

I can confirm that your latest changes on that branch make it run properly on my machine. Thanks!

@makspll
Copy link
Owner

makspll commented Aug 20, 2023

lovely, thanks for letting me know and good catch!

@LaserWitch
Copy link
Contributor Author

Resolved as of the 0.11 branch merge

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