lua51plugin

package
v0.0.0-...-18e76e9 Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2021 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultNamespace = "system"
View Source
const ModuleIDOpenlib = "builtin.openlib"
View Source
const ModuleIDParam = "builtin.param"
View Source
const ModuleIDPrint = "builtin.print"
View Source
const PluginType = "lua51"

Variables

View Source
var ModuleOpenlib = herbplugin.CreateModule(
	ModuleIDOpenlib,
	func(ctx context.Context, p herbplugin.Plugin, next func(ctx context.Context, plugin herbplugin.Plugin)) {
		plugin := p.(LuaPluginLoader).LoadLuaPlugin()
		plugin.LState.OpenLibs()

		if !plugin.PluginOptions().MustAuthorizePermission(herbplugin.PermissionDangerousAPI) {
			for _, v := range safetycommands {
				err := plugin.LState.DoString(v)
				if err != nil {
					panic(err)
				}
			}
			loLoaders := pluginLoaders(plugin)
			loaders := plugin.LState.CreateTable(len(loLoaders), 0)
			for i, loader := range loLoaders {
				plugin.LState.RawSetInt(loaders, i+1, plugin.LState.NewFunction(loader))
			}
			plugin.LState.SetField(plugin.LState.Get(lua.RegistryIndex), "_LOADERS", loaders)
			plugin.LState.SetGlobal("dofile", plugin.LState.NewFunction(pluginDoFile(plugin)))
			plugin.LState.SetGlobal("loadfile", plugin.LState.NewFunction(pluginLoadFile(plugin)))
		}
		next(ctx, plugin)
	},
	nil,
	nil,
)
View Source
var ModuleParam = herbplugin.CreateModule(
	ModuleIDParam,
	func(ctx context.Context, p herbplugin.Plugin, next func(ctx context.Context, plugin herbplugin.Plugin)) {
		plugin := p.(LuaPluginLoader).LoadLuaPlugin()
		plugin.Builtin["getparam"] = func(L *lua.LState) int {
			name := L.ToString(1)
			L.Push(lua.LString(p.PluginOptions().GetParam(name)))
			return 1
		}
		next(ctx, plugin)
	},
	nil,
	nil,
)
View Source
var ModulePrint = herbplugin.CreateModule(
	ModuleIDPrint,
	func(ctx context.Context, p herbplugin.Plugin, next func(ctx context.Context, plugin herbplugin.Plugin)) {
		plugin := p.(LuaPluginLoader).LoadLuaPlugin()
		plugin.LState.SetGlobal("print", plugin.LState.NewFunction(func(L *lua.LState) int {
			info := L.ToString(1)
			plugin.PluginPrint(info)
			return 0
		}))
		next(ctx, plugin)
	},
	nil,
	nil,
)

Functions

func AppendCommonModules

func AppendCommonModules(i *Initializer)

Types

type Initializer

type Initializer struct {
	Entry          string
	StartCommand   string
	DisableBuiltin bool
	Namespace      string
	Modules        []*herbplugin.Module
}

func NewInitializer

func NewInitializer() *Initializer

func (*Initializer) LuaOptions

func (i *Initializer) LuaOptions() []lua.Options

func (*Initializer) MustApplyInitializer

func (i *Initializer) MustApplyInitializer(p *Plugin)

type LuaPluginLoader

type LuaPluginLoader interface {
	LoadLuaPlugin() *Plugin
}

type Plugin

type Plugin struct {
	sync.RWMutex

	LState *lua.LState
	herbplugin.Plugin
	DisableBuiltin bool

	Builtin map[string]lua.LGFunction
	// contains filtered or unexported fields
}

func MustCreatePlugin

func MustCreatePlugin(i *Initializer) *Plugin

func New

func New() *Plugin

func (*Plugin) LoadLuaPlugin

func (p *Plugin) LoadLuaPlugin() *Plugin

func (*Plugin) MustBootPlugin

func (p *Plugin) MustBootPlugin()

func (*Plugin) MustClosePlugin

func (p *Plugin) MustClosePlugin()

func (*Plugin) MustInitPlugin

func (p *Plugin) MustInitPlugin()

func (*Plugin) MustLoadPlugin

func (p *Plugin) MustLoadPlugin()

func (*Plugin) PluginType

func (p *Plugin) PluginType() string

Jump to

Keyboard shortcuts

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