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

Possible order of operation bug in Luacore #1045

Open
amadeus1171 opened this issue Jun 20, 2019 · 5 comments
Open

Possible order of operation bug in Luacore #1045

amadeus1171 opened this issue Jun 20, 2019 · 5 comments

Comments

@amadeus1171
Copy link

Consider if (heal_party and party_needs_healing()) then.

heal_party is always true.
party_needs_healing() returns true or false depending on whether or not the party needs healing.

However, (heal_party and party_needs_healing()) always returns true.

But (heal_party and ((party_needs_healing()))) returns the correct true or false when force order of operation using parentheses around party_needs_healing().

@joshk6656
Copy link
Member

joshk6656 commented Jun 20, 2019 via email

@z16
Copy link
Member

z16 commented Jun 20, 2019

That is pretty much impossible. If anything that would be a bug in Lua itself, since LuaCore doesn't do any of its own parsing. Also, () does not make it evaluate first, nor should it. () only has two purposes, first it groups an expression together, so precedence of other operators is ignored. Second, it narrows multiple values into one. Both of which should be irrelevant here, your two expressions should behave exactly the same.

Also, even if it was not evaluated first it should still be evaluated. From a semantic perspective the order of operations is irrelevant if the first value is true. Only if the first value is false the second value should be skipped (regardless of parentheses).

I cannot stress how unlikely it is that there's something wrong here. I would really go with printing. You can keep your current structure if you do this:

local check = function(value)
    print(value)
    return value
end

if check(heal_party) and check(party_needs_healing()) then
    -- stuff
end

Now it will print the first and second value (unless the first is false in which case it should ignore the second..

If you're still convinced that there's an error on our end try to create a minimal working example of code that we can run directly to observe the error directly.

@amadeus1171
Copy link
Author

Looks like I have to make a video. I'll post it in a bit.

@z16
Copy link
Member

z16 commented Jun 21, 2019

I would really much prefer if you either tried to narrow down the erroneous code into a minimal working sample or ran the code I posted and reported the results. Videos have rarely helped me understand a problem. But if you think it'll help, I can take a look.

@amadeus1171
Copy link
Author

amadeus1171 commented Jun 25, 2019

This is so weird. This code worked properly.

_addon.name = 'Test'
_addon.author = 'Me'
_addon.version = '1'
_addon.commands = {'test'}

function testme()
	local retVal = false
	
	return retVal
end

windower.register_event('addon command', function(...)
	local args = {...}
	local cmd = ''
	
	if true and testme() then
		windower.add_to_chat(5, "testme was evaluated and not testme() return value")
	else
		windower.add_to_chat(5, "testme was not evaluated and testme() returned false")
	end
end)

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

No branches or pull requests

3 participants