2019-02-21 03:26:11 +03:00
|
|
|
package stdlib
|
|
|
|
|
|
|
|
import "github.com/d5/tengo/objects"
|
|
|
|
|
|
|
|
// Modules contain the standard modules.
|
2019-03-04 21:21:39 +03:00
|
|
|
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},
|
2019-02-21 03:26:11 +03:00
|
|
|
}
|
|
|
|
|
2019-03-01 05:41:29 +03:00
|
|
|
// 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 {
|
2019-03-04 21:21:39 +03:00
|
|
|
modules[name] = mod
|
2019-03-01 05:41:29 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return modules
|
|
|
|
}
|