-
Notifications
You must be signed in to change notification settings - Fork 0
/
lua.go
37 lines (31 loc) · 1022 Bytes
/
lua.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
package strlib
import (
"github.com/vela-ssoc/vela-kit/lua"
"github.com/vela-ssoc/vela-kit/vela"
)
var xEnv vela.Environment
type StrLib struct{}
func (s *StrLib) String() string { return "lua.strlib.export" }
func (s *StrLib) Type() lua.LValueType { return lua.LTObject }
func (s *StrLib) AssertFloat64() (float64, bool) { return 0, false }
func (s *StrLib) AssertString() (string, bool) { return "", false }
func (s *StrLib) AssertFunction() (*lua.LFunction, bool) { return nil, false }
func (s *StrLib) Peek() lua.LValue { return s }
func (s *StrLib) Index(L *lua.LState, key string) lua.LValue {
switch key {
case "utf8":
return lua.NewFunction(utf8L)
case "similarity":
return lua.NewFunction(similarityL)
case "ac":
return lua.NewFunction(acL)
case "gen":
return lua.NewFunction(generalizationL)
default:
return lua.LNil
}
}
func WithEnv(env vela.Environment) {
xEnv = env
xEnv.Set("strlib", new(StrLib))
}