rivescript_js

package
v0.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 18, 2016 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package rivescript_js implements JavaScript object macros for RiveScript.

Usage is simple. In your Golang code:

import (
	rivescript "github.com/aichaos/rivescript-go"
	"github.com/aichaos/rivescript-go/lang/rivescript_js"
)

func main() {
	bot := rivescript.New()
	jsHandler := rivescript_js.New(bot)
	bot.SetHandler("javascript", jsHandler)

	// and go on as normal
}

And in your RiveScript code, you can load and run JavaScript objects:

> object add javascript
	var a = args[0];
	var b = args[1];
	return parseInt(a) + parseInt(b);
< object

> object setname javascript
	// Set the user's name via JavaScript
	var uid = rs.CurrentUser();
	rs.SetUservar(uid, args[0], args[1])
< object

+ add # and #
- <star1> + <star2> = <call>add <star1> <star2></call>

+ my name is *
- I will remember that.<call>setname <id> <formal></call>

+ what is my name
- You are <get name>.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type JavaScriptHandler

type JavaScriptHandler struct {
	// contains filtered or unexported fields
}

func New

New creates an object handler for JavaScript with its own Otto VM.

func (JavaScriptHandler) Call

func (js JavaScriptHandler) Call(name string, fields []string) string

Call executes a JavaScript macro and returns its results.

func (JavaScriptHandler) Load

func (js JavaScriptHandler) Load(name string, code []string)

Load loads a new JavaScript object macro into the VM.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL