forked from vadv/gopher-lua-libs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
example_test.go
46 lines (38 loc) · 883 Bytes
/
example_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package plugin
import (
"log"
time "github.com/alexjx/gopher-lua-libs/time"
lua "github.com/yuin/gopher-lua"
)
// plugin.do_string(), plugin_ud:run(), plugin_ud:stop()
func Example_package() {
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
}