Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix image constructor argument handling #1479

Closed

Conversation

out-of-phaze
Copy link
Contributor

Before, it would always set icon_state to the corresponding argument even if icon_state was set by loc. Now, it properly skips it.

Copy link
Member

@wixoaGit wixoaGit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Playing around with argument skipping in /image's constructor won't work.

When named arguments are used, the VM places the named arguments in their positional order. Once you're in the constructor you have no way of knowing if positional arguments were used and you have to skip an arg, or if named arguments were used and skipping an arg will result in incorrect values.

image('icon.dmi', "state", FLOAT_LAYER, EAST)
gives you the args 0='icon.dmi' 1="state" 2=FLOAT_LAYER 3=EAST 4..6=null

image('icon.dmi', "state", layer=FLOAT_LAYER, dir=EAST)
gives you 0='icon.dmi' 1="state" 2=null 3=FLOAT_LAYER 4=EAST 5..6=null

Both of them have a string in the second spot. However, the first one skips an arg but the second does not.

This will probably have to be special-cased in the VM. That or extra type-guessing that I don't think BYOND does.

argIndex = 2;
if (!loc.TryGetValueAsDreamObject(out _loc)) { // If it's not a DreamObject, it's actually icon_state and not loc
startIndex = 1;
if (!loc.IsNull) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

loc.IsNull will always be false here because TryGetValueAsDreamObject() will return true for a null object.

if (loc.TryGetValueAsDreamObject(out _loc)) { // If it's not a DreamObject, it's actually icon_state and not loc
argIndex = 2;
if (!loc.TryGetValueAsDreamObject(out _loc)) { // If it's not a DreamObject, it's actually icon_state and not loc
startIndex = 1;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This ends up skipping the 3rd argument

@wixoaGit
Copy link
Member

Closing in favor of #1627

@wixoaGit wixoaGit closed this Jan 19, 2024
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.

2 participants