Skip to content

Conversation

makspll
Copy link
Owner

@makspll makspll commented Jul 4, 2022

Changes APIprovider interface to:

/// Implementors can modify a script context in order to enable
/// API access. ScriptHosts call `attach_api` when creating scripts
pub trait APIProvider: 'static + Send + Sync {
    /// the type of script engine/context the API is attached to, this must be the same as the APITarget of the ScriptHost meant to receive it.
    type APITarget: Send + Sync + 'static;
    /// The type of script context the APIProvider works with, must be the same as the ScriptContext of the target ScriptHost.
    type ScriptContext;
    /// The type of documentation fragment produced by the APIProvider, must be the same as the DocTarget of the target ScriptHost.
    type DocTarget: DocFragment;
    /// The type of script asset, must be the same as the ScriptAsset of the target ScriptHost
    // type ScriptAsset : CodeAsset;
    
    /// provide the given script context with the API permamently.
    /// Depending on the host, API's may be attached on a per-script basis
    /// or on a per-engine basis. Rhai for example allows you to decouple the State of each script from the
    /// engine. For one-time setup use `Self::setup_script` 
    fn attach_api(&mut self, ctx: &mut Self::APITarget) -> Result<(), ScriptError>;

    /// Setup meant to be executed once for every single script. Use this if you need to consistently setup scripts.
    /// For API's use `Self::attach_api` instead.
    fn setup_script(&mut self, script_data: &ScriptData,ctx: &mut Self::ScriptContext) -> Result<(), ScriptError>;

    fn get_doc_fragment(&self) -> Option<Self::DocTarget> {
        None
    }
}

Means that script hosts can setup the API once (as rhai can) but also provide one time setup for scripts depending on some script properties

@makspll makspll merged commit 8d1bf7a into main Jul 4, 2022
@makspll makspll deleted the add-once-script-setup branch January 20, 2025 14:28
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

Successfully merging this pull request may close these issues.

1 participant