armoha / euddraft

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

[epScript] Does epScript support Enum? #41

Closed zuhanit closed 3 years ago

zuhanit commented 3 years ago

In python over version 3.4, we can use enum like below:

class CUnitPosition(Enum):
    MOVETARGET = 0x10,
    POSITION = 0x28,
    ORDERTARGET = 0x58

print(CUnitPosition.MOVETARGET.value) # 16

But when I tried to use Enum, euddraft push General Syntax Error. it seems like Object doesn't support inheritance, just convert into EUDStruct. is there any way to use Enum in epScript? or instead, Can I create custom Python Class in epScript?

armoha commented 3 years ago

You can define python class in python script and import it in epScript, but can't define any python class nor function solely in epScript.

zuhanit commented 3 years ago

Thanks! I solved this question using python class.

#mypy.py
import enum

class MyClass(enum.Enum):
    FOO = 0,
    BAR = 1
import mypy;

function afterTriggerExec() {
    const k = EPD(Db(mypy.MyClass.FOO.name));
    const s = StringBuffer(1230);
    s.printf("{:t}", k); // 'FOO'
}