katsaii / catspeak-lang

A cross-platform modding language for GameMaker games.
https://www.katsaii.com/catspeak-lang/
MIT License
81 stars 4 forks source link

Implement `new` keyword in Catspeak #72

Closed LocalInsomniac closed 10 months ago

LocalInsomniac commented 11 months ago

Is your feature request related to a problem? Please specify.

Even though Catspeak recognizes the new keyword (see scr_catspeak_lexer), it hasn't been implemented yet and therefore has no functionality. This prevents users from creating new structs through constructors in their Catspeak code without adding wrapper functions.

What is your feature request?

See title.

Have you found an alternative solution? What have you been doing?

If new was implemented, the solution would look like this:

GML:

function Construct() constructor {}
Catspeak.addFunction("Construct", Construct)

Catspeak:

let _inst = new Construct()

Since Catspeak 3 Beta 3 (the latest pre-release at the time of writing this) doesn't have new, creating constructors requires adding wrapper functions to Catspeak like so:

GML:

function Construct() constructor {}

Catspeak.addFunction("Construct", function () {
    return new Construct()
})

Catspeak:

let _inst = Construct()