lang: funcs: core: Make module names public
This is needed for when we have nested modules.
This commit is contained in:
@@ -18,6 +18,6 @@
|
|||||||
package coredatetime
|
package coredatetime
|
||||||
|
|
||||||
const (
|
const (
|
||||||
// moduleName is the prefix given to all the functions in this module.
|
// ModuleName is the prefix given to all the functions in this module.
|
||||||
moduleName = "datetime"
|
ModuleName = "datetime"
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
facts.ModuleRegister(moduleName, "now", func() facts.Fact { return &DateTimeFact{} }) // must register the fact and name
|
facts.ModuleRegister(ModuleName, "now", func() facts.Fact { return &DateTimeFact{} }) // must register the fact and name
|
||||||
}
|
}
|
||||||
|
|
||||||
// DateTimeFact is a fact which returns the current date and time.
|
// DateTimeFact is a fact which returns the current date and time.
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ import (
|
|||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
// FIXME: consider renaming this to printf, and add in a format string?
|
// FIXME: consider renaming this to printf, and add in a format string?
|
||||||
simple.ModuleRegister(moduleName, "print", &types.FuncValue{
|
simple.ModuleRegister(ModuleName, "print", &types.FuncValue{
|
||||||
T: types.NewType("func(a int) str"),
|
T: types.NewType("func(a int) str"),
|
||||||
V: func(input []types.Value) (types.Value, error) {
|
V: func(input []types.Value) (types.Value, error) {
|
||||||
epochDelta := input[0].Int()
|
epochDelta := input[0].Int()
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
simple.ModuleRegister(moduleName, "weekday", &types.FuncValue{
|
simple.ModuleRegister(ModuleName, "weekday", &types.FuncValue{
|
||||||
T: types.NewType("func(a int) str"),
|
T: types.NewType("func(a int) str"),
|
||||||
V: Weekday,
|
V: Weekday,
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ import (
|
|||||||
const Answer = 42
|
const Answer = 42
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
simple.ModuleRegister(moduleName, "answer", &types.FuncValue{
|
simple.ModuleRegister(ModuleName, "answer", &types.FuncValue{
|
||||||
T: types.NewType("func() int"),
|
T: types.NewType("func() int"),
|
||||||
V: func([]types.Value) (types.Value, error) {
|
V: func([]types.Value) (types.Value, error) {
|
||||||
return &types.IntValue{V: Answer}, nil
|
return &types.IntValue{V: Answer}, nil
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
simple.ModuleRegister(moduleName, "errorbool", &types.FuncValue{
|
simple.ModuleRegister(ModuleName, "errorbool", &types.FuncValue{
|
||||||
T: types.NewType("func(a bool) str"),
|
T: types.NewType("func(a bool) str"),
|
||||||
V: func(input []types.Value) (types.Value, error) {
|
V: func(input []types.Value) (types.Value, error) {
|
||||||
if input[0].Bool() {
|
if input[0].Bool() {
|
||||||
|
|||||||
@@ -18,6 +18,6 @@
|
|||||||
package coreexample
|
package coreexample
|
||||||
|
|
||||||
const (
|
const (
|
||||||
// moduleName is the prefix given to all the functions in this module.
|
// ModuleName is the prefix given to all the functions in this module.
|
||||||
moduleName = "example"
|
ModuleName = "example"
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
facts.ModuleRegister(moduleName, "flipflop", func() facts.Fact { return &FlipFlopFact{} }) // must register the fact and name
|
facts.ModuleRegister(ModuleName, "flipflop", func() facts.Fact { return &FlipFlopFact{} }) // must register the fact and name
|
||||||
}
|
}
|
||||||
|
|
||||||
// FlipFlopFact is a fact which flips a bool repeatedly. This is an example fact
|
// FlipFlopFact is a fact which flips a bool repeatedly. This is an example fact
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
simple.ModuleRegister(moduleName, "int2str", &types.FuncValue{
|
simple.ModuleRegister(ModuleName, "int2str", &types.FuncValue{
|
||||||
T: types.NewType("func(a int) str"),
|
T: types.NewType("func(a int) str"),
|
||||||
V: func(input []types.Value) (types.Value, error) {
|
V: func(input []types.Value) (types.Value, error) {
|
||||||
return &types.StrValue{
|
return &types.StrValue{
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
simple.ModuleRegister(moduleName, "str2int", &types.FuncValue{
|
simple.ModuleRegister(ModuleName, "str2int", &types.FuncValue{
|
||||||
T: types.NewType("func(a str) int"),
|
T: types.NewType("func(a str) int"),
|
||||||
V: func(input []types.Value) (types.Value, error) {
|
V: func(input []types.Value) (types.Value, error) {
|
||||||
var i int64
|
var i int64
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
funcs.ModuleRegister(moduleName, "vumeter", func() interfaces.Func { return &VUMeterFunc{} }) // must register the func and name
|
funcs.ModuleRegister(ModuleName, "vumeter", func() interfaces.Func { return &VUMeterFunc{} }) // must register the func and name
|
||||||
}
|
}
|
||||||
|
|
||||||
// VUMeterFunc is a gimmic function to display a vu meter from the microphone.
|
// VUMeterFunc is a gimmic function to display a vu meter from the microphone.
|
||||||
|
|||||||
@@ -18,6 +18,6 @@
|
|||||||
package corefmt
|
package corefmt
|
||||||
|
|
||||||
const (
|
const (
|
||||||
// moduleName is the prefix given to all the functions in this module.
|
// ModuleName is the prefix given to all the functions in this module.
|
||||||
moduleName = "fmt"
|
ModuleName = "fmt"
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ import (
|
|||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
// FIXME: should this be named sprintf instead?
|
// FIXME: should this be named sprintf instead?
|
||||||
funcs.ModuleRegister(moduleName, "printf", func() interfaces.Func { return &PrintfFunc{} })
|
funcs.ModuleRegister(ModuleName, "printf", func() interfaces.Func { return &PrintfFunc{} })
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|||||||
@@ -18,6 +18,6 @@
|
|||||||
package coremath
|
package coremath
|
||||||
|
|
||||||
const (
|
const (
|
||||||
// moduleName is the prefix given to all the functions in this module.
|
// ModuleName is the prefix given to all the functions in this module.
|
||||||
moduleName = "math"
|
ModuleName = "math"
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
simplepoly.ModuleRegister(moduleName, "mod", []*types.FuncValue{
|
simplepoly.ModuleRegister(ModuleName, "mod", []*types.FuncValue{
|
||||||
{
|
{
|
||||||
T: types.NewType("func(int, int) int"),
|
T: types.NewType("func(int, int) int"),
|
||||||
V: Mod,
|
V: Mod,
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
simple.ModuleRegister(moduleName, "pow", &types.FuncValue{
|
simple.ModuleRegister(ModuleName, "pow", &types.FuncValue{
|
||||||
T: types.NewType("func(x float, y float) float"),
|
T: types.NewType("func(x float, y float) float"),
|
||||||
V: Pow,
|
V: Pow,
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
simple.ModuleRegister(moduleName, "sqrt", &types.FuncValue{
|
simple.ModuleRegister(ModuleName, "sqrt", &types.FuncValue{
|
||||||
T: types.NewType("func(x float) float"),
|
T: types.NewType("func(x float) float"),
|
||||||
V: Sqrt,
|
V: Sqrt,
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -26,15 +26,15 @@ import (
|
|||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
// TODO: Create a family method that will return a giant struct.
|
// TODO: Create a family method that will return a giant struct.
|
||||||
simple.ModuleRegister(moduleName, "is_debian", &types.FuncValue{
|
simple.ModuleRegister(ModuleName, "is_debian", &types.FuncValue{
|
||||||
T: types.NewType("func() bool"),
|
T: types.NewType("func() bool"),
|
||||||
V: IsDebian,
|
V: IsDebian,
|
||||||
})
|
})
|
||||||
simple.ModuleRegister(moduleName, "is_redhat", &types.FuncValue{
|
simple.ModuleRegister(ModuleName, "is_redhat", &types.FuncValue{
|
||||||
T: types.NewType("func() bool"),
|
T: types.NewType("func() bool"),
|
||||||
V: IsRedHat,
|
V: IsRedHat,
|
||||||
})
|
})
|
||||||
simple.ModuleRegister(moduleName, "is_archlinux", &types.FuncValue{
|
simple.ModuleRegister(ModuleName, "is_archlinux", &types.FuncValue{
|
||||||
T: types.NewType("func() bool"),
|
T: types.NewType("func() bool"),
|
||||||
V: IsArchLinux,
|
V: IsArchLinux,
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -18,6 +18,6 @@
|
|||||||
package coreos
|
package coreos
|
||||||
|
|
||||||
const (
|
const (
|
||||||
// moduleName is the prefix given to all the functions in this module.
|
// ModuleName is the prefix given to all the functions in this module.
|
||||||
moduleName = "os"
|
ModuleName = "os"
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
funcs.ModuleRegister(moduleName, "readfile", func() interfaces.Func { return &ReadFileFunc{} }) // must register the func and name
|
funcs.ModuleRegister(ModuleName, "readfile", func() interfaces.Func { return &ReadFileFunc{} }) // must register the func and name
|
||||||
}
|
}
|
||||||
|
|
||||||
// ReadFileFunc is a function that reads the full contents from a local file. If
|
// ReadFileFunc is a function that reads the full contents from a local file. If
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
simple.ModuleRegister(moduleName, "match", &types.FuncValue{
|
simple.ModuleRegister(ModuleName, "match", &types.FuncValue{
|
||||||
T: types.NewType("func(pattern str, s str) bool"),
|
T: types.NewType("func(pattern str, s str) bool"),
|
||||||
V: Match,
|
V: Match,
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -18,6 +18,6 @@
|
|||||||
package coreregexp
|
package coreregexp
|
||||||
|
|
||||||
const (
|
const (
|
||||||
// moduleName is the prefix given to all the functions in this module.
|
// ModuleName is the prefix given to all the functions in this module.
|
||||||
moduleName = "regexp"
|
ModuleName = "regexp"
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
simple.ModuleRegister(moduleName, "split", &types.FuncValue{
|
simple.ModuleRegister(ModuleName, "split", &types.FuncValue{
|
||||||
T: types.NewType("func(a str, b str) []str"),
|
T: types.NewType("func(a str, b str) []str"),
|
||||||
V: Split,
|
V: Split,
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -18,6 +18,6 @@
|
|||||||
package corestrings
|
package corestrings
|
||||||
|
|
||||||
const (
|
const (
|
||||||
// moduleName is the prefix given to all the functions in this module.
|
// ModuleName is the prefix given to all the functions in this module.
|
||||||
moduleName = "strings"
|
ModuleName = "strings"
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
simple.ModuleRegister(moduleName, "to_lower", &types.FuncValue{
|
simple.ModuleRegister(ModuleName, "to_lower", &types.FuncValue{
|
||||||
T: types.NewType("func(a str) str"),
|
T: types.NewType("func(a str) str"),
|
||||||
V: ToLower,
|
V: ToLower,
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
facts.ModuleRegister(moduleName, "cpu_count", func() facts.Fact { return &CPUCountFact{} }) // must register the fact and name
|
facts.ModuleRegister(ModuleName, "cpu_count", func() facts.Fact { return &CPUCountFact{} }) // must register the fact and name
|
||||||
}
|
}
|
||||||
|
|
||||||
// CPUCountFact is a fact that returns the current CPU count.
|
// CPUCountFact is a fact that returns the current CPU count.
|
||||||
|
|||||||
@@ -26,19 +26,19 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
simple.ModuleRegister(moduleName, "getenv", &types.FuncValue{
|
simple.ModuleRegister(ModuleName, "getenv", &types.FuncValue{
|
||||||
T: types.NewType("func(str) str"),
|
T: types.NewType("func(str) str"),
|
||||||
V: GetEnv,
|
V: GetEnv,
|
||||||
})
|
})
|
||||||
simple.ModuleRegister(moduleName, "defaultenv", &types.FuncValue{
|
simple.ModuleRegister(ModuleName, "defaultenv", &types.FuncValue{
|
||||||
T: types.NewType("func(str, str) str"),
|
T: types.NewType("func(str, str) str"),
|
||||||
V: DefaultEnv,
|
V: DefaultEnv,
|
||||||
})
|
})
|
||||||
simple.ModuleRegister(moduleName, "hasenv", &types.FuncValue{
|
simple.ModuleRegister(ModuleName, "hasenv", &types.FuncValue{
|
||||||
T: types.NewType("func(str) bool"),
|
T: types.NewType("func(str) bool"),
|
||||||
V: HasEnv,
|
V: HasEnv,
|
||||||
})
|
})
|
||||||
simple.ModuleRegister(moduleName, "env", &types.FuncValue{
|
simple.ModuleRegister(ModuleName, "env", &types.FuncValue{
|
||||||
T: types.NewType("func() map{str: str}"),
|
T: types.NewType("func() map{str: str}"),
|
||||||
V: Env,
|
V: Env,
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
facts.ModuleRegister(moduleName, "hostname", func() facts.Fact { return &HostnameFact{} }) // must register the fact and name
|
facts.ModuleRegister(ModuleName, "hostname", func() facts.Fact { return &HostnameFact{} }) // must register the fact and name
|
||||||
}
|
}
|
||||||
|
|
||||||
// HostnameFact is a function that returns the hostname.
|
// HostnameFact is a function that returns the hostname.
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
facts.ModuleRegister(moduleName, "load", func() facts.Fact { return &LoadFact{} }) // must register the fact and name
|
facts.ModuleRegister(ModuleName, "load", func() facts.Fact { return &LoadFact{} }) // must register the fact and name
|
||||||
}
|
}
|
||||||
|
|
||||||
// LoadFact is a fact which returns the current system load.
|
// LoadFact is a fact which returns the current system load.
|
||||||
|
|||||||
@@ -18,6 +18,6 @@
|
|||||||
package coresys
|
package coresys
|
||||||
|
|
||||||
const (
|
const (
|
||||||
// moduleName is the prefix given to all the functions in this module.
|
// ModuleName is the prefix given to all the functions in this module.
|
||||||
moduleName = "sys"
|
ModuleName = "sys"
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
facts.ModuleRegister(moduleName, "uptime", func() facts.Fact { return &UptimeFact{} })
|
facts.ModuleRegister(ModuleName, "uptime", func() facts.Fact { return &UptimeFact{} })
|
||||||
}
|
}
|
||||||
|
|
||||||
// UptimeFact is a fact which returns the current uptime of your system.
|
// UptimeFact is a fact which returns the current uptime of your system.
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
funcs.ModuleRegister(moduleName, "exchange", func() interfaces.Func { return &ExchangeFunc{} })
|
funcs.ModuleRegister(ModuleName, "exchange", func() interfaces.Func { return &ExchangeFunc{} })
|
||||||
}
|
}
|
||||||
|
|
||||||
// ExchangeFunc is special function which returns all the values of a given key
|
// ExchangeFunc is special function which returns all the values of a given key
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
funcs.ModuleRegister(moduleName, "kvlookup", func() interfaces.Func { return &KVLookupFunc{} })
|
funcs.ModuleRegister(ModuleName, "kvlookup", func() interfaces.Func { return &KVLookupFunc{} })
|
||||||
}
|
}
|
||||||
|
|
||||||
// KVLookupFunc is special function which returns all the values of a given key
|
// KVLookupFunc is special function which returns all the values of a given key
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
funcs.ModuleRegister(moduleName, "schedule", func() interfaces.Func { return &SchedulePolyFunc{} })
|
funcs.ModuleRegister(ModuleName, "schedule", func() interfaces.Func { return &SchedulePolyFunc{} })
|
||||||
}
|
}
|
||||||
|
|
||||||
// SchedulePolyFunc is special function which determines where code should run
|
// SchedulePolyFunc is special function which determines where code should run
|
||||||
|
|||||||
@@ -18,6 +18,6 @@
|
|||||||
package coreworld
|
package coreworld
|
||||||
|
|
||||||
const (
|
const (
|
||||||
// moduleName is the prefix given to all the functions in this module.
|
// ModuleName is the prefix given to all the functions in this module.
|
||||||
moduleName = "world"
|
ModuleName = "world"
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user