functions

package
v0.1.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 21, 2023 License: MIT Imports: 35 Imported by: 0

README

functions

The functions package contains the builtin functions (some of which are global and some of which are arranged into packages). The following provides a short summary of each of the built-in functions, broken into categories based on the general data types or functionality used.

Type Casting Functions

These functions are used to explicity specify the type of a value to be used in the evaluation of the expression. They take an arbitrary value and return that value coerced to a function-specific type.

int(any)

Return the argument coerced to an int data type. For a boolean, this will result in 0 or 1. For a float64, it returns the integer component. A string must contain a valid representation of an integer to convert without error.

int(33.5)

This returns the value 33.

bool(any)

Return the argument coerced to a bool data type. For numeric values, this means zero for false, or non-zero for true. For a string, it must contain the strings defs.True or defs.False to be converted without error.

bool(defs.True)

This returns the value true.

float64(any)

Return the argument coerced to an float64 data type. For a boolean, this will result in 0.0 or 1.0 values. For an, it returns the floating point equivalent of the integer value. A string must contain a valid representation of an floating point value to convert without error.

float64("3.1415")

Thsi returns the float64 value 3.1415.

String Functions

These functions act on string values, and usually return a string values as the result.

strings.Format(fmtstring, values...)

This returns a string containing the formatted value of the values array, using the Go-style fmtstring value. This supports any Go-style formatting.

strings.Left(string, count)

This returns count characters from the left side of the string.

strings.Left("abraham", 3)

This returns the value "abr".

strings.Right(string, count)

This returns count characters from the right side of the string.

strings.Right("abraham", 4)

This returns the value "aham".

strings.Substring(string, start, count)

This extracts a substring from the string argument. The substring starts at the start character position, and includes count characters in the result.

j := strings.Substring("Thomas Jefferson", 8, 4)

This returns the string "Jeff".

strings.Index(string, substring)

This searches the string parameter for the first instance of the substring parameter. If it is found, the function returns the character position where it starts. If it was not found, it returns an integer zero.

strings.Index("Scores of fun", "ore")

This returns the value 3, indicating that the string "ore" starts at the third character of the string.

strings.Lower(string)

This converts the string value given to lower-case letters. If the value is not a string, it is first coerced to a string type.

strings.Lower("Tom")

This results in the string value "tom".

strings.Upper(string)

This converts the string value given to uooer-case letters. If the value is not a string, it is first coerced to a string type.

strings.Upper("Jeffrey")

This results in the string value "JEFFREY".

strings.Tokenize(string)

This converts a string into an array of strings, tokenized using the same syntax rules that the Ego language uses itself. An empty string results in an empty token array.

General Functions

These functions work generally with any type of value, and perform coercsions as needed. The first value in the argument list determines the type that all the remaining items will be coerced to.

append(array, items...)

You can use the append function to add items to an array. The first argument is the source array to which data is to be appended. If the first argument is not an array, a new array is constructed containing that value.

The subsequent arguments are added to the array, and the resulting array is returned as the new value. If you add in an array, the array becomes a single new member of the resulting array. You can use the ... operator after the array name to cause it to be flattened out to be individual arguments, as if you has passed in each array member independantly.

delete(v, k)

The delete function is used to efficiently remove an element from an array, or remove a field from a structure. The second argument is either the zero-based array index to delete, or a string value that describes the name of the field to be removed from the structure.

a := [101, 102, 103, 104]
b := delete(a, 2)           \\ Result is [101, 102, 104]

a := { name: "Tom", age:55 }
a = delete(a, "age")         \\ Result is { name: "Tom" }

You cannot use the delete function with anything other than a struct or array item.

len(string)

Return the length of the argument. The meaning of length depends on the type of the argument. For a string, this returns the number of characters in the string. For an int, float64, or bool value, it returns the number of characters when the value is formatted for output.

Some examples:

Example Result
len("fortitude") 9, the number of characters in the string.
len(135) 3, the number of characters when 135 is converted to string "135"
len(false) 5, the number of characters in defs.False
len(3.1415) 6, the number of characters in "3.1415"
len([5,3,1]) 3, the number of elements in the array
len({a:1, b:true}) 2, the number of fields in the array
min(v1, v2...)

This gets the minimum (smallest numeric or alphabetic) value from the list. If the first item is a string, then all values are converted to a string for comparison and the result will be the lexigraphically first element. IF the values are int or float64 values, then a numeric comparison is done and the result is the numerically smallest value.

min(33.5, 22.76, 9, 55)

This returns the float64 value 9.0

max(v1, v2...)

This gets the maximum (largest numeric or alphabetic) value from the list. If the first item is a string, then all values are converted to a string for comparison and the result will be the lexigraphically lsat element. IF the values are int or float64 values, then a numeric comparison is done and the result is the numerically largest value.

max("shoe", "mouse", "cake", "whistle")

This returns the string value "whistle".

sum(v1, v2...)

This function returns the sum of the arguments. The meaning of sum depends on the arguments. The values must not be arrays or structures.

For a numeric value (int or float64), the function returns the mathematical sum of all the numeric values.

x := sum(3.5, 15, .5)

This results in x having the value 19. For a boolean value, this is the same as a boolean "and" operation being performed on all values.

For a string, it concatenates all the string values together into a single long string.

IO Functions

These functions handle general input and output to files.

io.Readdir(path)

This reads the contents of a directory, specified as a string path. The result is an array of structures, one structure for each file. The information in the structure contains the name, mode, size, modification date, and a flag indicating if this entry is a directory or not.

io.Readfile(name)

This reads the entire contents of the named file as a single large string, and returns that string as the function result.

io.Writefile(name, text)

This writes the string text to the output file, which is created if it does not already exist. The text becomes the contents of the file; any previous contents are lost.

strings.Split(text [, delimiter])

This will split a single string (typically read using the io.Readfile() function) into an array of strings on line boundaries.

buffer := io.Readfile("test.txt")
lines := strings.Split(buffer)

The result of this is that lines is an array of strings, each of which represents a line of text. If you wish to split the data using a different delimiter string than a newline, specify it as the optional second parameter:

urlParts := strings.Split("/services/debug/windows", "/")

results in urlParts being an array of three string values, containing ["service", "debug", "windows"] as its value.

io.Open(name [, createFlag ])

This opens a new file of the given name. If the optional second parameter is given it specifies the mode "create", "append", or "read". This determines if the file is created/overwritten versus appended to for writes, or only used for reads. The result is a file handle and an error value. If the error is nil, the file handle can be used for additional operations documented below.

 f := io.Open("file.txt", "create")

This creates a new file named "file.txt" in the current directory, and returns the identifier for the file as the variable f. The variable f is a readonly struct, which also contains a field name that contains the fully-qualified file name of the file that was opened.

f.ReadString()

This reads the next line of text from the input file and returns it as a string value. The file identifier f must have previously been returned by an io.Open() function call.

f.WriteString(text)

This writes a line of text to the output file f. The line of text is always followed by a newline character.

f.Close()

This closes the file, and releases the resources for the file. After the Close() call, the identifier cannot be used in a file function until it is reset using a call to io.Open().

Utility Functions

These are miscellaneous funcctions to support writing programs in Ego.

sort(v...)

This sorts list of values into ascending order. The elements can be scalar values or an array; they are all concatenated into a single array for the purposes of sorting the data. The type of the first element in the array determines the type used to sort all the data; the second and following array elements are cast to the same type as the first element for the purposes of sorting the data.

It is an error to call this function with an array that contains elements that are arrays or structures.

util.UUID()

This generates a UUID (universal unique identifier) and returns it formatted as a string value. Every call to this function will result in a new unique value.

members(st)

Returns an array of strings containing the names of each member of the structure passed as an argument. If the value passed is not a structure it causes an error. Note that the resulting array elements can be used to reference fields in a structure using array index notation.

e := { name: "Dave", age: 33 }
m := utils.members(e)

e[m[1]] := 55

The util.members() function returns an array [ "age", "name" ]. These are the fields of the structure, and they are always returned in alphabetical order. The assignment statement uses the first array element ("age") to access the value of e.age.

util.Symbols()

Returns a string containing a formatted expression of the symbol table at the moment the function is called, including all nested levels of scope. The typical use is to simply print the string:

x := 55
{
    x = 42
    y := "test"
    fmt.Println( util.symbols() )
}

This will print the symbols for the nested basic block as well as the symbols for the main program.

Formatted Output

You can print values to the console (or stdout device) by using calls into the functions of the fmt package.

fmt.Print(...)

The Print function prints any values passed as parameters to the standard output, using the default formatting operations for Ego values. There is no trailing newline after the output, so multiple Print() calls will produce output on a single line of text.

fmt.Println(...)

The Println function prints any values passed as parameters to the standard output, using the default formatting operations. After any values are printed, a newline is printed. This can also be used with no parameters to produce a newline character after a series of Print calls.

fmt.Printf(format, ...)

The Printf function formats output and prints it. You must specify at least one parameter which is a string containing the format specification to print. This can include substitution operators for values in thie string, which correspond to the additional parameters passed after the format string.

This uses the Go format processor, so it can support the exact same format specifications as Go.

fmt.Sprintf(format, ...)

The Sprintf function formats output and returns it as a string value. You must specify at least one parameter which is a string containing the format specification to output. This can include substitution operators for values in thie string, which correspond to the additional parameters passed after the format string.

This uses the Go format processor, so it can support the exact same format specifications as Go.

JSON Support

You can formalize the parsing of JSON strings into Ego variables using the json package. This converts a string containing a JSON represetnation into an Ego object, or converts an Ego object into the corresponding JSON string.

json.Marshal()

Returns a string containing the JSON representation of the arguments. If only one argument is given, the result is the JSON for that specific argument. If more than one argument is given, the result is always encoded as a JSON array where each element matches a parameter to the call.

json.MarshalIndent(v, prefix, indent)

Returns a string containing the JSON representation of the v arguement. The caller must also specify a string for the prefix that appears at the start of each line of the formatted JSON output, and a indent value that is the string used to indent nested JSON objects.

json.UnMarhsal()

This accepts a string that must contain a syntactically valid JSON expression, which is then converted to the matching Ego data types. Supported types are int, float64, bool, string, array, and struct elements.

Profile

This collection allows an Ego program to interact with the persistent settings profile data.

profile.Keys()

This returns an array of strings, each of which is a key value in the active profile. Each of these values can be used in a profile.get() call to read a value.

keys := profile.Keys()
for i := range keys {
    fmt.Printf("profile key is %s\n", i)
}
profile.Get()

Use this to read a single key value from the profile. The only parameter is the name of the profile key.

 password := profile.Get("secret-password")

If the key is not valid, then an empty string is returned as the value.

profile.Set()

Use this to store a value in the profile. The first parameter is the name of the profile key, and the second parameter is coerced to be a string value that is stored in the profile. If the key does not already exist, it is created.

profile.Set("secret-password", "gronzeldabelle")

Note this can only be invoked as a call statement; it does not return a value.

profile.Delete()

This will delete a key from the current profile. If you try to delete a key that does not exist, there is no action taken.

profile.Delete("secret-password")

This must be invoked as a call statement; there is no function result value. This delete operation cannot be undone; the key value is immediately removed from the profile and the profile is rewritten to disk.

Strings

This collection of functions support string operations.

strings.String(v...)

The function accepts one or more arguments, which are processed and concatenated into a single string value.

Type Example Description
int 65 Character with matching unicode value
string "test" String value
[]string ["a", "b", "c"] Array of string values
[]int ] [ 65, 66, 67 ] Array of runes expressed as integer unicode value
strings.Ints(string)

Given a string value, returns an array containing all the runes of the string expressed as integers containing the unicode values. If this array was passed to strings.string() it would return the original string.

strings.Chars(string)

Given a string value, return an array containing all the characters of the string as individual string array elements. So "test" becomes ["t", "e", "s", "t"]

time

The time package supports basic time calculations.

time.Now()

This returns the current time as a formatted string. Time values are generally always expressed as strings.

time.Add(t, d)

Adds a given duration ("1s", "-5h3m", etc) to the time and return a new time string.

time.Subtract(t1, t2)

Subtract t2 from t1 and return the duration ("-5s", etc). The sign will be "-" if t2 is greater than t1.

Documentation

Index

Constants

View Source
const Any = math.MaxInt32

Any is a constant that defines that a function can have as many arguments as desired.

View Source
const MaxDeepCopyDepth = 100

For a new() on an object, we won't recursively copy objects nested more deeply than this. Setting this too small will prevent complex structures from copying correctly. Too large, and memory could be swallowed whole.

Variables

View Source
var FunctionDictionary = map[string]FunctionDefinition{}/* 127 elements not displayed */

FunctionDictionary is the dictionary of functions. As functions are determined to allow the return of both a value and an error as multi-part results, add the ErrReturn:true flag to each function definition.

View Source
var NativeFunctionMap = []NativeFunctionDef{
	{
		Kind: data.WaitGroupType,
		Name: "Wait",
		F:    waitGroupWait,
	},
	{
		Kind: data.WaitGroupType,
		Name: "Add",
		F:    waitGroupAdd,
	},
	{
		Kind: data.WaitGroupType,
		Name: "Done",
		F:    waitGroupDone,
	},
	{
		Kind: data.PointerType(data.WaitGroupType),
		Name: "Wait",
		F:    waitGroupWait,
	},
	{
		Kind: data.PointerType(data.WaitGroupType),
		Name: "Add",
		F:    waitGroupAdd,
	},
	{
		Kind: data.PointerType(data.WaitGroupType),
		Name: "Done",
		F:    waitGroupDone,
	},
	{
		Kind: data.MutexType,
		Name: "Lock",
		F:    mutexLock,
	},
	{
		Kind: data.MutexType,
		Name: "Unlock",
		F:    mutexUnlock,
	},
	{
		Kind: data.PointerType(data.MutexType),
		Name: "Lock",
		F:    mutexLock,
	},
	{
		Kind: data.PointerType(data.MutexType),
		Name: "Unlock",
		F:    mutexUnlock,
	},
}

NativeFunctionMap defines, for each combination of data type and function name, specify the native function handler for that type. For example, a sync.WaitGroup has Add(), Done(), and Wait() methods and are all shown here. This table is used by the Member opcode to check to see if the member index is into a natively implemented type...

Functions

func Abs

func Abs(symbols *symbols.SymbolTable, args []interface{}) (interface{}, error)

Abs implements the abs() function.

func AddBuiltins

func AddBuiltins(symbolTable *symbols.SymbolTable)

AddBuiltins adds or overrides the default function library in the symbol map. Function names are distinct in the map because they always have the "()" suffix for the key.

func AddFunction

func AddFunction(s *symbols.SymbolTable, fd FunctionDefinition) error

func Append

func Append(s *symbols.SymbolTable, args []interface{}) (interface{}, error)

Append implements the builtin append() function, which concatenates all the items together as an array. The first argument is flattened into the result, and then each additional argument is added to the array as-is.

func AsString

func AsString(s *symbols.SymbolTable, args []interface{}) (interface{}, error)

func BlockFonts

func BlockFonts(s *symbols.SymbolTable, args []interface{}) (interface{}, error)

func BlockPrint

func BlockPrint(s *symbols.SymbolTable, args []interface{}) (interface{}, error)

func CallBuiltin

func CallBuiltin(s *symbols.SymbolTable, name string, args ...interface{}) (interface{}, error)

func Chars

func Chars(s *symbols.SymbolTable, args []interface{}) (interface{}, error)

Chars implements the strings.chars() function. This accepts a string value and converts it to an array of characters.

func Chdir

func Chdir(s *symbols.SymbolTable, args []interface{}) (interface{}, error)

Chdir implements the os.Chdir() function.

func Chmod

func Chmod(s *symbols.SymbolTable, args []interface{}) (interface{}, error)

Chmod implements the os.Chmod() function.

func Chown

func Chown(s *symbols.SymbolTable, args []interface{}) (interface{}, error)

Chown implements the os.Chown() function.

func CipherRandom

func CipherRandom(s *symbols.SymbolTable, args []interface{}) (interface{}, error)

Random implements the cipher.Random() function which generates a random token string value using the cryptographic random number generator.

func Clearenv

func Clearenv(s *symbols.SymbolTable, args []interface{}) (interface{}, error)

Clearenv implements the os.Clearenv() function.

func Close

func Close(s *symbols.SymbolTable, args []interface{}) (interface{}, error)

Close closes a file.

func CloseAny

func CloseAny(s *symbols.SymbolTable, args []interface{}) (interface{}, error)

This is the generic close() which can be used to close a channel or a file, and maybe later other items as well.

func Compare

func Compare(s *symbols.SymbolTable, args []interface{}) (interface{}, error)

Wrapper around strings.Compare().

func Contains

func Contains(s *symbols.SymbolTable, args []interface{}) (interface{}, error)

Wrapper around strings.Contains().

func ContainsAny

func ContainsAny(s *symbols.SymbolTable, args []interface{}) (interface{}, error)

Wrapper around strings.Contains().

func Count

func Count(s *symbols.SymbolTable, args []interface{}) (interface{}, error)

Wrapper around strings.Count().

func CreateToken

func CreateToken(s *symbols.SymbolTable, args []interface{}) (interface{}, error)

CreateToken creates a new token with a username and a data payload.

func DecodeBase64

func DecodeBase64(s *symbols.SymbolTable, args []interface{}) (interface{}, error)

DecodeBase64 encodes a string as a BASE64 string using standard encoding rules.

func Decrypt

func Decrypt(s *symbols.SymbolTable, args []interface{}) (interface{}, error)

Decrypt implements the cipher.Decrypt() function. It accepts an encrypted string and a key, and attempts to decode the string. If the string is not a valid encryption using the given key, an empty string is returned. It is an error if the string does not contain a valid hexadecimal character string.

func DeepCopy

func DeepCopy(source interface{}, depth int) interface{}

DeepCopy makes a deep copy of an Ego data type. It should be called with the maximum nesting depth permitted (i.e. array index->array->array...). Because it calls itself recursively, this is used to determine when to give up and stop traversing nested data. The default is MaxDeepCopyDepth.

func Delete

func Delete(s *symbols.SymbolTable, args []interface{}) (interface{}, error)

Delete can be used three ways. To delete a member from a structure, to delete an element from an array by index number, or to delete a symbol entirely. The first form requires a string name, the second form requires an integer index, and the third form does not have a second parameter.

func DeleteFile

func DeleteFile(s *symbols.SymbolTable, args []interface{}) (interface{}, error)

DeleteFile deletes a file.

func EncodeBase64

func EncodeBase64(s *symbols.SymbolTable, args []interface{}) (interface{}, error)

EncodeBase64 encodes a string as a BASE64 string using standard encoding rules.

func Encrypt

func Encrypt(s *symbols.SymbolTable, args []interface{}) (interface{}, error)

Encrypt implements the cipher.Encrypt() function. This takes a string value and a string key, and encrypts the string using the key.

func Environ

func Environ(s *symbols.SymbolTable, args []interface{}) (interface{}, error)

Environ implements the os.Environ() function.

func EqualFold

func EqualFold(s *symbols.SymbolTable, args []interface{}) (interface{}, error)

Wrapper around strings.EqualFold().

func Exec

func Exec(s *symbols.SymbolTable, args []interface{}) (result interface{}, err error)

Exec implements the util.Exec() function. This should be replaced with a proper emulation of the Go command object type in the future.

func Executable

func Executable(s *symbols.SymbolTable, args []interface{}) (interface{}, error)

Executable implements the os.Executable() function.

func Exit

func Exit(symbols *symbols.SymbolTable, args []interface{}) (interface{}, error)

Exit implements the os.exit() function.

func Expand

func Expand(s *symbols.SymbolTable, args []interface{}) (interface{}, error)

Expand expands a list of file or path names into a list of files.

func ExpandPath

func ExpandPath(path, ext string) ([]string, error)

ExpandPath is used to expand a path into a list of file names. This is also used elsewhere to product path lists, so it must be an exported symbol.

func Extract

func Extract(s *symbols.SymbolTable, args []interface{}) (interface{}, error)

Extract extracts the data from a token and returns it as a struct.

func Fields

func Fields(s *symbols.SymbolTable, args []interface{}) (interface{}, error)

Wrapper around strings.Fields().

func FindName

func FindName(f func(*symbols.SymbolTable, []interface{}) (interface{}, error)) string

FindName returns the name of a function from the dictionary if one is found.

func Format

func Format(s *symbols.SymbolTable, args []interface{}) (interface{}, error)

Format implements the strings.format() function.

func FormatAsString

func FormatAsString(s *symbols.SymbolTable, v interface{}) string

FormatAsString will attempt to use the String() function of the object type passed in, if it is a typed struct. Otherwise, it just returns the Unquoted format value.

func GetArgs

func GetArgs(s *symbols.SymbolTable, args []interface{}) (interface{}, error)

GetArgs implements util.Args() which fetches command-line arguments from the Ego command invocation, if any.

func GetEnv

func GetEnv(symbols *symbols.SymbolTable, args []interface{}) (interface{}, error)

GetEnv implements the util.getenv() function which reads an environment variable from the os.

func GetMode

func GetMode(symbols *symbols.SymbolTable, args []interface{}) (interface{}, error)

GetMode implements the util.Mode() function which reports the runtime mode.

func GetName

func GetName(f NativeFunction) string

func Hash

func Hash(s *symbols.SymbolTable, args []interface{}) (interface{}, error)

Hash implements the cipher.hash() function. For an arbitrary string value, it computes a crypotraphic hash of the value, and returns it as a 32-character string containing the hexadecimal hash value. Hashes are irreversible.

func Hostname

func Hostname(symbols *symbols.SymbolTable, args []interface{}) (interface{}, error)

func I18nLanguage

func I18nLanguage(s *symbols.SymbolTable, args []interface{}) (interface{}, error)

func I18nT

func I18nT(s *symbols.SymbolTable, args []interface{}) (interface{}, error)

func Index

func Index(symbols *symbols.SymbolTable, args []interface{}) (interface{}, error)

Index implements the index() function.

func InternalCast

func InternalCast(s *symbols.SymbolTable, args []interface{}) (interface{}, error)

Compiler-generate casting; generally always array types. This is used to convert numeric arrays to a different kind of array, to convert a string to an array of integer (rune) values, etc.

func Ints

func Ints(s *symbols.SymbolTable, args []interface{}) (interface{}, error)

Ints implements the strings.ints() function. This accepts a string value and converts it to an array of integer rune values.

func JSONMarshal

func JSONMarshal(s *symbols.SymbolTable, args []interface{}) (interface{}, error)

JSONMarshal writes a JSON string from arbitrary data.

func JSONMarshalIndent

func JSONMarshalIndent(s *symbols.SymbolTable, args []interface{}) (interface{}, error)

JSONMarshalIndent writes a JSON string from arbitrary data.

func JSONUnmarshal

func JSONUnmarshal(s *symbols.SymbolTable, args []interface{}) (interface{}, error)

JSONUnmarshal reads a string as JSON data.

func Join

func Join(s *symbols.SymbolTable, args []interface{}) (interface{}, error)

Wrapper around strings.Join().

func Left

func Left(symbols *symbols.SymbolTable, args []interface{}) (interface{}, error)

Left implements the left() function.

func Length

func Length(symbols *symbols.SymbolTable, args []interface{}) (interface{}, error)

Length implements the len() function.

func Log

func Log(symbols *symbols.SymbolTable, args []interface{}) (interface{}, error)

Log is the log() function.

func LogTail

func LogTail(s *symbols.SymbolTable, args []interface{}) (interface{}, error)

LogTail implements the util.Log(n) function, which returns the last 'n' lines from the current.

func Lower

func Lower(symbols *symbols.SymbolTable, args []interface{}) (interface{}, error)

Lower implements the lower() function.

func Make

func Make(s *symbols.SymbolTable, args []interface{}) (interface{}, error)

Make implements the make() function. The first argument must be a model of the array type (using the Go native version), and the second argument is the size.

func MakeTime

func MakeTime(t *time.Time) interface{}

Make a time object with the given time value.

func Max

func Max(symbols *symbols.SymbolTable, args []interface{}) (interface{}, error)

Max implements the max() function.

func MemStats

func MemStats(s *symbols.SymbolTable, args []interface{}) (interface{}, error)

func Members

func Members(symbols *symbols.SymbolTable, args []interface{}) (interface{}, error)

Members gets an array of the names of the fields in a structure.

func Min

func Min(symbols *symbols.SymbolTable, args []interface{}) (interface{}, error)

Min implements the min() function.

func New

func New(s *symbols.SymbolTable, args []interface{}) (interface{}, error)

New implements the new() function. If an integer type number or a string type name is given, the "zero value" for that type is returned. For an array, struct, or map, a recursive copy is done of the members to a new object which is returned.

func Normalize

func Normalize(s *symbols.SymbolTable, args []interface{}) (interface{}, error)

Normalize coerces a value to match the type of a model value.

func OpenFile

func OpenFile(s *symbols.SymbolTable, args []interface{}) (interface{}, error)

OpenFile opens a file.

func Packages

func Packages(s *symbols.SymbolTable, args []interface{}) (interface{}, error)

func ParseURLPattern

func ParseURLPattern(url, pattern string) (map[string]interface{}, bool)

ParseURLPattern accepts a pattern that tells what part of the URL is meant to be literal, and what is a user-supplied item. The result is a map of the URL items parsed.

If the pattern is

"/services/debug/processes/{{ID}}"

and the url is

/services/debug/processses/1653

Then the result map will be

map[string]interface{} {
         "ID" : 1653
}

func PathAbs

func PathAbs(s *symbols.SymbolTable, args []interface{}) (interface{}, error)

func PathBase

func PathBase(s *symbols.SymbolTable, args []interface{}) (interface{}, error)

func PathClean

func PathClean(s *symbols.SymbolTable, args []interface{}) (interface{}, error)

func PathDir

func PathDir(s *symbols.SymbolTable, args []interface{}) (interface{}, error)

func PathExt

func PathExt(s *symbols.SymbolTable, args []interface{}) (interface{}, error)

func PathJoin

func PathJoin(s *symbols.SymbolTable, args []interface{}) (interface{}, error)

Given a list of path components, connect them together in the syntax supported by the host platform as a file system path. Resolve duplicate separators.

func Print

func Print(s *symbols.SymbolTable, args []interface{}) (interface{}, error)

Print implements fmt.Print() and is a wrapper around the native Go function.

func Printf

func Printf(s *symbols.SymbolTable, args []interface{}) (interface{}, error)

Printf implements fmt.printf() and is a wrapper around the native Go function.

func Println

func Println(s *symbols.SymbolTable, args []interface{}) (interface{}, error)

Println implements fmt.Println() and is a wrapper around the native Go function.

func ProfileDelete

func ProfileDelete(symbols *symbols.SymbolTable, args []interface{}) (interface{}, error)

ProfileDelete implements the profile.delete() function. This just calls the set operation with an empty value, which results in a delete operatinon. The consolidates the persmission checking, etc. in the Set routine only.

func ProfileGet

func ProfileGet(symbols *symbols.SymbolTable, args []interface{}) (interface{}, error)

ProfileGet implements the profile.get() function.

func ProfileKeys

func ProfileKeys(symbols *symbols.SymbolTable, args []interface{}) (interface{}, error)

ProfileKeys implements the profile.keys() function.

func ProfileSet

func ProfileSet(symbols *symbols.SymbolTable, args []interface{}) (interface{}, error)

ProfileSet implements the profile.set() function.

func Random

func Random(symbols *symbols.SymbolTable, args []interface{}) (interface{}, error)

Random implmeents the math.Random function.

func ReadDir

func ReadDir(s *symbols.SymbolTable, args []interface{}) (interface{}, error)

ReadDir implements the io.readdir() function.

func ReadFile

func ReadFile(s *symbols.SymbolTable, args []interface{}) (interface{}, error)

ReadFile reads a file contents into a string value.

func ReadString

func ReadString(s *symbols.SymbolTable, args []interface{}) (interface{}, error)

ReadString reads the next line from the file as a string.

func Reflect

func Reflect(s *symbols.SymbolTable, args []interface{}) (interface{}, error)
func Right(symbols *symbols.SymbolTable, args []interface{}) (interface{}, error)

Right implements the right() function.

func Seal

func Seal(i interface{}) interface{}

func SetLogger

func SetLogger(symbols *symbols.SymbolTable, args []interface{}) (interface{}, error)

SetLogger implements the util.SetLogger() function. This sets a logger to be enabled or disabled, and returns the previous state of the logger. It is an error to specify a non-existent logger name. Logger names are not case sensitive.

func Signal

func Signal(s *symbols.SymbolTable, args []interface{}) (interface{}, error)

Signal creates an error object based on the parameters.

func SizeOf

func SizeOf(s *symbols.SymbolTable, args []interface{}) (interface{}, error)

SizeOf returns the size in bytes of an arbibrary object.

func Sleep

func Sleep(s *symbols.SymbolTable, args []interface{}) (interface{}, error)

Sleep implements util.sleep().

func Sort

func Sort(symbols *symbols.SymbolTable, args []interface{}) (interface{}, error)

Sort implements the sort.Sort() function, whichi sorts an array regardless of it's type.

func SortBytes

func SortBytes(s *symbols.SymbolTable, args []interface{}) (interface{}, error)

SortBytes implements the sort.Bytes function.

func SortFloat32s

func SortFloat32s(s *symbols.SymbolTable, args []interface{}) (interface{}, error)

SortFloat32s implements the sort.Float32s function.

func SortFloat64s

func SortFloat64s(s *symbols.SymbolTable, args []interface{}) (interface{}, error)

SortFloat64s implements the sort.Float64s function.

func SortFloats

func SortFloats(s *symbols.SymbolTable, args []interface{}) (interface{}, error)

SortFloats implements the sort.Floats function.

func SortInt32s

func SortInt32s(s *symbols.SymbolTable, args []interface{}) (interface{}, error)

SortInt32s implements the sort.Int32s function.

func SortInt64s

func SortInt64s(s *symbols.SymbolTable, args []interface{}) (interface{}, error)

SortInt64s implements the sort.Int64s function.

func SortInts

func SortInts(s *symbols.SymbolTable, args []interface{}) (interface{}, error)

SortInts implements the sort.Ints function.

func SortStrings

func SortStrings(s *symbols.SymbolTable, args []interface{}) (interface{}, error)

SortStrings implements the sort.Strings function.

func Split

func Split(s *symbols.SymbolTable, args []interface{}) (interface{}, error)

Split splits a string into lines separated by a newline. Optionally a different delimiter can be supplied as the second argument.

func Sprintf

func Sprintf(s *symbols.SymbolTable, args []interface{}) (interface{}, error)

Sprintf implements fmt.sprintf() and is a wrapper around the native Go function.

func Sqrt

func Sqrt(symbols *symbols.SymbolTable, args []interface{}) (interface{}, error)

Sqrt implements the sqrt() function.

func Sscanf

func Sscanf(s *symbols.SymbolTable, args []interface{}) (interface{}, error)

func StrConvAtoi

func StrConvAtoi(s *symbols.SymbolTable, args []interface{}) (interface{}, error)

func StrConvFormatBool

func StrConvFormatBool(s *symbols.SymbolTable, args []interface{}) (interface{}, error)

func StrConvFormatFloat

func StrConvFormatFloat(s *symbols.SymbolTable, args []interface{}) (interface{}, error)

func StrConvFormatInt

func StrConvFormatInt(s *symbols.SymbolTable, args []interface{}) (interface{}, error)

func StrConvItoa

func StrConvItoa(s *symbols.SymbolTable, args []interface{}) (interface{}, error)

func StrConvQuote

func StrConvQuote(s *symbols.SymbolTable, args []interface{}) (interface{}, error)

func StrConvUnquote

func StrConvUnquote(s *symbols.SymbolTable, args []interface{}) (interface{}, error)

func StrLen

func StrLen(symbols *symbols.SymbolTable, args []interface{}) (interface{}, error)

StrLen is the strings.Length() function, which counts characters/runes instead of bytes like len() does.

func Substring

func Substring(symbols *symbols.SymbolTable, args []interface{}) (interface{}, error)

Substring implements the substring() function.

func Sum

func Sum(symbols *symbols.SymbolTable, args []interface{}) (interface{}, error)

Sum implements the sum() function.

func Template

func Template(s *symbols.SymbolTable, args []interface{}) (interface{}, error)

Template implements the strings.template() function.

func TimeAdd

func TimeAdd(s *symbols.SymbolTable, args []interface{}) (interface{}, error)

TimeAdd implements time.duration().

func TimeFormat

func TimeFormat(s *symbols.SymbolTable, args []interface{}) (interface{}, error)

TimeFormat implements time.Format().

func TimeNow

func TimeNow(s *symbols.SymbolTable, args []interface{}) (interface{}, error)

TimeNow implements time.now().

func TimeParse

func TimeParse(s *symbols.SymbolTable, args []interface{}) (interface{}, error)

TimeParse time.Parse().

func TimeSince

func TimeSince(s *symbols.SymbolTable, args []interface{}) (interface{}, error)

func TimeSleep

func TimeSleep(s *symbols.SymbolTable, args []interface{}) (interface{}, error)

TimeSleep implements time.SleepUntil().

func TimeString

func TimeString(s *symbols.SymbolTable, args []interface{}) (interface{}, error)

TimeFormat implements time.Format().

func TimeSub

func TimeSub(s *symbols.SymbolTable, args []interface{}) (interface{}, error)

TimeSub implements time.duration().

func ToString

func ToString(s *symbols.SymbolTable, args []interface{}) (interface{}, error)

ToString implements the strings.string() function, which accepts an array of items and converts it to a single long string of each item. Normally , this is an array of characters.

func Tokenize

func Tokenize(s *symbols.SymbolTable, args []interface{}) (interface{}, error)

Tokenize splits a string into tokens.

func Truncate

func Truncate(symbols *symbols.SymbolTable, args []interface{}) (interface{}, error)

func Type

func Type(s *symbols.SymbolTable, args []interface{}) (interface{}, error)

Type implements the type() function.

func URLPattern

func URLPattern(s *symbols.SymbolTable, args []interface{}) (interface{}, error)

URLPattern uses ParseURLPattern and then puts the result in a native Ego map structure.

func UUIDNew

func UUIDNew(symbols *symbols.SymbolTable, args []interface{}) (interface{}, error)

UUIDNew implements the uuid.New() function.

func UUIDNil

func UUIDNil(symbols *symbols.SymbolTable, args []interface{}) (interface{}, error)

UUIDNil implements the uuid.Nil() function.

func UUIDParse

func UUIDParse(symbols *symbols.SymbolTable, args []interface{}) (interface{}, error)

UUIDParse implements the uuid.Parse() function.

func Upper

func Upper(symbols *symbols.SymbolTable, args []interface{}) (interface{}, error)

Upper implements the upper() function.

func Validate

func Validate(s *symbols.SymbolTable, args []interface{}) (interface{}, error)

Validate determines if a token is valid and returns true/false.

func Write

func Write(s *symbols.SymbolTable, args []interface{}) (interface{}, error)

Write writes an arbitrary binary object to a file.

func WriteAt

func WriteAt(s *symbols.SymbolTable, args []interface{}) (interface{}, error)

Write writes an arbitrary binary object to a file at an offset.

func WriteFile

func WriteFile(s *symbols.SymbolTable, args []interface{}) (interface{}, error)

WriteFile writes a string to a file.

func WriteString

func WriteString(s *symbols.SymbolTable, args []interface{}) (interface{}, error)

WriteString writes a string value to a file.

Types

type AuthToken

type AuthToken struct {
	Name    string
	Data    string
	TokenID uuid.UUID
	Expires time.Time
	AuthID  uuid.UUID
}

AuthToken is the Go native expression of a token value, which contains the identity of the creator, an arbitrary data payload, an expiration time after which the token is no longer valid, a unique ID for this token, and the unique ID of the Ego session that created the token.

type FunctionDefinition

type FunctionDefinition struct {
	Name      string
	Pkg       string
	Min       int
	Max       int
	ErrReturn bool
	FullScope bool
	F         interface{}
	V         interface{}
	D         *data.FunctionDeclaration
}

FunctionDefinition is an element in the function dictionary.

func FindFunction

func FindFunction(f func(*symbols.SymbolTable, []interface{}) (interface{}, error)) *FunctionDefinition

FindFunction returns the function definition associated with the provided function pointer, if one is found.

type MultiValueReturn

type MultiValueReturn struct {
	Value []interface{}
}

MultiValueReturn is a type used to return a list of values from a builtin function. This an be used to return a result and an err to the caller, for example. The Value list must contain the values in the order received by the caller.

type NativeFunction

type NativeFunction func(s *symbols.SymbolTable, args []interface{}) (interface{}, error)

func FindNativeFunction

func FindNativeFunction(kind *data.Type, name string) NativeFunction

For a given datatype and name, see if there is a native function that supports this operation. If so, return it's function pointer.

type NativeFunctionDef

type NativeFunctionDef struct {
	Kind *data.Type
	Name string
	F    NativeFunction
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL