-
Notifications
You must be signed in to change notification settings - Fork 40
/
loader.go
40 lines (35 loc) · 940 Bytes
/
loader.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
package strings
import (
lua "github.com/yuin/gopher-lua"
)
// Preload adds strings to the given Lua state's package.preload table. After it
// has been preloaded, it can be loaded using require:
//
// local strings = require("strings")
func Preload(L *lua.LState) {
L.PreloadModule("strings", Loader)
}
// Loader is the module loader function.
func Loader(L *lua.LState) int {
readerMt := registerStringsReader(L)
builderMt := registerStringsBuilder(L)
t := L.NewTable()
t.RawSetString("Reader", readerMt)
t.RawSetString("Builder", builderMt)
L.SetFuncs(t, api)
L.Push(t)
return 1
}
var api = map[string]lua.LGFunction{
"split": Split,
"trim": Trim,
"trim_space": TrimSpace,
"trim_prefix": TrimPrefix,
"trim_suffix": TrimSuffix,
"has_prefix": HasPrefix,
"has_suffix": HasSuffix,
"contains": Contains,
"new_reader": newStringsReader,
"new_builder": newStringsBuilder,
"fields": Fields,
}