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

Multiple Argument Hooks #129

Open
christianlarrabure opened this issue Sep 11, 2024 · 1 comment
Open

Multiple Argument Hooks #129

christianlarrabure opened this issue Sep 11, 2024 · 1 comment

Comments

@christianlarrabure
Copy link

Hey, I want to have some events that have no arguments and others that have other arguments. Right now my approach is this:
`rust

    app.add_plugins(ScriptingPlugin)
        .add_systems(Update, run_scripts)
        .add_systems(Update, (do_update, load_scripts, forward_errors, on_player_connected))
        .add_event::<ExecuteScriptDto>()
        .add_script_handler::<LuaScriptHost<()>, 0, 0>(PostUpdate)
        .add_script_handler::<LuaScriptHost<LuaEntity>, 0, 0>(PostUpdate)
        .add_script_host::<LuaScriptHost<()>>(PostUpdate)
        .add_script_host::<LuaScriptHost<LuaEntity>>(PostUpdate)
        .add_api_provider::<LuaScriptHost<LuaEntity>>(Box::new(UntoldDawnAPI))
        .add_api_provider::<LuaScriptHost<LuaEntity>>(Box::new(LuaBevyAPIProvider))
        .add_api_provider::<LuaScriptHost<LuaEntity>>(Box::new(LuaCoreBevyAPIProvider))
        .add_api_provider::<LuaScriptHost<()>>(Box::new(LuaBevyAPIProvider))
        .add_api_provider::<LuaScriptHost<()>>(Box::new(LuaCoreBevyAPIProvider))
        .add_api_provider::<LuaScriptHost<()>>(Box::new(UntoldDawnAPI));`

And then some events are:

rust fn do_update(mut lua_events: PriorityEventWriter<LuaEvent<()>>) { lua_events.send( LuaEvent { hook_name: "on_update".to_owned(), args: (), recipients: Recipients::All, }, 0, ) }

And others are:

rust fn on_player_connected( query: Query<Entity, Added<PlayerConnection>>, mut lua_events: PriorityEventWriter<LuaEvent<LuaEntity>>, ) { for item in query.iter() { lua_events.send( LuaEvent { hook_name: "internal_onPlayerConnected".to_owned(), args: LuaEntity::new(item), recipients: Recipients::All, }, 0, ) } }

However, this doesn't seem to work?
Any ideas?

@makspll
Copy link
Owner

makspll commented Sep 11, 2024

Hey! It looks like you're using multiple separate script hosts, which should work but is not really how the library was intended to be used. Because the lua script host supports anything that converts into lua via IntoLuaMulti you should be able to have a single enum type on which you implement IntoLuaMulti yourself to get this behavior

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