Skip to content

Commit

Permalink
renamings and make sure docs get generated correct
Browse files Browse the repository at this point in the history
  • Loading branch information
makspll committed Apr 4, 2024
1 parent 3975b7a commit b2315ae
Show file tree
Hide file tree
Showing 10 changed files with 18 additions and 17 deletions.
4 changes: 2 additions & 2 deletions crates/bevy_script_api/src/core_providers.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::lua::RegisterForeignLuaType;

pub struct CoreBevyAPIProvider;
pub struct LuaCoreBevyAPIProvider;

#[derive(Default)]
pub(crate) struct CoreBevyGlobals;
Expand Down Expand Up @@ -28,7 +28,7 @@ impl bevy_mod_scripting_lua::tealr::mlu::ExportInstances for CoreBevyGlobals {
}
}

impl bevy_mod_scripting_core::hosts::APIProvider for CoreBevyAPIProvider {
impl bevy_mod_scripting_core::hosts::APIProvider for LuaCoreBevyAPIProvider {
type APITarget = std::sync::Mutex<bevy_mod_scripting_lua::tealr::mlu::mlua::Lua>;
type ScriptContext = std::sync::Mutex<bevy_mod_scripting_lua::tealr::mlu::mlua::Lua>;
type DocTarget = bevy_mod_scripting_lua::docs::LuaDocFragment;
Expand Down
4 changes: 2 additions & 2 deletions crates/bevy_script_api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ pub use {script_ref::*, sub_reflect::*};
pub mod prelude {
#[cfg(feature = "lua")]
pub use crate::{
core_providers::CoreBevyAPIProvider,
core_providers::LuaCoreBevyAPIProvider,
lua::{std::LuaVec, FromLuaProxy, IntoLuaProxy, LuaProxyable, ReflectLuaProxyable},
providers::BevyAPIProvider,
providers::LuaBevyAPIProvider,
LuaProxy,
};

Expand Down
4 changes: 2 additions & 2 deletions crates/bevy_script_api/src/providers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ pub(crate) mod bevy_window;
pub(crate) mod bevy_reflect;
extern crate self as bevy_script_api;
use bevy_mod_scripting_core::docs::DocFragment;
pub struct BevyAPIProvider;
impl bevy_mod_scripting_core::hosts::APIProvider for BevyAPIProvider {
pub struct LuaBevyAPIProvider;
impl bevy_mod_scripting_core::hosts::APIProvider for LuaBevyAPIProvider {
type APITarget = std::sync::Mutex<bevy_mod_scripting_lua::tealr::mlu::mlua::Lua>;
type ScriptContext = std::sync::Mutex<bevy_mod_scripting_lua::tealr::mlu::mlua::Lua>;
type DocTarget = bevy_mod_scripting_lua::docs::LuaDocFragment;
Expand Down
4 changes: 2 additions & 2 deletions examples/lua/bevy_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ fn main() -> std::io::Result<()> {
.register_foreign_lua_type::<Option<bool>>()
.register_foreign_lua_type::<Option<Vec<bool>>>()
.add_script_host::<LuaScriptHost<()>>(PostUpdate)
.add_api_provider::<LuaScriptHost<()>>(Box::new(BevyAPIProvider))
.add_api_provider::<LuaScriptHost<()>>(Box::new(CoreBevyAPIProvider))
.add_api_provider::<LuaScriptHost<()>>(Box::new(LuaBevyAPIProvider))
.add_api_provider::<LuaScriptHost<()>>(Box::new(LuaCoreBevyAPIProvider))
.add_systems(Startup,
|world: &mut World| {

Expand Down
2 changes: 1 addition & 1 deletion examples/lua/console_integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ fn main() -> std::io::Result<()> {
// choose and register the script hosts you want to use
.add_script_host::<LuaScriptHost<()>>(PostUpdate)
.add_api_provider::<LuaScriptHost<()>>(Box::new(LuaAPIProvider))
.add_api_provider::<LuaScriptHost<()>>(Box::new(CoreBevyAPIProvider))
.add_api_provider::<LuaScriptHost<()>>(Box::new(LuaCoreBevyAPIProvider))
.add_script_handler::<LuaScriptHost<()>, 0, 0>(PostUpdate)
// add your systems
.add_systems(Update, trigger_on_update_lua)
Expand Down
4 changes: 2 additions & 2 deletions examples/lua/documentation_gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ fn main() -> std::io::Result<()> {
// add the providers and script host
.add_script_host::<LuaScriptHost<MyLuaArg>>(PostUpdate)
.add_api_provider::<LuaScriptHost<MyLuaArg>>(Box::new(LuaAPIProvider))
.add_api_provider::<LuaScriptHost<MyLuaArg>>(Box::new(CoreBevyAPIProvider))
.add_api_provider::<LuaScriptHost<MyLuaArg>>(Box::new(BevyAPIProvider))
.add_api_provider::<LuaScriptHost<MyLuaArg>>(Box::new(LuaCoreBevyAPIProvider))
.add_api_provider::<LuaScriptHost<MyLuaArg>>(Box::new(LuaBevyAPIProvider))
// this needs to be placed after any `add_api_provider` and `add_script_host` calls
// it will generate `doc` and `types` folders under `assets/scripts` containing the documentation and teal declaration files
// respectively. See example asset folder to see how they look like. The `teal_file.tl` script in example assets shows the usage of one of those
Expand Down
2 changes: 1 addition & 1 deletion examples/lua/game_of_life.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ fn main() -> std::io::Result<()> {
.add_systems(FixedUpdate, send_on_update.after(update_rendered_state))
.add_systems(FixedUpdate, script_event_handler::<LuaScriptHost<()>, 0, 1>)
.add_script_host::<LuaScriptHost<()>>(PostUpdate)
.add_api_provider::<LuaScriptHost<()>>(Box::new(CoreBevyAPIProvider))
.add_api_provider::<LuaScriptHost<()>>(Box::new(LuaCoreBevyAPIProvider))
.add_api_provider::<LuaScriptHost<()>>(Box::new(LifeAPI));

app.run();
Expand Down
2 changes: 1 addition & 1 deletion examples/wrappers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ fn main() -> std::io::Result<()> {
.add_script_host::<LuaScriptHost<()>>(PostUpdate)
.register_type::<MyProxiedStruct>()
.init_resource::<MyProxiedStruct>()
.add_api_provider::<LuaScriptHost<()>>(Box::new(CoreBevyAPIProvider))
.add_api_provider::<LuaScriptHost<()>>(Box::new(LuaCoreBevyAPIProvider))
.add_systems(Startup, |world: &mut World| {
world.insert_resource(MyProxiedStruct {
my_string: "I was retrieved from the world".to_owned(),
Expand Down
5 changes: 3 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ Register your API providers like so:
app.add_plugins(DefaultPlugins)
.add_plugins(ScriptingPlugin)
.add_script_host::<LuaScriptHost<MyLuaArg>>(PostUpdate)
.add_api_provider::<LuaScriptHost<MyLuaArg>>(Box::new(LuaAPIProvider))
.add_api_provider::<LuaScriptHost<MyLuaArg>>(Box::new(LuaAPI))
//...
```
The `APIProvider` interface also includes `setup_script` and `get_doc_fragment` methods. By default, these methods do not perform any operation. However, they can be utilized for specific purposes. For instance, `get_doc_fragment` can be used to generate documentation (refer to examples), and `setup_script` can ensure a one-time setup per script, like setting up a Lua package path.
Expand All @@ -210,7 +210,8 @@ fn main() -> std::io::Result<()> {
.add_script_host::<LuaScriptHost<()>>(PostUpdate)
// Note: This is a noop in optimized builds unless the `doc_always` feature is enabled!
// this will pickup any API providers added *BEFOREHAND* like this one
// .add_api_provider::<LuaScriptHost<()>>(Box::new(LuaAPIProvider))
.add_api_provider::<LuaScriptHost<()>>(Box::new(LuaBevyAPIProvider))
.add_api_provider::<LuaScriptHost<()>>(Box::new(LuaCoreBevyAPIProvider))
.update_documentation::<LuaScriptHost<()>>()
.add_script_handler::<LuaScriptHost<()>, 0, 0>(PostUpdate);
Expand Down
4 changes: 2 additions & 2 deletions src/documentation/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ fn main() {
"lua" => {
#[cfg(all(feature = "lua", feature = "lua_script_api"))]
app.add_script_host::<LuaScriptHost<()>>(PostUpdate)
.add_api_provider::<LuaScriptHost<()>>(Box::new(CoreBevyAPIProvider))
.add_api_provider::<LuaScriptHost<()>>(Box::new(BevyAPIProvider))
.add_api_provider::<LuaScriptHost<()>>(Box::new(LuaCoreBevyAPIProvider))
.add_api_provider::<LuaScriptHost<()>>(Box::new(LuaBevyAPIProvider))
.update_documentation::<LuaScriptHost<()>>();

#[cfg(any(not(feature = "lua"), not(feature = "lua_script_api")))]
Expand Down

0 comments on commit b2315ae

Please sign in to comment.