Documentation ¶
Overview ¶
This package is the Engine implementation for a javascript scripting interface. All callbacks are optional and the overhead for checking callback-existence is rather low, as it happens on script initialisation. All invocations of callbacks perform locking on the instance that they are being called on. Each instance has their own lock.
Index ¶
- type JavaScriptEngine
- func (engine *JavaScriptEngine) LoadScripts(dirname string) (err error)
- func (engine *JavaScriptEngine) OnMessageDelete(message *discordgo.Message)
- func (engine *JavaScriptEngine) OnMessageEdit(message *discordgo.Message)
- func (engine *JavaScriptEngine) OnMessageReceive(message *discordgo.Message)
- func (engine *JavaScriptEngine) OnMessageSend(oldText string) (newText string)
- func (engine *JavaScriptEngine) SetErrorOutput(errorOutput io.Writer)
- func (engine *JavaScriptEngine) SetGetCurrentChannelFunction(function func() string)
- func (engine *JavaScriptEngine) SetGetCurrentGuildFunction(function func() string)
- func (engine *JavaScriptEngine) SetPrintLineToConsoleFunction(function func(text string))
- func (engine *JavaScriptEngine) SetPrintToConsoleFunction(function func(text string))
- func (engine *JavaScriptEngine) SetTriggerNotificationFunction(function func(title, text string))
- type ScriptInstance
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type JavaScriptEngine ¶
type JavaScriptEngine struct {
// contains filtered or unexported fields
}
JavaScriptEngine stores scripting engine state
func New ¶
func New() *JavaScriptEngine
New instantiates a new scripting engine. The resulting object doesn't hold any data or VMs initially. Only upon loading scripts, VMs are created.
func (*JavaScriptEngine) LoadScripts ¶
func (engine *JavaScriptEngine) LoadScripts(dirname string) (err error)
LoadScripts implements Engine. Each script gets a designated Otto-VM in order to avoid scripts modifying each others state by accident. All available callbacks get eagerly evaluated in the beginning. Locking of the instances when calling one of the callbacks only happens, if a callback actually exists.
func (*JavaScriptEngine) OnMessageDelete ¶
func (engine *JavaScriptEngine) OnMessageDelete(message *discordgo.Message)
OnMessageDelete implements Engine
func (*JavaScriptEngine) OnMessageEdit ¶
func (engine *JavaScriptEngine) OnMessageEdit(message *discordgo.Message)
OnMessageEdit implements Engine
func (*JavaScriptEngine) OnMessageReceive ¶
func (engine *JavaScriptEngine) OnMessageReceive(message *discordgo.Message)
OnMessageReceive implements Engine
func (*JavaScriptEngine) OnMessageSend ¶
func (engine *JavaScriptEngine) OnMessageSend(oldText string) (newText string)
OnMessageSend implements Engine
func (*JavaScriptEngine) SetErrorOutput ¶
func (engine *JavaScriptEngine) SetErrorOutput(errorOutput io.Writer)
SetErrorOutput sets the writer to which errors can be written from inside the JavaScript engines.
func (*JavaScriptEngine) SetGetCurrentChannelFunction ¶
func (engine *JavaScriptEngine) SetGetCurrentChannelFunction(function func() string)
SetGetCurrentChannelFunction implements Engine
func (*JavaScriptEngine) SetGetCurrentGuildFunction ¶
func (engine *JavaScriptEngine) SetGetCurrentGuildFunction(function func() string)
SetGetCurrentGuildFunction implements Engine
func (*JavaScriptEngine) SetPrintLineToConsoleFunction ¶
func (engine *JavaScriptEngine) SetPrintLineToConsoleFunction(function func(text string))
SetPrintLineToConsoleFunction implements Engine
func (*JavaScriptEngine) SetPrintToConsoleFunction ¶
func (engine *JavaScriptEngine) SetPrintToConsoleFunction(function func(text string))
SetPrintToConsoleFunction implements Engine
func (*JavaScriptEngine) SetTriggerNotificationFunction ¶
func (engine *JavaScriptEngine) SetTriggerNotificationFunction(function func(title, text string))
SetTriggerNotificationFunction implements Engine
type ScriptInstance ¶
type ScriptInstance struct {
// contains filtered or unexported fields
}
ScriptInstance represents a usable and already loaded javascript. The callbacks are pre-evaluated and the instance can be locked as soon as any of the requested callbacks are available.