runtimelua

package module
v0.1.7 Latest Latest
Warning

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

Go to latest
Published: Jul 19, 2023 License: Apache-2.0 Imports: 26 Imported by: 0

README

Lua runtime framework

A lua framework which base on golang, support Redis pub/sub, ZeroMQ, HTTP, Event and Real-time hot reload.

Features

  • aes256 - AES-256 encryption and decryption.

  • base64 - Base64 encoding and decoding.

  • json - JSON encoding and decoding.

  • md5 - MD5 hash funtion.

  • uuid - UUID generator.

  • bit32 - 32 bit shifting.

  • bit64 - 64 bit shifting.

  • event - Event module for subscribing loop、delay events.

  • http - HTTP module for sending Http Request.

  • logger - Logger module for logging.

  • redis - Redis module to comminucate with redis sever, support pub/sub.

  • zmq (Optional build) - ZeroMQ module to create router and dealers.

  • Real-time hot reload - Support for lua hot reload when files changed.

Getting Started

A quick demostration of this framework can be found under example directory.

cd example && go run main.go

When launched you'll see each runtime informations in console output.

2023-05-08T14:54:20.449+0200 INFO runtimelua/scripts.go:364 Watching runtime directory {"vm": 0, "path": "/Users/user/runtimelua/example/script"} 2023-05-08T14:54:20.450+0200 DEBUG runtimelua/runtime.go:120 Runtime information {"vm": 0, "load": ["table", "os", "io", "string", "math", "coroutine", "package"]} 2023-05-08T14:54:20.450+0200 DEBUG runtimelua/runtime.go:123 Runtime information {"vm": 0, "preload": ["runtime", "json", "bit32", "base64", "event", "logger"]} 2023-05-08T14:54:20.451+0200 INFO runtimelua/scripts.go:364 Watching runtime directory {"vm": 1, "path": "/Users/user/runtimelua/example/script"} 2023-05-08T14:54:20.451+0200 DEBUG runtimelua/runtime.go:120 Runtime information {"vm": 1, "load": ["math", "coroutine", "package", "table", "os", "io", "string"]} 2023-05-08T14:54:20.451+0200 DEBUG runtimelua/runtime.go:123 Runtime information {"vm": 1, "preload": ["runtime", "json", "bit32", "base64", "event", "logger"]}

Building with ZeroMQ support

ZeroMQ require extra libraries dependency, so it's optional.

go build -tags zmq

Contribute

Contributions are always welcome.

License

This project is licensed under the Apache-2 License.

☕ Donation

If you like my project and also appericate for the effort. Don't hesitate to buy me a coffee😊.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewScriptModule

func NewScriptModule(logger *zap.Logger) *localScriptModule

Types

type Event

type Event interface {
	Valid() bool

	Update(time.Duration, *lua.LState) error

	Continue() bool

	Priority() int
}

type EventSequence

type EventSequence []Event

func (EventSequence) Len

func (s EventSequence) Len() int

func (EventSequence) Less

func (s EventSequence) Less(i, j int) bool

func (EventSequence) Swap

func (s EventSequence) Swap(i, j int)

type EventState

type EventState uint32
const (
	EVENT_STATE_INITIALIZE EventState = iota
	EVENT_STATE_PROGRESS
	EVENT_STATE_FINALIZE
	EVENT_STATE_COMPLETE
)

type EventType

type EventType struct{}

func (*EventType) Continue

func (p *EventType) Continue() bool

func (*EventType) Priority

func (p *EventType) Priority() int

func (*EventType) Update

func (p *EventType) Update(time.Duration, *lua.LState) error

func (*EventType) Valid

func (p *EventType) Valid() bool

type Module

type Module interface {
	Name() string
	Open() lua.LGFunction
}

type ModuleNames

type ModuleNames []string

func (ModuleNames) Len

func (a ModuleNames) Len() int

func (ModuleNames) Less

func (a ModuleNames) Less(i, j int) bool

func (ModuleNames) Swap

func (a ModuleNames) Swap(i, j int)

type Option

type Option interface {
	// contains filtered or unexported methods
}

func WithContext

func WithContext(ctx context.Context) Option

func WithEvaluation

func WithEvaluation(evaluation func(interface{})) Option

Evaluation handler which handle the return value of script entry.

func WithGlobal

func WithGlobal(key string, value interface{}) Option

Global variable which can be access within Lua runtime.

func WithLibAes128

func WithLibAes128() Option

func WithLibAes256

func WithLibAes256() Option

func WithLibBase64

func WithLibBase64() Option

func WithLibBit32

func WithLibBit32() Option

func WithLibBit64

func WithLibBit64() Option

func WithLibJson

func WithLibJson() Option

func WithLibMD5

func WithLibMD5() Option

func WithLibUUID

func WithLibUUID() Option

func WithLogger

func WithLogger(logger *zap.Logger) Option

func WithModule

func WithModule(mod Module) Option

func WithModuleEvent

func WithModuleEvent(logger *zap.Logger) Option

func WithModuleHttp

func WithModuleHttp(logger *zap.Logger) Option

func WithModuleLogger

func WithModuleLogger(logger *zap.Logger) Option

func WithModuleRedis

func WithModuleRedis(logger *zap.Logger, opts *redis.Options) Option

func WithRuntimeModule

func WithRuntimeModule(mod RuntimeModule) Option

func WithScriptEntry added in v0.1.5

func WithScriptEntry(path string) Option

The script path for the runtime entrypoint. Default is main.

func WithWaitGroup

func WithWaitGroup(wg *sync.WaitGroup) Option

type Runtime

type Runtime struct {
	EventQueue chan Event
	// contains filtered or unexported fields
}

func NewRuntime

func NewRuntime(scripts *localScriptModule, options ...Option) *Runtime

func NewRuntimeWithConfig

func NewRuntimeWithConfig(scripts ScriptModule, opts lua.Options, options ...Option) *Runtime

func (*Runtime) Shutdown

func (r *Runtime) Shutdown()

func (*Runtime) Startup

func (r *Runtime) Startup()

type RuntimeModule

type RuntimeModule interface {
	Module
	// Provide Initialization
	InitializeRuntime(*Runtime)
}

type ScriptModule

type ScriptModule interface {
	OpenPackage() lua.LGFunction

	List() []string
}

type StateEvent

type StateEvent struct {
	EventType
	// contains filtered or unexported fields
}

func (*StateEvent) Continue

func (e *StateEvent) Continue() bool

func (*StateEvent) Load

func (e *StateEvent) Load() uint32

func (*StateEvent) Stop

func (e *StateEvent) Stop()

func (*StateEvent) Store

func (e *StateEvent) Store(value uint32)

func (*StateEvent) Update

func (e *StateEvent) Update(d time.Duration, l *lua.LState) error

func (*StateEvent) Valid

func (e *StateEvent) Valid() bool

type TimerEvent

type TimerEvent struct {
	EventType

	Delay, Period time.Duration
	// contains filtered or unexported fields
}

func (*TimerEvent) Continue

func (e *TimerEvent) Continue() bool

func (*TimerEvent) Load

func (e *TimerEvent) Load() bool

func (*TimerEvent) Stop

func (e *TimerEvent) Stop()

func (*TimerEvent) Store

func (e *TimerEvent) Store(value bool)

func (*TimerEvent) Update

func (e *TimerEvent) Update(elapse time.Duration, l *lua.LState) error

func (*TimerEvent) Valid

func (e *TimerEvent) Valid() bool

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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