katsaii / catspeak-lang

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

Creating a new environment and using `.parseString()` refers to Catspeak env. #87

Closed tabularelf closed 1 year ago

tabularelf commented 1 year ago

What version of Catspeak are you using?

3.0.0-beta3

What happened?

While I was making a separate environment to add in keywords and execute via env.parseString(_str), I was getting strange compiling errors until I realized that it's just accessing Catspeak itself. (On a off note, there's a memory leak here too)

I think it should be changed to something like this instead.

    static parseString = function (src) {
        var buff = __catspeak_create_buffer_from_string(src);
        var result = parse(buff);
    buffer_delete(buff);
    return result;
    };

Code that demonstrates this problem:

env = new CatspeakEnvironment();
env.renameKeyword(
        "//", "div",
        "--", "//"
);
// Fails to parse due to pointing towards Catspeak in .parseString
var asg = env.parseString(@"// A Comment!
    num = 42;
    return num;
");
func = env.compileGML(asg);
show_debug_message(func());
katsaii commented 1 year ago

Good catch, this will make it into the 3.0.0 release.