Open Source Cross-Platform Game Programming

Core

The core library exposes some basic built-in language functionality. Unlike other libraries, the Core library does not need to be imported and is readily available from all files.

enum Type[link]

Enum representing the various types in Crayon.

NameDescription
NULL

null

BOOLEAN

booleans (true and false)

INTEGER

integers

FLOAT

floating point decimals

STRING

strings (text)

LIST

lists

DICTIONARY

dictionaries

OBJECT

object instances

FUNCTION

function pointer

CLASS

class reference

function assert(condition, message)[link]

Generates an exception if the condition is false.

Arguments

NameTypeOptionalDescription
condition boolean

A boolean condition that must be true.

message string Optional

An optional error message to show when the assertion condition is false.

function chr(charCode)[link]

Converts a character code value (as a unicode point value) into a single-character string.

Arguments

NameTypeDescription
charCode integer

Unicode code point value.

function currentTime()[link]

Returns the current unix time stamp as reported by the local machine. The unix time stamp is the number of seconds since midnight January 1st, 1970.

function fail(message)[link]

Generates an exception when called.

Arguments

NameTypeDescription
message string

An error message to show in the exception.

function isNumber(value)[link]

Returns true if the given value is one of the numeric types (integer or float). This is semantically identical to typeof(value) == Core.Types.INTEGER || typeof(value) == Core.Types.FLOAT.

Arguments

NameTypeDescription
value any

Any value

Return Value

TypeDescription
boolean

True if the value is an integer or a float

function isString(value)[link]

Returns true if the given value is a string. This is semantically identical to typeof(value) == Core.Types.STRING.

Arguments

NameTypeDescription
value any

Any value

Return Value

TypeDescription
boolean

True if the value is a string

function ord(character)[link]

Converts a character value into its numerical unicode point value. If the string passed in has multiple characters, the first character is used.

Arguments

NameTypeDescription
character string

A single-character string

function parseFloat(value)[link]

Converts a decimal (or integer) string into its actual numeric value. If the number depicted is an integer, the return value will still be a float (see parseInt). Surrounding whitespace is ignored. If the string does not depict a number, null is returned instead.

Arguments

NameTypeDescription
value string

A floating point number as a string.

function parseInt(value)[link]

Converts an integer as a text string into the actual integer type. Surrounding whitespace is ignored. If the string does not depict an integer, null is returned. If the string is a floating point decimal, null is also returned (see parseFloat).

Arguments

NameTypeDescription
value string

An integer as a string.

function print(value)[link]

Shows a message or value in the standard output. Standard output is generally in the same window as the command line for platforms that support this, however, the actual output may appear elsewhere depending on the platform (for example, the JavaScript console, or the Android Log).

Arguments

NameTypeDescription
value any

Item or message to display in standard output

function sleep(delay)[link]

Pauses execution for some number of seconds. NOTE: for JavaScript-exported platforms, the underlying implementation uses a setTimeout rather than blocking the browser thread, so this is still safe to use in JavaScript without causing the browser to become unresponsive.

Arguments

NameTypeDescription
delay float

Number of seconds to pause execution

function typeof(value)[link]

Determines which type the given value is.

Arguments

NameTypeDescription
value any

Any value

Return Value

TypeDescription
Core.Type

A type

class AssertionFailedException[link]

Exception thrown by Core.assert() and Core.fail()

class DivisionByZeroException[link]

Generated when you divide or mod by 0.

class Exception[link]

The root class of all exceptions.

Fields

NameTypeDescription
.message string

Error message of the exception

.cause Core.Exception

A wrapped exception that caused this exception to occur.

new Exception(message, cause)[link]

Instantiates a new exception. Optionally allows for setting a message and also another exception that caused this exception.

Arguments

NameTypeOptionalDescription
message string Optional

Message to show in the exception

cause Core.Exception Optional

Another exception

function getTrace()[link]

Returns a stack trace of where the exception was thrown.

Return Value

TypeDescription
List of strings

The stack trace of this exception.

class FatalException[link]

An exception that cannot be caught. This is generated by the VM in situations where it cannot recover, such as stack overflows.

class IndexOutOfRangeException[link]

Generated when you access an index in a list outside of its bounds.

class InvalidArgumentException[link]

General exception used when an argument to a function is wrong. The message field should contain specific information.

class InvalidAssignmentException[link]

Exception generated when you assign a value to an invalid target. For example, attempting to assign a value to a field that is already occupied by a function defined in code.

class InvalidInvocationException[link]

Generated when you attempt to invoke a non-function value like a function.

class InvalidKeyException[link]

Generated when you attempt to use a value for a dictionary key that is not an integer, object, or string.

class InvalidOperationException[link]

General-purpose exception for when something has been invoked incorrectly. The message should contain specific information.

class KeyNotFoundException[link]

Generated when you attempt to access a key in a dictionary that does not exist.

class NotImplementedException[link]

Useful exception to throw for when you want to mark a function as not having been implemented.

class NullReferenceException[link]

Thrown when null is accessed as though it is a non-null value.

class UnassignedVariableException[link]

Occurs when a variable is used before it has any value assigned to it.

class UnknownFieldException[link]

Occurs when you access a field on a value that does not exist.

class UnsupportedOperationException[link]

General purpose exception for when you attempt to use code in a way that it was not designed to support. Also thrown when you perform operations on types that do not have that combination of operations defined. For example, subtracting a list from a string.

function getClasses(commonBaseClass)[link]

Gets a list of all class types in the project. Optionally, you can pass a filter argument to limit results down to only classes that implement that base class.

Arguments

NameTypeOptionalDescription
commonBaseClass class Optional

filters results to only classes that extend from this class

Return Value

TypeDescription
List of class

A list of class references

function getClassFromInstance(instance)[link]

Gets a reference to the class of the given object.

Arguments

NameTypeDescription
instance object

Any instance of an object.

Return Value

TypeDescription
class

The class of the object.

function getMethods(instanceOrClass)[link]

Gets a list of methods on an instance or class. For instances, only instance methods are returned. For classes, only static methods are returned.

Arguments

NameTypeDescription
instanceOrClass object or class

instance or class to get methods from.

Return Value

TypeDescription
List of functions

A list of function pointers.