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 ObjectRef crashes due to lua_isnil() #10564

Merged
merged 12 commits into from
Nov 4, 2020
Merged

Conversation

Zughy
Copy link
Member

@Zughy Zughy commented Oct 26, 2020

So, according to Lua, when a value is not specified is not nil, but no value. And they're not the same. This should fix it

To do

This PR is Ready for Review.

How to test

Spawn an armorball and it shouldn't crash anymore

@Zughy Zughy changed the title TNONE Fix ObjectRef crashes due to lua_isnil() Oct 26, 2020
@sfan5 sfan5 added the Maintenance Tasks to keep the codebase and related parts in order, including architectural improvements label Oct 27, 2020
@sfan5
Copy link
Member

sfan5 commented Oct 27, 2020

I'd been meaning to ask this on the cleanup PR but it got merged before I got around. Oh well.

@sfan5 sfan5 added the Bugfix 🐛 PRs that fix a bug label Oct 27, 2020
Copy link
Member

@sfan5 sfan5 left a comment

Choose a reason for hiding this comment

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

Looks good.

@rubenwardy
Copy link
Member

Shouldn't all of the checks be isnoneornil?

@Zughy
Copy link
Member Author

Zughy commented Oct 27, 2020

Shouldn't all of the checks be isnoneornil?

Idk, for some functions is kind of silly to declare them like function(something, nil, nil nil), so I avoided that. But if it's a problem, I'll change it. Also, a few lua_isnone could be completely removed if readParam<float>(L, idx) supported a third parameter acting as default, like <bool> and strings do

@Desour
Copy link
Member

Desour commented Oct 27, 2020

Imho, none and nil shouldn't be distinguishable to modders, like it is for normal lua functions.

You could add the missing readParam functions with default values. (It might be less work to just implement the generic function using the generic no-default-value readParam.)

@rubenwardy
Copy link
Member

rubenwardy commented Oct 27, 2020

Yeah, makes sense to remove the boolean and int/float specialisations with default values, and instead use:

template <typename T>
inline T readParam(lua_State *L, int index, const T &default_value)
{
	return lua_isnoneornil(L, index) ? default_value : readParam<T>(L, index);
}

@Zughy
Copy link
Member Author

Zughy commented Oct 27, 2020

Ruben suggestion addressed. Also, I've added a couple more readParam: int and v3f, I hope it's fine

src/script/lua_api/l_object.cpp Outdated Show resolved Hide resolved
src/script/lua_api/l_object.cpp Outdated Show resolved Hide resolved
src/script/common/helper.cpp Show resolved Hide resolved
@numberZero
Copy link
Contributor

LGTM

@numberZero
Copy link
Contributor

btw note that v2f is spelled three times on this line (others are similar):
v2f frame_range = readParam<v2f>(L, 2, v2f(1, 1));
whether that is good is style question (NB: I’m not asking to change anything, I don’t govern the style) but two of these are redundant:
auto frame_range = readParam<v2f>(L, 2, {1, 1}); and
auto frame_range = readParam(L, 2, v2f(1, 1)); are both valid

@SmallJoker SmallJoker merged commit 72b93ec into minetest:master Nov 4, 2020
HybridDog pushed a commit to HybridDog/minetest that referenced this pull request Dec 17, 2020
@Zughy Zughy deleted the tnone branch January 2, 2021 15:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bugfix 🐛 PRs that fix a bug Maintenance Tasks to keep the codebase and related parts in order, including architectural improvements >= Two approvals ✅ ✅
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants