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() defer state.Close() Preload(state) time.Preload(state) source := ` local plugin = require("plugin") local time = require("time") local plugin_body = [[ local doCh, doneCh = unpack(arg) local i = 1 while doCh:receive() do print(i) doneCh:send(i) i = i + 1 end ]] -- Make synchronization channels and fire up the plugin local doCh = channel.make(100) local doneCh = channel.make(100) local print_plugin = plugin.do_string(plugin_body, doCh, doneCh) print_plugin:run() -- Allow two iterations to proceed doCh:send(nil) local ok, got = doneCh:receive() assert(ok and got == 1, string.format("ok = %s; got = %s", ok, got)) doCh:send(nil) ok, got = doneCh:receive() assert(ok and got == 2, string.format("ok = %s; got = %s", ok, got)) -- Close the doCh and wait to ensure it's closed gracefully but stop just to be sure doCh:close() time.sleep(1) print_plugin:stop() time.sleep(1) -- Ensure it's not still running assert(not print_plugin:is_running(), "still running") ` if err := state.DoString(source); err != nil { log.Fatal(err.Error()) }
Output: 1 2
Example (Using_like_goroutine) ¶
state := lua.NewState() defer state.Close() Preload(state) source := ` local plugin = require 'plugin' function myfunc(...) print(table.concat({...}, "")) end local background_body = [[ return pcall(unpack(arg)) ]] local background_plugin = plugin.do_string(background_body, myfunc, "Hello", " ", "World") background_plugin:run() local err = background_plugin:wait() assert(not err, err) ` if err := state.DoString(source); err != nil { log.Fatal(err) }
Output: Hello World
Index ¶
- func DoFile(L *lua.LState) int
- func DoFileWithPayload(L *lua.LState) int
- func DoString(L *lua.LState) int
- func DoStringWithPayload(L *lua.LState) int
- func DoneChannel(L *lua.LState) int
- func Error(L *lua.LState) int
- func IsRunning(L *lua.LState) int
- func Loader(L *lua.LState) int
- func NewLuaPlugin(L *lua.LState, n int) *luaPlugin
- func NewPluginState() *lua.LState
- func Preload(L *lua.LState)
- func PreloadAll(L *lua.LState)
- func Run(L *lua.LState) (nRet int)
- func Stop(L *lua.LState) int
- func Wait(L *lua.LState) int
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DoFileWithPayload ¶
DoFileWithPayload lua plugin.async() returns (plugin_ud, err)
func DoStringWithPayload ¶
DoStringWithPayload lua plugin.async() returns (plugin_ud, err)
func DoneChannel ¶ added in v0.3.0
DoneChannel lua plugin_ud:done_chan()
func NewLuaPlugin ¶ added in v0.3.0
func Preload ¶
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 PreloadAll ¶ added in v0.3.0
PreloadAll preload all gopher lua packages - note it's needed here to prevent circular deps between plugin and libs
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.