forked from d5/tengo
-
Notifications
You must be signed in to change notification settings - Fork 1
/
stdlib.go
37 lines (32 loc) · 1005 Bytes
/
stdlib.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 stdlib
import "github.com/d5/tengo/objects"
// Modules contain the standard modules.
var Modules = map[string]*objects.ImmutableMap{
"math": &objects.ImmutableMap{Value: mathModule},
"os": &objects.ImmutableMap{Value: osModule},
"text": &objects.ImmutableMap{Value: textModule},
"times": &objects.ImmutableMap{Value: timesModule},
"rand": &objects.ImmutableMap{Value: randModule},
}
// AllModuleNames returns a list of all default module names.
func AllModuleNames() []string {
var names []string
for name := range Modules {
names = append(names, name)
}
return names
}
// GetModules returns the modules for the given names.
// Duplicate names and invalid names are ignore.
func GetModules(names ...string) map[string]*objects.ImmutableMap {
modules := make(map[string]*objects.ImmutableMap)
for _, name := range names {
if mod := Modules[name]; mod != nil {
modules[name] = mod
}
}
return modules
}
func objectPtr(o objects.Object) *objects.Object {
return &o
}