-
Notifications
You must be signed in to change notification settings - Fork 78
Expand file tree
/
Copy pathlua-clientinfo.go
More file actions
42 lines (38 loc) · 945 Bytes
/
lua-clientinfo.go
File metadata and controls
42 lines (38 loc) · 945 Bytes
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
package rdns
import (
"fmt"
lua "github.com/yuin/gopher-lua"
)
const luaClientInfoMetatableName = "ClientInfo"
func (s *LuaScript) RegisterClientInfoType() {
L := s.L
mt := L.NewTypeMetatable(luaClientInfoMetatableName)
L.SetGlobal(luaClientInfoMetatableName, mt)
// methods and fields
L.SetField(mt, "__index", L.NewFunction(
func(L *lua.LState) int {
ci, ok := getUserDataArg[ClientInfo](L, 1)
if !ok {
return 0
}
fieldName := L.CheckString(2)
switch fieldName {
case "source_ip":
if ci.SourceIP != nil {
L.Push(lua.LString(ci.SourceIP.String()))
} else {
L.Push(lua.LNil)
}
case "doh_path":
L.Push(lua.LString(ci.DoHPath))
case "tls_server_name":
L.Push(lua.LString(ci.TLSServerName))
case "listener":
L.Push(lua.LString(ci.Listener))
default:
L.ArgError(2, fmt.Sprintf("clientinfo does not have field %q", fieldName))
return 0
}
return 1
}))
}