-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathemmy_core.go
47 lines (38 loc) · 812 Bytes
/
emmy_core.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
47
package lua_debugger
import (
lua "github.com/yuin/gopher-lua"
"log"
)
func init() {
log.SetFlags(log.Ldate | log.Ltime | log.Lshortfile)
}
const (
KeyDebuggerFcd = "__Debugger_Fcd"
)
func TcpConnect(L *lua.LState) int {
host := L.CheckString(1)
port := L.CheckNumber(2)
fcd := newFacade()
fcdUd := L.NewUserData()
fcdUd.Value = fcd
L.SetField(L.Get(lua.RegistryIndex), KeyDebuggerFcd, fcdUd)
if err := fcd.TcpConnect(L, host, int(port)); err != nil {
L.Push(lua.LFalse)
L.Push(lua.LString(err.Error()))
return 2
}
L.Push(lua.LTrue)
return 1
}
var coreApi = map[string]lua.LGFunction{
"tcpConnect": TcpConnect,
}
func Loader(L *lua.LState) int {
t := L.NewTable()
L.SetFuncs(t, coreApi)
L.Push(t)
return 1
}
func Preload(L *lua.LState) {
L.PreloadModule("emmy_core", Loader)
}