Help us shape the future of Go! Take the 2026 Go Developer Survey

plugin

package
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: May 6, 2022 License: BSD-3-Clause Imports: 30 Imported by: 0

README

plugin GoDoc

Usage

local plugin = require("plugin")
local time = require("time")

local plugin_body = [[
    local time = require("time")
    local i = 1
    while true do
        print(i)
        i = i + 1
        time.sleep(1)
    end
]]

-- plugin.do_string(body)
-- also you can use: plugin.do_file(filename)
local print_plugin = plugin.do_string(plugin_body)
print_plugin:run()
time.sleep(2)
print_plugin:stop()
time.sleep(1)

local running = print_plugin:is_running()
if running then error("already running") end
-- also you can get last error: print_plugin:error()

-- plugin.do_string_with_payload()
-- also you can use: plugin.do_file_with_payload(filename)
local job_body = [[
    print(payload)
]]
local print_plugin_with_payload = plugin.do_string_with_payload(plugin_body, "text of payload")
print_plugin_with_payload:run()
-- must print: "text of payload"
time.sleep(1)
local running = print_plugin:is_running()
if running then error("already running") end

Documentation

Overview

Package plugin implements run lua-code from lua-code.

Example (Package)

plugin.do_string(), plugin_ud:run(), plugin_ud:stop()

state := lua.NewState()
Preload(state)
time.Preload(state)
source := `
    local plugin = require("plugin")
    local time = require("time")

    local plugin_body = [[
        local time = require("time")
        local i = 1
        while true do
            print(i)
            i = i + 1
            time.sleep(1.01)
        end
    ]]

    local print_plugin = plugin.do_string(plugin_body)
    print_plugin:run()
    time.sleep(2)
    print_plugin:stop()
    time.sleep(1)

    local running = print_plugin:is_running()
    if running then error("already running") end

`
if err := state.DoString(source); err != nil {
	log.Fatal(err.Error())
}
Output:
1
2

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func DoFile

func DoFile(L *lua.LState) int

DoFile lua plugin.do_file(filename) returns plugin_ud

func DoFileWithPayload

func DoFileWithPayload(L *lua.LState) int

DoFileWithPayload lua plugin.async() returns (plugin_ud, err)

func DoString

func DoString(L *lua.LState) int

DoString lua plugin.do_string(body) returns plugin_ud

func DoStringWithPayload

func DoStringWithPayload(L *lua.LState) int

DoStringWithPayload lua plugin.async() returns (plugin_ud, err)

func Error

func Error(L *lua.LState) int

Error lua plugin_ud:error() returns err

func IsRunning

func IsRunning(L *lua.LState) int

IsRunning lua plugin_ud:is_running()

func Loader

func Loader(L *lua.LState) int

Loader is the module loader function.

func NewPluginState

func NewPluginState() *lua.LState

NewPluginState return lua state

func Preload

func Preload(L *lua.LState)

Preload adds plugin to the given Lua state's package.preload table. After it has been preloaded, it can be loaded using require:

local plugin = require("plugin")

func Run

func Run(L *lua.LState) int

Run lua plugin_ud:run()

func Stop

func Stop(L *lua.LState) int

Stop lua plugin_ud:stop()

Types

This section is empty.

Jump to

Keyboard shortcuts

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