Skip to content

feat(avm1): evaluate String, Number and Boolean conversion calls - #71

Merged
AerafalDev merged 1 commit into
mainfrom
feat/avm1-conversion-calls
Nov 17, 2026
Merged

AerafalDev merged 1 commit into
mainfrom
feat/avm1-conversion-calls

Conversation

@AerafalDev

Copy link
Copy Markdown
Owner

For 1.8.1. Avm1Machine now evaluates calls to the built-in conversion functions String(x), Number(x) and Boolean(x). Until now, ActionCallFunction always pushed undefined.

Why: data scripts wrap literals in these calls, as in C.CHECK_MAP_FILE_ID = Boolean(true);, C.SPEAKING_ITEMS_MSG_COUNT = Number(30); and C.RSS_LINK = String("http://…");. In the Dofus Retro lang file, 88 of the 100 constants came out undefined because of this.

What changed:

  • ActionCallFunction pops the name, the argument count and the arguments. For String, Number and Boolean it pushes ToStr, ToNum or ToBool of the first argument. These are the same version-gated rules the operators use, so Number("30") is 30, Boolean(0) is false, and Boolean("0") is false before SWF 7 and true from SWF 7.
  • Extra arguments are popped and ignored. With no argument, the calls return "", 0 and undefined respectively. This matches Ruffle's string_function, number_function and boolean_function.
  • Before SWF 7 the names match case-insensitively, like every AVM1 identifier. From SWF 7 they must match exactly.
  • Any other function still evaluates to undefined. NewObject and CallMethod are unchanged.
  • Docs: avm1/machine.mdx has a new Conversion calls section and an extra line in Version-gated behavior. The scope notes in avm1/index.mdx and index.mdx now name the supported calls.

Tests: Avm1ConversionCallTests (10 tests) builds the actions in code, encodes them to DoAction bytes and runs them through Avm1Machine.Run in strict mode. The tests cover:

  • a lang-style C.X = Boolean/Number/String(…) script
  • string, number and boolean arguments
  • coercion cases: Number("30"), Number("0x1F"), Boolean(0), and Boolean("0") on SWF 6 and on SWF 7
  • calls with no argument and calls with extra arguments
  • name case before and from SWF 7
  • a call to another function, which still returns undefined

Validation: dotnet test -c Release passes 381/381 (371 existing + 10 new) with zero warnings. No changelog file is kept in the repository.

🤖 Generated with Claude Code

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.
@AerafalDev
AerafalDev merged commit 915f8f3 into main Nov 17, 2026
6 checks passed
@AerafalDev
AerafalDev deleted the feat/avm1-conversion-calls branch November 17, 2026 08:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant