-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontrollerLib.go
63 lines (56 loc) · 1.02 KB
/
controllerLib.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
51
52
53
54
55
56
57
58
59
60
61
62
63
package LibraryController
import (
"github.com/Eclalang/Ecla/interpreter/eclaType"
)
// Lib is the interface of a lib.
type Lib interface {
Call(name string, args []eclaType.Type) ([]eclaType.Type, error)
}
var (
allLibs map[string]func() Lib
)
// InitLibs initializes the libs.
func init() {
allLibs = map[string]func() Lib{
"console": func() Lib {
return NewConsole()
},
"debugKingdom": func() Lib {
return NewDebugKingdom()
},
"encoding": func() Lib {
return NewEncoding()
},
"json": func() Lib {
return NewJson()
},
"os": func() Lib {
return NewOs()
},
"hash": func() Lib {
return NewHash()
},
"regex": func() Lib {
return NewRegex()
},
"math": func() Lib {
return NewMath()
},
"strings": func() Lib {
return NewStrings()
},
"cast": func() Lib {
return NewCast()
},
"time": func() Lib {
return NewTime()
},
}
}
// Import imports the lib with the given name.
func Import(name string) Lib {
if lib, ok := allLibs[name]; ok {
return lib()
}
return nil
}