Repository navigation
feat(avm1): evaluate String, Number and Boolean conversion calls - #71
Merged
Merged
Conversation
Data scripts wrap literals in the built-in conversion functions, as in `C.SPEAKING_ITEMS_MSG_COUNT = Number(30);`. ActionCallFunction always pushed undefined, so every such constant was lost (88 of the 100 constants of the Dofus Retro `lang` file). ActionCallFunction now evaluates String(x), Number(x) and Boolean(x) with the machine's own version-gated ToStr, ToNum and ToBool coercion. As in the player, only the first argument is used, and a call with no argument returns "", 0 and undefined respectively. Names match case-insensitively before SWF 7, like every other identifier. Any other function still evaluates to undefined.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
For 1.8.1.
Avm1Machinenow evaluates calls to the built-in conversion functionsString(x),Number(x)andBoolean(x). Until now,ActionCallFunctionalways pushedundefined.Why: data scripts wrap literals in these calls, as in
C.CHECK_MAP_FILE_ID = Boolean(true);,C.SPEAKING_ITEMS_MSG_COUNT = Number(30);andC.RSS_LINK = String("http://…");. In the Dofus Retrolangfile, 88 of the 100 constants came outundefinedbecause of this.What changed:
ActionCallFunctionpops the name, the argument count and the arguments. ForString,NumberandBooleanit pushesToStr,ToNumorToBoolof the first argument. These are the same version-gated rules the operators use, soNumber("30")is30,Boolean(0)isfalse, andBoolean("0")isfalsebefore SWF 7 andtruefrom SWF 7."",0andundefinedrespectively. This matches Ruffle'sstring_function,number_functionandboolean_function.undefined.NewObjectandCallMethodare unchanged.avm1/machine.mdxhas a new Conversion calls section and an extra line in Version-gated behavior. The scope notes inavm1/index.mdxandindex.mdxnow name the supported calls.Tests:
Avm1ConversionCallTests(10 tests) builds the actions in code, encodes them toDoActionbytes and runs them throughAvm1Machine.Runin strict mode. The tests cover:lang-styleC.X = Boolean/Number/String(…)scriptNumber("30"),Number("0x1F"),Boolean(0), andBoolean("0")on SWF 6 and on SWF 7undefinedValidation:
dotnet test -c Releasepasses 381/381 (371 existing + 10 new) with zero warnings. No changelog file is kept in the repository.🤖 Generated with Claude Code