-
Notifications
You must be signed in to change notification settings - Fork 10
/
lib.go
50 lines (47 loc) · 1.15 KB
/
lib.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
48
49
50
package lib
import (
"github.com/arnodel/golua/lib/base"
"github.com/arnodel/golua/lib/coroutine"
"github.com/arnodel/golua/lib/debuglib"
"github.com/arnodel/golua/lib/golib"
"github.com/arnodel/golua/lib/iolib"
"github.com/arnodel/golua/lib/mathlib"
"github.com/arnodel/golua/lib/oslib"
"github.com/arnodel/golua/lib/packagelib"
"github.com/arnodel/golua/lib/runtimelib"
"github.com/arnodel/golua/lib/stringlib"
"github.com/arnodel/golua/lib/tablelib"
"github.com/arnodel/golua/lib/utf8lib"
rt "github.com/arnodel/golua/runtime"
)
func LoadLibs(r *rt.Runtime, loaders ...packagelib.Loader) func() {
var cleanups []func()
for _, loader := range loaders {
cleanup := loader.Run(r)
if cleanup != nil {
cleanups = append(cleanups, cleanup)
}
}
return func() {
for i := len(cleanups) - 1; i >= 0; i-- {
cleanups[i]()
}
}
}
func LoadAll(r *rt.Runtime) func() {
return LoadLibs(
r,
base.LibLoader,
packagelib.LibLoader,
coroutine.LibLoader,
stringlib.LibLoader,
tablelib.LibLoader,
mathlib.LibLoader,
iolib.LibLoader,
utf8lib.LibLoader,
oslib.LibLoader,
debuglib.LibLoader,
golib.LibLoader,
runtimelib.LibLoader,
)
}