Documentation
¶
Index ¶
- func GetVMSymbol[T any](vm VM, name string) (T, error)
- func GetVMSymbolPtr[T any](vm VM, name string) (*T, error)
- func OnEvent(vm VM, event string)
- func OnFrame(vm VM)
- func Register(r RuntimeInfo)
- func WithEngine(ctx context.Context, g Engine) context.Context
- type BaseVM
- type Engine
- type ErrIncorrectSymbolType
- type RuntimeInfo
- type VM
- type Writer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetVMSymbol ¶
GetVMSymbol is a generic helper for VM.GetSymbol. It is suitable for functions mostly, since it returns value directly, not a pointer.
func GetVMSymbolPtr ¶
GetVMSymbolPtr is a generic helper for VM.GetSymbol. It is similar to GetVMSymbol, but returns a pointer to the value. Useful for variables.
Types ¶
type Engine ¶
type Engine interface {
// Frame returns current server tick/frame number.
Frame() int
// Time returns relative time from server start.
Time() time.Duration
// Console returns script console.
Console(error bool) Writer
}
Engine is an interface to the game engine.
type ErrIncorrectSymbolType ¶
func (*ErrIncorrectSymbolType) Error ¶
func (e *ErrIncorrectSymbolType) Error() string
type RuntimeInfo ¶
type RuntimeInfo struct {
// Name is a short name for the VM runtime. Must be unique.
Name string
// Title is a human-friendly name for the VM runtime.
Title string
// NewMap creates a new script VM for map scripts.
// If there's no scripts for the map, function may return nil, nil.
NewMap func(g Engine, maps string, name string) (VM, error)
}
RuntimeInfo is a type for registering new script runtime implementations.
type VM ¶
type VM interface {
// GetEngine returns Engine used by this VM.
GetEngine() Engine
// Stdout returns standard output used by this VM.
Stdout() Writer
// Stderr returns error output used by this VM.
Stderr() Writer
// Exec executes text as a script source code.
Exec(s string) (reflect.Value, error)
// ExecFile executes a script from the file or directory.
ExecFile(path string) error
// GetSymbol tries to find a function or variable with a given name and type.
// If symbol is found, but type doesn't match, it returns an error.
// If symbol is not found, it returns reflect.Value{}, false, nil.
GetSymbol(name string, typ reflect.Type) (reflect.Value, bool, error)
// Close the VM and free resources.
Close() error
// contains filtered or unexported methods
}
VM is an interface for a virtual machine running the script engine.
Click to show internal directories.
Click to hide internal directories.