armoha / euddraft

System for pluginizing eudplib codes.
Other
28 stars 4 forks source link

[epScript] Circular import problem when referring to another module's variable within EUD function (new problem introduced in 0.9.9.0) #110

Open Dr-zzt opened 1 year ago

Dr-zzt commented 1 year ago

This is a minimal working example:

main.eps:

import b;
var problem = 0;

function onPluginStart()
{
    py_print("Hello!");
}

b.eps:

import main;

function troublemaker()
{
    main.problem = 1;
}

function funcptrexmaple(f)
{
    return 0;
}

var trouble = funcptrexmaple(f_troublemaker);

This code works fine until 0.9.8.13, but won't compile in 0.9.9.0 or later, due to circular import. My guess is that EUD function pointer content evaluation was lazy before but for some reason it's eager now.

Dr-zzt commented 1 year ago

I did some more experiment, and it's actually seemingly not related to function pointers. This is a smaller example:

main.eps:

import b;
var problem = 0;

function onPluginStart()
{
    py_print("Hello!");
}

b.eps:

import main;

function troublemaker()
{
    main.problem = 1;
    return 0;
}

var trouble = troublemaker();

Works fine until 0.9.8.13, doesn't compile in 0.9.9.0 or later.

armoha commented 1 year ago

It's not just EUDFuncPtr but applying to every epScript globals: https://github.com/armoha/euddraft/blob/master/CHANGELOG.md#bugfix-7

Bugfix

  • [epScript] Don't wrap global consants with ExprProxy unless there's forward-declared function call.
    • No need to write globalConst.getValue() in most cases.

      Improved

  • [epScript] Don't add initialization trigger for global variables when their initial values are constants
var trouble = 1;  // since euddraft 0.9.9.0, this does not execute any trigger on game start
// before 0.9.9.0, this runs/wastes trigger to assign 1 on game start

// in euddraft 0.9.9.0, above code is rewrite into this:
const troubleRewrite = EUDVariable(1);
// works similar to `static var`