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

Add support for Java object macros #10

Merged
merged 1 commit into from
Jun 28, 2016
Merged

Add support for Java object macros #10

merged 1 commit into from
Jun 28, 2016

Conversation

kirsle
Copy link
Member

@kirsle kirsle commented Jun 28, 2016

This finally adds support for compile-time Java object macros to be used, bringing the API function setSubroutine() that most of the other implementations have.

New API Features

  • void setSubroutine (String name, com.rivescript.ObjectMacro impl) -- to set an object macro written in Java at compile-time of your application.
  • string currentUser () -- retrieve the current user's ID from within a Java object macro.
  • string lastMatch (String username) -- retrieve the text of the last matched trigger for that user. The RSBot example bot calls this when you use the /last command.

Misc Changes

  • Version numbering is switching to semver, so com.rivescript.RiveScript.VERSION is a string now like "0.6.0"

Object Macro Example

To implement an object macro written in Java you must implement the ObjectMacro class. Example:

public class MyMacro implements com.rivescript.ObjectMacro {
    public String call (com.rivescript.RiveScript rs, String[] args) {
        return "Hello, Java!";
    }
}

And register it using the setSubroutine() API function:

rs.setSubroutine("mine", new MyMacro());

And it's callable within RiveScript:

+ test my macro
- Here goes nothing: <call>mine</call>

@kirsle kirsle merged commit c033ff8 into master Jun 28, 2016
@kirsle kirsle deleted the feature/java-macros branch June 28, 2016 22:29
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