struct CatspeakEnvironment
function CatspeakEnvironment() constructor {
self.interface : Struct.CatspeakForeignInterface;
// 2 fields omitted
}
Encapsulates all common Catspeak features into a single, configurable box.
§ addConstant
static addConstant = function(
name : String,
value : Any,
... : Any,
)
👎 DeprecatedUse
Catspeak.interface.exposeConstant
instead.
Used to add a new constant to this environment.
Arguments
name
The name of the constant as it will appear in Catspeak.
value
The constant value to add.
...
Additional arguments in the same name-value format.
§ addFunction
static addFunction = function(
name : String,
func : Function,
... : Any,
)
👎 DeprecatedUse
Catspeak.interface.exposeFunction
instead.
Used to add a new unbound function to this environment.
Arguments
name
The name of the function as it will appear in Catspeak.
func
The script or function to add.
...
Additional arguments in the same name-value format.
§ addKeyword
static addKeyword = function(
name : String,
token : Enum.CatspeakToken,
... : Any,
)
🔬 This is an experimental feature. It may change at any moment.
Used to add a new Catspeak keyword alias.
Arguments
name
The name of the keyword to add. E.g.
"otherwise"
token
The token this keyword should represent. E.g.
CatspeakToken.ELSE
...
Additional arguments in the same name-value format.
§ addMethod
static addMethod = function(
name : String,
func : Function,
... : Any,
)
👎 DeprecatedUse
Catspeak.interface.exposeMethod
instead.
Used to add a new method to this environment.
Arguments
name
The name of the function as it will appear in Catspeak.
func
The script or function to add.
...
Additional arguments in the same name-value format.
§ applyPreset
static applyPreset = function(
preset : Enum.CatspeakPreset,
... : Enum.CatspeakPreset,
)
🔬 This is an experimental feature. It may change at any moment.
Applies list of presets to this Catspeak environment. These changes cannot be undone, so only choose presets you really need.
You can add additional presets using the catspeak_preset_add
function.
Arguments
preset
The preset type to apply.
...
Additional presets.
Example
Enabling the math and draw presets on the default Catspeak environment:
Catspeak.applyPreset(
CatspeakPreset.MATH,
CatspeakPreset.DRAW
);
§ compileGML
static compileGML = function(
ir : Struct,
) -> Function
Compiles Catspeak IR into a callable GML function.
Arguments
ir
The Catspeak IR to compile. You can get this from
Catspeak.parse
.
Returns Function
§ enableSharedGlobal
static enableSharedGlobal = function(
enabled? : Bool,
) -> Struct
Enables the shared global feature on this Catspeak environment, forcing all Catspeak programs compiled after this point to share the same global variable scope.
Typically this should not be enabled, but it can be useful for REPL (Read-Eval-Print-Loop) style command consoles, where variables persist between commands.
Returns the shared global struct if this feature is enabled, or
undefined
if the feature is disabled.
Arguments
enabled
(optional)Whether to enable this feature. Defaults to
true
.
Returns Struct
§ getInterface
static getInterface = function()
-> Struct.CatspeakForeignInterface
👎 Deprecated since 3.0.0Use
Catspeak.interface
instead.
Returns Struct.CatspeakForeignInterface
§ interface
self.interface : Struct.CatspeakForeignInterface
The foreign interface used by this Catspeak environment. This is where all external GML functions and constants are exposed to the Catspeak runtime environment.
Returns Struct.CatspeakForeignInterface
§ parse
static parse = function(
buff : Id.Buffer,
offset? : Real,
size? : Real,
) -> Struct.CatspeakLexer
Parses a buffer containing a Catspeak program into a bespoke format
understood by Catspeak. Overrides the keyword database if one exists
for this CatspeakEngine
.
⚠️ WarningThe parser does not take ownership of this buffer, so you must make sure to delete it after calling this function. Failure to do this will result in leaking memory.
Arguments
buff
The ID of the GML buffer to use.
offset
(optional)The offset in the buffer to start parsing from. Defaults to 0.
size
(optional)The length of the buffer input. Any characters beyond this limit will be treated as the end of the file. Defaults to
infinity
.
Returns Struct.CatspeakLexer
§ parseAsync
static parseAsync = function(
buff : Id.Buffer,
offset? : Real,
size? : Real,
)
🔬 This is an experimental feature. It may change at any moment.
Similar to parse
, except it will pass the responsibility of
parsing to this environments async handler.
📝 NoteThe async handler can be customised, and therefore any third-party handlers are not guaranteed to finish within a reasonable time.
Arguments
buff
The ID of the GML buffer to use.
offset
(optional)The offset in the buffer to start parsing from. Defaults to 0.
size
(optional)The length of the buffer input. Any characters beyond this limit will be treated as the end of the file. Defaults to
infinity
.
§ parseString
static parseString = function(
src : String,
) -> Struct.CatspeakLexer
Similar to Catspeak.parse
, except a string is used instead of a buffer.
Arguments
src
The string containing Catspeak source code to parse.
Returns Struct.CatspeakLexer
§ removeConstant
static removeConstant
👎 DeprecatedUse
Catspeak.interface.addBanList
instead.
Used to remove an existing constant from this environment.
📝 NoteAlthough you can use this to remove functions, it's recommended to use
Catspeak.removeFunction
for that purpose instead.
Arguments
name
The name of the constant to remove.
...
Additional constants to remove.
§ removeFunction
static removeFunction
👎 DeprecatedUse
Catspeak.interface.addBanList
instead.
Used to remove an existing function from this environment.
Arguments
name
The name of the function to remove.
...
Additional functions to remove.
§ removeKeyword
static removeKeyword = function(
name : String,
... : String,
)
🔬 This is an experimental feature. It may change at any moment.
Used to remove an existing Catspeak keyword from this environment.
Arguments
name
The name of the keyword to remove. E.g.
"do"
...
Additional keywords to remove.
§ renameKeyword
static renameKeyword = function(
currentName : String,
newName : String,
... : Any,
)
🔬 This is an experimental feature. It may change at any moment.
Used to change the string representation of a Catspeak keyword.
Arguments
currentName
The current string representation of the keyword to change. E.g.
"fun"
newName
The new string representation of the keyword. E.g.
"function"
...
Additional arguments in the same name-value format.
§ tokenise
static tokenise = function(
buff : Id.Buffer,
offset? : Real,
size? : Real,
) -> Struct.CatspeakLexer
Creates a new CatspeakLexer
from the supplied buffer, overriding
the keyword database if one exists for the current Catspeak
environment.
⚠️ WarningThe lexer does not take ownership of this buffer, so you must make sure to delete it after calling this function. Failure to do this will result in leaking memory.
Arguments
buff
The ID of the GML buffer to use.
offset
(optional)The offset in the buffer to start parsing from. Defaults to 0.
size
(optional)The length of the buffer input. Any characters beyond this limit will be treated as the end of the file. Defaults to
infinity
.
Returns Struct.CatspeakLexer