script

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2023 License: BSD-3-Clause Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// non-error but requires quiting the application.
	ScriptQuitMessage = "# EXIT NORMALY #"

	// non-error but interrupts script execution.
	ScriptLongReturnMessage = "# LONG RETURN #"

	// non-error but requires quiting current scene flow and starts next scene.
	ScriptGoToNextSceneMessage = "# GOTO NEXT SCENE #"
)
View Source
const (
	// Maximum integer number to maintain accuracy in Interpreter.
	// Since log10(MaxInteger) = 15.95...,
	// a number upto 10^15 is completely supported, and
	// upto 10^16 is partialy supported.
	MaxInteger = (1 << 53) - 1

	// Maximum number in Interpreter.
	MaxNumber = math.MaxFloat64
)
View Source
const (
	// era functions are included in this module.
	EraModuleName = "era"
)

Variables

View Source
var (
	// default paramters for script VM.
	LoadPattern               = "init.lua"
	CallStackSize             = lua.CallStackSize
	RegistrySize              = lua.RegistrySize
	InfiniteLoopTimeoutSecond = 10 * time.Second
)
View Source
var (
	// ErrWatchDogtimerExpired indicates script execution takes too long time, it may be infinite loop.
	ErrWatchDogTimerExpired = errors.New("script execution takes too long time, may be infinite loop")
)

Functions

func LogDebugf

func LogDebugf(L *lua.LState) int

+gendoc * log.debugf(fmt_string, [any...])

Debugレベルで、fmt_stringをログファイルに出力します。 fmt_string中の特殊文字(例えば、%v)は、anyで置き換えられます。 特殊文字の詳細は、Golangのfmtパッケージを参照 (https://godoc.org/fmt)。 この関数はデバッグモード時のみ動作します。

Types

type Config

type Config struct {
	LoadDir     string
	LoadPattern string

	CallStackSize       int
	RegistrySize        int
	IncludeGoStackTrace bool

	InfiniteLoopTimeoutSecond int
	ReloadFileChange          bool
}

ScriptConfig holds Script parameters.

type GameController

type GameController interface {
	scene.IOController

	// scene controll
	//
	// do multiple trains defined by commands.
	DoTrainsScene(commands []int64) error

	// starting scene of loading game data.
	DoLoadGameScene() error
	// starting scene of saving game data.
	DoSaveGameScene() error

	// set next scene specified by its name.
	SetNextSceneByName(name string) error

	// register new scene flow using its name and the function desclibeing its flow.
	// next_func must return next scene name to move to next flow.
	RegisterSceneFunc(name string, next_func func() (string, error))

	// remove registered scene specified name.
	UnRegisterScene(name string)
}

game controller controlls game flow, input, output, ... etc.

type InputQueuer added in v0.8.0

type InputQueuer interface {
	Append(x string) (n int)
	Prepend(x string) (n int)
	Clear()
	Size() int
}

InputQueuer is an interface for the queue of user input commands. It's values can be retrieved from GameController.InputXXX.

type Interpreter

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

Interpreter parse script files. it runs user script in the strict environment.

typical usage:

ip := NewInterpreter(...)
defer ip.Quit()

func NewInterpreter

func NewInterpreter(s *state.GameState, g GameController, config Config) *Interpreter

construct interpreter. must be call Interpreter.Quit after use this.

func (*Interpreter) AddCustomLoader added in v0.5.0

func (ip *Interpreter) AddCustomLoader(ld filesystem.RFileSystemPR) error

func (*Interpreter) DoFile

func (ip *Interpreter) DoFile(file string) error

do given script on internal VM.

func (Interpreter) DoString

func (ip Interpreter) DoString(src string) error

DoString runs given src text as script.

func (Interpreter) EraCall

func (ip Interpreter) EraCall(vname string) error

call funtion vname in era module.

func (Interpreter) EraCallBool

func (ip Interpreter) EraCallBool(vname string) (bool, error)

call funtion vname in era module and return a bool value.

func (Interpreter) EraCallBoolArgInt

func (ip Interpreter) EraCallBoolArgInt(func_name string, arg int64) (bool, error)

call funtion vname in era module with argument int64, and return a bool value. To cover all range of int, argument requires int64

func (Interpreter) HasEraValue

func (ip Interpreter) HasEraValue(vname string) bool

VM has given value name in era module?

func (*Interpreter) LoadDataOnSandbox added in v0.3.0

func (ip *Interpreter) LoadDataOnSandbox(file, dataKey string) (map[string]string, error)

do given script file on internal VM with sandbox environment. Return data table queried by the dataKey.

func (Interpreter) LoadSystem

func (ip Interpreter) LoadSystem() error

load all files matched to config pattern. it is used for loading user scirpts under specified directory. If any files not found to be loaded, it returns LoadPattenNotFoundError. And other cases in failure, It returns arbitrary error type.

func (*Interpreter) OpenTestingLibs added in v0.8.0

func (ip *Interpreter) OpenTestingLibs(tc TestingController)

OpenTestingLibs enables the features used for only testing. Such features are useful for development purpose such as unit testing. The test feature is disabled at default.

func (Interpreter) PathOf

func (ip Interpreter) PathOf(file string) string

return Path of Under Script Dir

func (*Interpreter) Quit

func (ip *Interpreter) Quit()

Quit quits virtual machine in Interpreter. use it for releasing resources.

func (*Interpreter) RemoveCustomLoader added in v0.5.0

func (ip *Interpreter) RemoveCustomLoader(ld filesystem.RFileSystemPR) error

func (Interpreter) SetContext

func (ip Interpreter) SetContext(ctx context.Context)

set context to internal virtual machine. context must not be nil. It also starts Watch Dog Timer (WDT) which detect infinite loop on script and terminate execution with raise error.

type LoadPatternNotFoundError added in v0.7.0

type LoadPatternNotFoundError = os.PathError

LoadPatternNotFoundError indicates Config.LoadDir and Config.LoadPattern are not matched any files.

type TestingController added in v0.8.0

type TestingController interface {
	InputQueuer
}

TestingController is an interface to define features accesible only testing mode.

Jump to

Keyboard shortcuts

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