Documentation ¶
Index ¶
- Constants
- Variables
- func LogDebugf(L *lua.LState) int
- type Config
- type GameController
- type InputQueuer
- type Interpreter
- func (ip *Interpreter) AddCustomLoader(ld filesystem.RFileSystemPR) error
- func (ip *Interpreter) DoFile(file string) error
- func (ip Interpreter) DoString(src string) error
- func (ip Interpreter) EraCall(vname string) error
- func (ip Interpreter) EraCallBool(vname string) (bool, error)
- func (ip Interpreter) EraCallBoolArgInt(func_name string, arg int64) (bool, error)
- func (ip Interpreter) HasEraValue(vname string) bool
- func (ip *Interpreter) LoadDataOnSandbox(file, dataKey string) (map[string]string, error)
- func (ip Interpreter) LoadSystem() error
- func (ip *Interpreter) OpenTestingLibs(tc TestingController)
- func (ip Interpreter) PathOf(file string) string
- func (ip *Interpreter) Quit()
- func (ip *Interpreter) RemoveCustomLoader(ld filesystem.RFileSystemPR) error
- func (ip Interpreter) SetContext(ctx context.Context)
- type LoadPatternNotFoundError
- type TestingController
Constants ¶
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 #" )
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 )
const (
// era functions are included in this module.
EraModuleName = "era"
)
Variables ¶
var ( // default paramters for script VM. LoadPattern = "init.lua" CallStackSize = lua.CallStackSize RegistrySize = lua.RegistrySize InfiniteLoopTimeoutSecond = 10 * time.Second )
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 ¶
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 // get next scene name. NextSceneName() string // get current scene name. CurrentSceneName() string // 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
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.