armoha / euddraft

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

Unexpected output for f_parse? #6

Closed Chromowolf closed 4 years ago

Chromowolf commented 4 years ago
function onPluginStart() {
    const s = StringBuffer(256);
    s.insert(0);
    s.append("123");
    const sAddr = GetMapStringAddr(s.StringIndex);
    simpleprint(parse(sAddr));

    s.insert(0);
    s.append("0xFF");
    simpleprint(parse(sAddr, radix = 0));

    s.insert(0);
    s.append("0b0101");
    simpleprint(parse(sAddr, radix = 0));

    simpleprint(parse(GetMapStringAddr($T("24680")), radix = 0));
}

Expected output:

123
255
5
24680

But I got this instead:

1233
2552
53
246805

The return value of parse seems to have an unwanted trailing digit which equals the number of digits of the input number. Is this a bug or an intended feature? (PS: I'm using the current newest version 1.23.3.7146)

armoha commented 4 years ago

It is intended, f_parse has 2 return values, parsed value and digits. And simpleprint accepts varargs so you actually printed like this;

const number, digit = parse(address, base);
simpleprint(number, digit);

To fix: use [[0]] or deconstruct like above and only use number value. It is intended to return digit as you can differentiate parse error and parse 0 by confirm digit is 0 or greater than 0.

I didn't want to introduce EUDErrno at that moment so decided to yield digits too, having refered other programming APIs.

Chromowolf commented 4 years ago

Got it. Thank you. Sorry for not reading the ChangeLog carefully.