stdlib.go 778 B

12345678910111213141516171819202122232425262728293031323334
  1. package stdlib
  2. //go:generate go run gensrcmods.go
  3. import (
  4. "github.com/d5/tengo/v2"
  5. )
  6. // AllModuleNames returns a list of all default module names.
  7. func AllModuleNames() []string {
  8. var names []string
  9. for name := range BuiltinModules {
  10. names = append(names, name)
  11. }
  12. for name := range SourceModules {
  13. names = append(names, name)
  14. }
  15. return names
  16. }
  17. // GetModuleMap returns the module map that includes all modules
  18. // for the given module names.
  19. func GetModuleMap(names ...string) *tengo.ModuleMap {
  20. modules := tengo.NewModuleMap()
  21. for _, name := range names {
  22. if mod := BuiltinModules[name]; mod != nil {
  23. modules.AddBuiltinModule(name, mod)
  24. }
  25. if mod := SourceModules[name]; mod != "" {
  26. modules.AddSourceModule(name, []byte(mod))
  27. }
  28. }
  29. return modules
  30. }