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

Inconsistent data types in Itemstack #4947

Closed
forsakenquantum opened this issue Dec 21, 2016 · 6 comments · Fixed by #12685
Closed

Inconsistent data types in Itemstack #4947

forsakenquantum opened this issue Dec 21, 2016 · 6 comments · Fixed by #12685
Labels
Bug Issues that were confirmed to be a bug @ Script API

Comments

@forsakenquantum
Copy link

The awards mod has a register_on_craft which receives an itemstack object. In general, it appears that type(itemstack)=="userdata", however, in some cases it looks like type(itemstack)=="table". Specifically, if I make a mese pickaxe and add a couple of cavorite handles, as long as the mese pickaxe has never been used, then type(itemstack)=="userdata" and when the awards mod calls itemstack:get_name(), everything is fine. But if the mese pickaxe has been used, then type(itemstack)=="table" and trying to call itemstack:get_name() crashes the server.

I can work around this by detecting when type(itemstack)=="table" and then callling itemstack["name"] to get the name instead of itemstack:get_name(), but I feel like this isn't optimal

@TeTpaAka
Copy link
Contributor

This is intended (see http:https://dev.minetest.net/ItemStack). You could also use a string as an itemstack.
If you want to have a consistent interface, you can always call
ItemStack(itemstack or itemstring or table or nil)
to get a userdata object.

@paramat
Copy link
Contributor

paramat commented Dec 22, 2016

Perhaps we should avoid a crash for this situation?

@paramat paramat added the Bug Issues that were confirmed to be a bug label Dec 22, 2016
@stujones11
Copy link
Contributor

stujones11 commented Dec 25, 2016

Perhaps we should avoid a crash for this situation?

I am not sure how that would be possible, calling a method on a string or a table will obviously cause a crash. I think the documentation is fairly clear about this and the reason why ItemStack() is provided by the api.

@rubenwardy
Copy link
Member

If the parameter is called itemstack then it should always give an object that conforms to ItemStack. It's misleading otherwise

@stujones11
Copy link
Contributor

stujones11 commented Dec 25, 2016

Yeah, I have misread the issue, register_on_craft should be made to consistently provide a valid userdata type object. Maybe register_on_craft is not the only callback guilty of this?

@SmallJoker
Copy link
Member

SmallJoker commented Feb 18, 2017

bump
@fermionic, I check all enabled mods that use minetest.register_on_craft. Most likely this error is caused by one of these. They return string or tables (since it's a valid stack, by definition), but these values do not get converted to the userdata ItemStack anywhere, that's why calling functions such as :get_wear() fail.
A fix for this would be to manually convert the returned value to an ItemStack in builtin/game/register.lua

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Issues that were confirmed to be a bug @ Script API
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants