Skip to main content

LanguageLoader

Trait LanguageLoader 

Source
pub trait LanguageLoader: Send + Sync {
    // Required methods
    fn load(&mut self, name: &str, code: Vec<String>) -> Result<bool, String>;
    fn call<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        proxy: &'life1 dyn Proxy,
        name: &'life2 str,
        args: Vec<String>,
    ) -> Pin<Box<dyn Future<Output = Result<SubroutineResult, String>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait;
}
Expand description

§Foreign Programming Language Object Macros

The LanguageLoader trait enables you to define a custom programming-language handler for RiveScript Object Macros written in languages other than Rust.

For example, a RiveScript document might define an object macro written in JavaScript like so:

> object reverse javascript
    let str = args.join(" ");
    return str.split('').reverse().join('');
< object

+ reverse *
- "<star>" spelled backwards is "<call>reverse <star></call>."

The load() function will receive the name of the object macro along with its source code (as lines of text). Your LanguageLoader might then parse and evaluate the code using your backing runtime or VM.

The call() function is invoked when a named object macro has been called via the <call> tag in a RiveScript reply. The name is the name of the object macro and the args are the parameters (using shell-style quoting rules, so a “quoted string” would come as one item of the Vec<String>).

Required Methods§

Source

fn load(&mut self, name: &str, code: Vec<String>) -> Result<bool, String>

Source

fn call<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, proxy: &'life1 dyn Proxy, name: &'life2 str, args: Vec<String>, ) -> Pin<Box<dyn Future<Output = Result<SubroutineResult, String>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Implementors§