end
itemdef.name = name
- -- default short_description to first line of description
- itemdef.short_description = itemdef.short_description or
- (itemdef.description or ""):gsub("\n.*","")
-
-- Apply defaults and add to registered_* table
if itemdef.type == "node" then
-- Use the nodebox as selection box if it's not set manually
stack).
* `set_metadata(metadata)`: (DEPRECATED) Returns true.
* `get_description()`: returns the description shown in inventory list tooltips.
- * The engine uses the same as this function for item descriptions.
+ * The engine uses this when showing item descriptions in tooltips.
* Fields for finding the description, in order:
* `description` in item metadata (See [Item Metadata].)
* `description` in item definition
* item name
-* `get_short_description()`: returns the short description.
+* `get_short_description()`: returns the short description or nil.
* Unlike the description, this does not include new lines.
- * The engine uses the same as this function for short item descriptions.
* Fields for finding the short description, in order:
* `short_description` in item metadata (See [Item Metadata].)
* `short_description` in item definition
- * first line of the description (See `get_description()`.)
+ * first line of the description (From item meta or def, see `get_description()`.)
+ * Returns nil if none of the above are set
* `clear()`: removes all items from the stack, making it empty.
* `replace(item)`: replace the contents of this stack.
* `item` can also be an itemstring or table.
short_description = "Steel Axe",
-- Must not contain new lines.
- -- Defaults to the first line of description.
- -- See also: `get_short_description` in [`ItemStack`]
+ -- Defaults to nil.
+ -- Use an [`ItemStack`] to get the short description, eg:
+ -- ItemStack(itemname):get_short_description()
groups = {},
-- key = name, value = rating; rating = 1..3.
})
function unittests.test_short_desc()
+ local function get_short_description(item)
+ return ItemStack(item):get_short_description()
+ end
+
local stack = ItemStack("unittests:colorful_pick")
assert(stack:get_short_description() == "Colorful Pickaxe")
- assert(stack:get_short_description() == minetest.registered_items["unittests:colorful_pick"].short_description)
+ assert(get_short_description("unittests:colorful_pick") == "Colorful Pickaxe")
+ assert(minetest.registered_items["unittests:colorful_pick"].short_description == nil)
assert(stack:get_description() == full_description)
assert(stack:get_description() == minetest.registered_items["unittests:colorful_pick"].description)
stack:get_meta():set_string("description", "Hello World")
- assert(stack:get_short_description() == "Colorful Pickaxe")
+ assert(stack:get_short_description() == "Hello World")
assert(stack:get_description() == "Hello World")
+ assert(get_short_description(stack) == "Hello World")
+ assert(get_short_description("unittests:colorful_pick") == "Colorful Pickaxe")
stack:get_meta():set_string("short_description", "Foo Bar")
assert(stack:get_short_description() == "Foo Bar")
lua_setfield(L, -2, "name");
lua_pushstring(L, i.description.c_str());
lua_setfield(L, -2, "description");
- lua_pushstring(L, i.short_description.c_str());
- lua_setfield(L, -2, "short_description");
+ if (!i.short_description.empty()) {
+ lua_pushstring(L, i.short_description.c_str());
+ lua_setfield(L, -2, "short_description");
+ }
lua_pushstring(L, type.c_str());
lua_setfield(L, -2, "type");
lua_pushstring(L, i.inventory_image.c_str());