gm




array

Brief: array will create a fixed size array object
Param: int size optional (0)
Return: array


array




Size

Brief: Size will return the current size of the fixed array
Return: int array size

Resize

Brief: Resize will resize the array to a new size
Param: int size optional (0)
Return: null

Shift

Brief: Shift will shift slide the array elements by a delta, nulls are shifted in
Param: int delta
Return: null

Move

Brief: Move will perform a non destructive move on the array
Param: int dst
Param: int src
Param: int size
Return: null


math




abs

Brief: abs will return the absolute value of the passed int \ float
Param: int\float
Return: int\float abs(param)

sqrt

Brief: sqrt will return the square root of the passed int \ float
Param: int\float
Return: int\float sqrt(param)

sqrt

Brief: sqrt will return the square root of the passed int \ float
Param: int\float A
Param: int\float B
Return: int\float A to the power of B

floor

Brief: floor
Param: float A
Return: float floor(A)

ceil

Brief: ceil
Param: float A
Return: float ceil(A)

round

Brief: round
Param: float A
Return: float round(A)

degtorad

Brief: degtorad will convert degrees to radians
Param: float\int deg
Return: float

radtodeg

Brief: radtodeg will convert radians to degrees
Param: float\int rad
Return: float

cos

Brief: cos will return the radian cosine
Param: float
Return: float

sin

Brief: sin will return the radian sine
Param: float
Return: float

tan

Brief: tan will return the radian tan (sin/cos)
Param: float
Return: float

acos

Brief: acos will return the radian arc cosine
Param: float
Return: float

asin

Brief: asin will return the radian arc sine
Param: float
Return: float

atan

Brief: atan will return the radian arc tangent
Param: float
Return: float

atan

Brief: atan will return the radian arc tangent of x / y
Param: float x
Param: float y
Return: float

log

Brief: log will return the natural logarithm of 1 parameter, or (base, value) the logarithm to base
Param: float natural \ base
Param: float value (optional)
Return: float

min

Brief: min will return the min of the 2 passed values
Param: float\int A
Param: float\int B
Return: float \ int min(A, B)

max

Brief: max will return the max of the 2 passed values
Param: float\int A
Param: float\int B
Return: float \ int max(A, B)

clamp

Brief: clamp will return the clamed value. clamp(min, val, max)
Param: float\int MIN
Param: float\int VALUE
Param: float\int MAX
Return: float\int value clamped to min, max

randint

Brief: randint will return a random int from lower inclusive to upper.
Param: int lower inclusive
Param: int upper
Return: int

randfloat

Brief: randfloat will return a random float from lower inclusive to upper.
Param: float lower inclusive
Param: float upper
Return: float

randseed

Brief: randseed will seed the random number generator
Param: int seed


string



Brief: string operations often store a copy of the string on the stack, so keep string sizes reasonable

IsEmpty

Brief: IsEmpty will test to see if the string is 0 length
Return: non-zero if the string is empty

Length

Brief: Length will return the length of the string not including the null terminating character
Return: int length

Left

Brief: Left will return the left count charaters of the string
Param: int count
Return: string

Right

Brief: Right will return the right count charaters of the string
Param: int count
Return: string

RightAt

Brief: RightAt will return the charaters right of and including the given index
Param: int index
Return: string

Mid

Brief: Mid will return count characters from the start index
Param: int startIndex
Param: int count
Return: string

Compare

Brief: Compare will perform a string compare
Param: string to compare
Return: -1 if the this < compare string, 0 if the strings are equal, 1 otherwise

CompareNoCase

Brief: CompareNoCase will perform a string compare (case insensitive)
Param: string to compare
Return: -1 if the this < compare string, 0 if the strings are equal, 1 otherwise

Int

Brief: Int will return the int value of the string
Return: int value

Float

Brief: Float will return the float value of the string
Return: float value

String

Return: string

Upper

Brief: Upper will return the string as uppercase
Return: string

Lower

Brief: Lower will return the string as lowercase
Return: string

SpanIncluding

Brief: SpanIncluding will return this string while characters are within the passed string
Param: string charset
Return: string

SpanExcluding

Brief: SpanExcluding will return this string while characters are not within the passed string
Param: string charset
Return: string

AppendPath

Brief: AppendPath will append a path make sure one '\' is maintained
Param: string path to append
Return: string

ReplaceCharsInSet

Brief: ReplaceCharsInSet will replace all chars in this that are within the charset with the given int char
Param: int char to replace with
Param: string charset of chars to replace
Return: string

Find

Brief: Find will find the first occurance of the passed string within this string
Param: string search string
Param: int start index optional (0)
Return: int index of first occurance, or -1 if the string was not found

Reverse

Brief: Reverse characters of a string
Return: string

ReverseFind

Brief: ReverseFind will find the first occurance of the passed string within this string starting from the right
Param: string search string
Return: int index of first occurance, or -1 if the string was not found

GetAt

Brief: GetAt will return the char at the given index
Param: int index
Return: int char, or null if index was out of range

SetAt

Brief: SetAt will return the string with the character set at the given position
Param: int index
Param: int char
Return: string

TrimLeft

Brief: TrimLeft will return the string with the chars from the passed char set trimmed from the left
Param: string charset optional (" \r\n\v\t")
Return: string

TrimRight

Brief: TrimRight will return the string with the chars from the passed char set trimmed from the right
Param: string charset optional (" \r\n\v\t")
Return: string

GetFilenameNoExt

Brief: GetFilenameNoExt will return the filename part of a path string
Return: string

GetFilename

Brief: GetFilename will return the filename part of a path string incl. extension
Return: string

GetExtension

Brief: GetExtension will return the file extension
Param: int inclDot optional (0) 1 will include '.', 0 won't
Return: string

SetExtension

Brief: SetExtension returns a string with the extension change to the given one.
Param: string ext optional (null) the new extension, with or without the dot. null to remove extension.
Return: string

GetPath

Brief: GetPath will return the file path from a path string
Param: int inclSlash optional (0) will include a '\' on the end of the path
Return: string


system



Brief: system functions are bound in a "system" table.

Exec

Brief: Exec will execute a system command
Param: string params will be concatinated together with a single space to form the final system command string
Return: integer value returned from system exec call, -1 on error

DoFile

Brief: DoFile will execute the gm script in the named file
Param: string filename
Param: int optional (1) as 1 will execute string before returning, 0 will execute later.
Param: ref optional (null) set 'this'
Return: thread id of new thread created to execute file

File

Brief: File will create a file object
Return: file object

FileExists

Brief: FileExists will test to see if a file exists
Param: string filename
Return: 1 if the file exists, otherwise 0

FileFindFirst

Brief: FileFindFirst will start a file search will test to see if a file exists
Param: string filesearch (may contain wildcards, eg, `c:\temp\*.txt`)
Return: fileFind object. fileFind object has .filename and .size member
See Also: fileFind

FileFindNext

Brief: FileFindNext will get the next file matching the file find
Param: fileFind object returned by FileFindFirst call or FileFindNext call
Return: fileFind object
See Also: fileFind

FileInfo

Brief: FileInfo will return a file info object that has readonly members for .creationDate
Param: string path
Return: fileInfo object, fileInfo object has a .creationTime, .accessedTime, .modifiedTime and a .size

CreateFolder

Brief: CreateFolder will create a file path if it does not already exist
Param: string path
Return: int 0 on failure, 1 on successful create, 2 if folder already exists

DeleteFolder

Brief: DeleteFolder will remove a file path
Param: string path
Param: int remove subfiles and folders optional (0)
Return: int 1 on success, 0 con failure

Time

Brief: Time will return a unix style time_t as an int
Return: the current time

FormatTime

Brief: FormatTime will take a int (time_t) value and format according to the passed format string.
Param: int time (-1) is a (time_t) to be converted to a string, passing -1 gets current time
Param: string format ("%A %d %B %Y, %I:%M:%S %p") is the format string to use.
%a : Abbreviated weekday name
%A : Full weekday name
%b : Abbreviated month name
%B : Full month name
%c : Date and time representation appropriate for locale
%d : Day of month as decimal number (01 – 31)
%H : Hour in 24-hour format (00 – 23)
%I : Hour in 12-hour format (01 – 12)
%j : Day of year as decimal number (001 – 366)
%m : Month as decimal number (01 – 12)
%M : Minute as decimal number (00 – 59)
%p : Current locale’s A.M./P.M. indicator for 12-hour clock
%S : Second as decimal number (00 – 59)
%U : Week of year as decimal number, with Sunday as first day of week (00 – 53)
%w : Weekday as decimal number (0 – 6; Sunday is 0)
%W : Week of year as decimal number, with Monday as first day of week (00 – 53)
%x : Date representation for current locale
%X : Time representation for current locale
%y : Year without century, as decimal number (00 – 99)
%Y : Year with century, as decimal number
%z, %Z : Time-zone name or abbreviation; no characters if time zone is unknown
%% : Percent sign

Return: the time as a string.


fileFind



Brief: fileFind object has a "filename" and "size" member

GetAttribute

Brief: GetAttribute will test a file attribute.
Param: int char attribute 'r' readonly, 'a' archive, 's' system, 'h' hidden, 'c' compressed, 'd' directory
Return: 1 if the attribute is set, 0 otherwise


file




Open

Brief: Open will open a file in binary mode
Param: string filename
Param: int readonly optional (1)
Return: 1 if the open was successful, 0 otherwise

OpenText

Brief: OpenText will open a file in text mode
Param: string filename
Param: int readonly optional (1)
Return: 1 if the open was successful, 0 otherwise

Close

Brief: Close will close a file

IsOpen

Brief: IsOpen will test to see if a file is open
Return: 1 if the file is open, 0 otherwise

Seek

Brief: Move to position within file
Param: int offset positional offset relative to origin
Param: int origin eg. myFile.SEEK_CUR, myFile.SEEK_END, myFile.SEEK_SET for current, end, start origins.
Return: int 1 if operation succeeded, 0 if failed.

Tell

Brief: Tell will return the current cursor position of the file
Return: int the current cursor position, -1 on error

ReadLine

Brief: ReadLine will read a line of text from the file.
Param: int keep optional (0) as 1 will keep the "\n" char on the line, otherwise it is removed
Return: string, or null on eof

ReadChar

Brief: ReadChar will read a char from the file
Return: int char or null on eof

WriteString

Brief: WriteString will write a string to the file
Param: string to write to file
Return: 1 on success, null on error

WriteChar

Brief: WriteChar will write a char to the file
Param: int char to write to file
Return: 1 on success, null on error


Vector3




Vector3

Brief: Create a Vector3 object
Param: float x or [0] optional (0)
Param: float y or [1] optional (0)
Param: float z or [2] optional (0)


Vector3



Brief: Vector3 math class

DominantAxis

Brief: Find the index of the largest vector component.
This: Vector to evaluate.
Return: int Index of largest component.

Dot

Brief: Calculate the Dot (or Inner) Product of two vectors.
This: Vector3 First vector.
Param: Vector3 Second vector.
Return: float result.

Length

Brief: Length will return the length of the vector.
Return: float Dot product result that is cosine of the angle between the two vectors.

Cross

Brief: Calculate the Cross (or Outer) Product of two vectors.
This: Vector3 First vector.
Param: Vector3 Second vector.
Return: Vector3 Cross product resultant vector that is perpendicular to the two input vectors and length sine of the angle between them.

Normalize

Brief: Return a unit length copy of this vector.
This: Vector to be copied.
Return: Vector3 Unit length copy of this vector.

LengthSquared

Brief: Return the squared length of the vector.
Return: float Squared length of the vector.

ProjectFrom

Brief: Project a direction from a point.
This: Vector3 Direction.
Param: Vector3 Start point;
Param: float Distance or time.
Return: Vector3 Projected result.

Clone

Brief: Return a copy of this vector.
Return: A copy of this vector.

Set

Brief: Set vector from other vector or 3 components.

LerpToPoint

Brief: Linear interpolate between two 'point' vectors.
This: Vector3 From vector.
Param: Vector3 To vector.
Param: float Fraction or time between 0 and 1.
Return: Vector3 Resulting inbetween vector.

SlerpToVector

Brief: Spherical linear interpolate between two vectors.
This: Vector3 From vector.
Param: Vector3 To vector.
Param: float Fraction or time between 0 and 1.
Return: Vector3 Resulting inbetween vector.

RotateAxisAngle

Brief: Rotate around Axis by Angle.
This: Vector3 Vector to rotate.
Param: Vector3 Unit length axis of rotation.
Param: float Angle amount to rotate.
Return: Vector3 Resulting rotated vector.

RotateX

Brief: Rotate around X Axis by Angle.
This: Vector3 Vector to rotate.
Param: float Angle amount to rotate.
Return: Vector3 Resulting rotated vector.

RotateX

Brief: Rotate around Y Axis by Angle.
This: Vector3 Vector to rotate.
Param: float Angle amount to rotate.
Return: Vector3 Resulting rotated vector.

RotateZ

Brief: Rotate around Z Axis by Angle.
This: Vector3 Vector to rotate.
Param: float Angle amount to rotate.
Return: Vector3 Resulting rotated vector.

SetAdd

Brief: Add two vectors, store result in this. Demonstrate relative efficiency compared to operator version.
This: Vector3 Result vector.
Param: Vector3 First vector.
Param: Vector3 Second vector.

Add

Brief: Add vector to this. Demonstrate relative efficiency compared to operator version.
This: Vector3 Result vector.
Param: Vector3 vector to add.


gm



Brief: functions in the gm lib are all global scope

debug

Brief: debug will cause a the debugger to break at this point while running.


gm



Brief: functions in the gm lib are all global scope

gmVersion

Brief: gmVersion will return the gmMachine version string. version string is major type . minor type as a string and was added at version 1.1
Return: string

typeId

Brief: typeId will return the type id of the passed var
Param: var
Return: integer type

typeName

Brief: typeName will return the type name of the passed var
Param: var
Return: string

typeRegisterOperator

Brief: typeRegisterOperator will register an operator for a type
Param: int typeid
Param: string operator name is one of "getdot", "setdot", "getind", "setind", "add", "sub", "mul", "div", "mod", "inc", "dec", "bitor", "bitxor", "bitand", "shiftleft", "shiftright", "bitinv", "lt", "gt", "lte", "gte", "eq", "neq", "neg", "pos", "not"
Param: function
Return: 1 on success, otherwise 0

typeRegisterVariable

Brief: typeRegisterVariable will register a variable with a type such that (type).varname will return the variable
Param: int typeid
Param: string var name
Param: var
Return: 1 on success, otherwise 0

sysCollectGarbage

Brief: sysCollectGarbage will run the garbage collector iff the current mem used is over the desired mem used
Param: forceFullCollect (false) Optionally perform full garbage collection immediately if garbage collection is not disabled.
Return: 1 if the gc was run, 0 otherwise

sysGetMemoryUsage

Brief: sysGetMemoryUsage will return the current memory used in bytes
Return: int memory usage

sysSetDesiredMemoryUsageHard

Brief: sysSetDesiredMemoryUsageHard will set the desired memory useage in bytes. when this is exceeded the garbage collector will be run.
Param: int desired mem usage in bytes

sysSetDesiredMemoryUsageSoft

Brief: sysSetDesiredMemoryUsageSoft will set the desired memory useage in bytes. when this is exceeded the garbage collector will be run.
Param: int desired mem usage in bytes

sysGetDesiredMemoryUsageHard

Brief: sysGetDesiredMemoryUsageHard will get the desired memory useage in bytes. Note that this value is used to start garbage collection, it is not a strict limit.
Return: int Desired memory usage in bytes.

sysGetDesiredMemoryUsageSoft

Brief: sysGetDesiredMemoryUsageSoft will get the desired memory useage in bytes. Note that this value is used to start garbage collection, it is not a strict limit.
Return: int Desired memory usage in bytes.

sysSetDesiredMemoryUsageAuto

Brief: sysSetDesiredMemoryUsageAuto will enable auto adjustment of the memory limit(s) for subsequent garbage collections.
Param: int enable or disable flag

sysGetStatsGCNumFullCollects

Brief: sysGetStatsGCNumFullCollects Return the number of times full garbage collection has occured.
Return: int Number of times full collect has occured.

sysGetStatsGCNumIncCollects

Brief: sysGetStatsGCNumIncCollects Return the number of times incremental garbage collection has occured. This number may increase in twos as the GC has multiple phases which appear as restarts.
Return: int Number of times incremental collect has occured.

sysGetStatsGCNumWarnings

Brief: sysGetStatsGCNumWarnings Return the number of warnings because the GC or VM thought the GC was poorly configured. If this number is large and growing rapidly, the GC soft and hard limits need to be configured better. Do not be concerned if this number grows slowly.
Return: int Number of warnings garbage collect has generated.

sysIsGCRunning

Brief: Returns true if GC is running a cycle.

sysTime

Brief: sysTime will return the machine time in milli seconds
Return: int

doString

Brief: doString will execute the passed gm script
Param: string script
Param: int optional (1) set as true and the string will execute before returning to this thread
Param: ref optional (null) set 'this'
Return: int thread id of thread created for string execution

globals

Brief: globals will return the globals table
Return: table containing all global variables

threadTime

Brief: threadTime will return the thread execution time in milliseconds
Return: int

threadId

Brief: threadId will return the thread id of the current executing script
Return: int

threadAllIds

Brief: threadIds returns a table of thread Ids
Return: table of thread Ids

threadKill

Brief: threadKill will kill the thread with the given id
Param: int threadId optional (0) will kill this thread

threadKillAll

Brief: threadKillAll will kill all the threads except the current one
Param: bool optional (false) will kill this thread if true

thread

Brief: thread will start a new thread
Param: function entry point of the thread
Param: ... parameters to pass to the entry function
Return: int threadid

yield

Brief: yield will hand execution control to the next thread

exit

Brief: exit will kill this thread

assert

Brief: assert
Param: int expression if true, will do nothing, if false, will cause an exception

sleep

Brief: sleep will sleep this thread for the given number of seconds
Param: int\float seconds

signal

Brief: signal will signal the given variable, this will unblock dest threads that are blocked on the same variable.
Param: var
Param: int destThreadId optional (0) 0 will signal all threads

block

Brief: block will block on all passed vars, execution will halt until another thread signals one of the block variables. Will yield on null and return null.
Param: ... vars
Return: the unblocking var

stateSet

Brief: stateSet will collapse the stack to nothing, and push the passed functions.
Param: function new state function to execute
Param: ... params for new state function

stateSetOnThread

Brief: stateSetOnThread will collapse the stack of the given thread id to nothing, and push the passed functions.
Param: int thread id
Param: function new state function to execute
Param: ... params for new state function

stateGet

Brief: stateGet will return the function on the bottom of this threads execution stack iff it was pushed using stateSet
Param: a_threadId Optional Id of thread to get state on. \reutrn function \ null

stateGetLast

Brief: stateGetLast will return the last state function of this thread
Param: a_threadId Optional Id of thread to get last state on. \reutrn function \ null

stateSetExitFunction

Brief: stateSetExitFunction will set an exit function for this state, that will be called with no parameters if this thread switches state
Param: function

tableCount

Brief: tableCount will return the number of elements in a table object
Param: table
Return: int

tableDuplicate

Brief: tableDuplicate will duplicate the passed table object
Param: table
Return: table

print

Brief: print will print the given vars to the print handler. passed strings are concatinated together with a seperating space.
Param: ... strings

format

Brief: format (like sprintf, but returns a string) %d, %s, %f, %c, %b, %x, %e
Param: string