Documentation
¶
Index ¶
- func Compile(options ...CompileArg) (*program.Program, error)
- func NoCodeCompression(ca *CompileArgs)
- func NoCodeFolding(ca *CompileArgs)
- func NoDeadCodeElimination(ca *CompileArgs)
- type CompileArg
- func ASTOutput(w io.Writer) CompileArg
- func AsmOutput(w io.Writer) CompileArg
- func CompilerInput(r io.Reader) CompileArg
- func CompilerOutput(w io.Writer) CompileArg
- func ErrOutput(w io.Writer) CompileArg
- func LexOutput(w io.Writer) CompileArg
- func ParseOutput(w io.Writer) CompileArg
- func PostProcessOutput(w io.Writer) CompileArg
- func TextOutput(w io.Writer) CompileArg
- type CompileArgs
- type ExecutionType
- type Function
- type NewVMOption
- func HandleEndDialogue(handler func(*VM)) NewVMOption
- func HandleEnterNode(handler func(*VM, string) ExecutionType) NewVMOption
- func HandleExitNode(handler func(*VM, string) ExecutionType) NewVMOption
- func HandleShowChoice(handler func(*VM, []string) ExecutionType) NewVMOption
- func HandleShowLine(handler func(*VM, string) ExecutionType) NewVMOption
- func RegisterCallback(function Function) NewVMOption
- type VM
- func (vm *VM) Choose(selectedChoice int) error
- func (vm *VM) GetVariable(name string) (val asm.Value, exists bool)
- func (vm *VM) Reset()
- func (vm *VM) Resume() error
- func (vm *VM) Run() error
- func (vm *VM) SetVariableBoolean(name string, val bool)
- func (vm *VM) SetVariableNull(name string)
- func (vm *VM) SetVariableNumber(name string, val int)
- func (vm *VM) SetVariableString(name string, val string)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Compile ¶
func Compile(options ...CompileArg) (*program.Program, error)
Compile tranlates a Script from text into its executable form. Any reads errors, syntax errors, semantic errors, or write errors will result in an error being returned.
func NoCodeCompression ¶
func NoCodeCompression(ca *CompileArgs)
func NoCodeFolding ¶
func NoCodeFolding(ca *CompileArgs)
func NoDeadCodeElimination ¶
func NoDeadCodeElimination(ca *CompileArgs)
Types ¶
type CompileArg ¶
type CompileArg func(*CompileArgs)
func ASTOutput ¶
func ASTOutput(w io.Writer) CompileArg
func AsmOutput ¶
func AsmOutput(w io.Writer) CompileArg
func CompilerInput ¶
func CompilerInput(r io.Reader) CompileArg
func CompilerOutput ¶
func CompilerOutput(w io.Writer) CompileArg
func ErrOutput ¶
func ErrOutput(w io.Writer) CompileArg
func LexOutput ¶
func LexOutput(w io.Writer) CompileArg
func ParseOutput ¶
func ParseOutput(w io.Writer) CompileArg
func PostProcessOutput ¶
func PostProcessOutput(w io.Writer) CompileArg
func TextOutput ¶
func TextOutput(w io.Writer) CompileArg
type CompileArgs ¶
type CompileArgs struct {
// contains filtered or unexported fields
}
type ExecutionType ¶
type ExecutionType int
ExecutionType tells the VM whether to suspend ot keep running after a callback is executed.
const ( // PauseExecution tells the VM to suspend PauseExecution ExecutionType = iota // ContinueExecution tells the VM to keep running ContinueExecution // WaitingForChoiceExecution tells the VM we haven't made a choice yet WaitingForChoiceExecution )
type Function ¶
type Function struct {
// Func is the actual code which handles the events
Func func(vm *VM, args ...asm.Value) ExecutionType
}
Function is a callback for custom events fired with the Call instruction.
type NewVMOption ¶
NewVMOption is a builder-like function for instantiating a new VM
func HandleEndDialogue ¶
func HandleEndDialogue(handler func(*VM)) NewVMOption
HandleEndDialogue assigns a handler for the EndDialogue event. Pass as an option to NewVM.
func HandleEnterNode ¶
func HandleEnterNode(handler func(*VM, string) ExecutionType) NewVMOption
HandleEnterNode assigns a handler for the EnterNode event. Pass as an option to NewVM.
func HandleExitNode ¶
func HandleExitNode(handler func(*VM, string) ExecutionType) NewVMOption
HandleExitNode assigns a handler for the ExitNode event. Pass as an option to NewVM.
func HandleShowChoice ¶
func HandleShowChoice(handler func(*VM, []string) ExecutionType) NewVMOption
HandleShowChoice assigns a handler for the ShowChoice event. Pass as an option to NewVM.
func HandleShowLine ¶
func HandleShowLine(handler func(*VM, string) ExecutionType) NewVMOption
HandleShowLine assigns a handler for the ShowLine event. Pass as an option to NewVM.
func RegisterCallback ¶
func RegisterCallback(function Function) NewVMOption
RegisterCallback assigns a handler for a custom event which can be fired with the Call instruction.
type VM ¶
type VM struct {
// contains filtered or unexported fields
}
VM is the virtual machine which runs the instructions generated by the dialogue tree.
func NewVM ¶
func NewVM(program *program.Program, options ...NewVMOption) (*VM, error)
NewVM instantiates a new VM.
func (*VM) Choose ¶
ChooseAndResume will notify the VM that an option was selected and resumes from the decision point according to the option chosen. Which options are available are given by the ShowChoice event, which is fired at the decision point and puts the VM into a waiting state until an option is chosen.
func (*VM) GetVariable ¶
GetVariable retrieves a named variable saved by the StoreVariable instruction or by the SetVarableT() series of methods. If the variable does not exist, val is Null and exists is false.
func (*VM) Reset ¶
func (vm *VM) Reset()
Reset stops a VM and clears its variables so that the next time it runs, it will be as if running for the first time.
func (*VM) Run ¶
Run executes the program from its start point. Assigned variables are persisted across runs.
func (*VM) SetVariableBoolean ¶
SetVariableBoolean stores val as a boolean under the given name. Name strings are converted into symbol values. Saved variables are persisted across runs.
func (*VM) SetVariableNull ¶
SetVariableNull stores a null value under the given name. Name strings are converted into symbol values. Saved variables are persisted across runs.
func (*VM) SetVariableNumber ¶
SetVariableNumber stores val as a number under the given name. Name strings are converted into symbol values. Saved variables are persisted across runs.
func (*VM) SetVariableString ¶
SetVariableString stores val as a string under the given name. Name strings are converted into symbol values. Saved variables are persisted across runs.