1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-08-01 17:38:41 +00:00

Replace Optional with std::optional

This commit is contained in:
Desour 2023-06-11 22:55:36 +02:00 committed by sfan5
parent 34ad551efc
commit e700182f44
15 changed files with 39 additions and 198 deletions

View file

@ -337,7 +337,7 @@ void read_object_properties(lua_State *L, int index,
if (read_color(L, -1, &color))
prop->nametag_bgcolor = color;
} else {
prop->nametag_bgcolor = nullopt;
prop->nametag_bgcolor = std::nullopt;
}
}
lua_pop(L, 1);

View file

@ -59,7 +59,7 @@ bool ScriptApiItem::item_OnDrop(ItemStack &item,
return true;
}
bool ScriptApiItem::item_OnPlace(Optional<ItemStack> &ret_item,
bool ScriptApiItem::item_OnPlace(std::optional<ItemStack> &ret_item,
ServerActiveObject *placer, const PointedThing &pointed)
{
SCRIPTAPI_PRECHECKHEADER
@ -88,13 +88,13 @@ bool ScriptApiItem::item_OnPlace(Optional<ItemStack> &ret_item,
throw WRAP_LUAERROR(e, "item=" + item.name);
}
} else {
ret_item = nullopt;
ret_item = std::nullopt;
}
lua_pop(L, 2); // Pop item and error handler
return true;
}
bool ScriptApiItem::item_OnUse(Optional<ItemStack> &ret_item,
bool ScriptApiItem::item_OnUse(std::optional<ItemStack> &ret_item,
ServerActiveObject *user, const PointedThing &pointed)
{
SCRIPTAPI_PRECHECKHEADER
@ -118,13 +118,13 @@ bool ScriptApiItem::item_OnUse(Optional<ItemStack> &ret_item,
throw WRAP_LUAERROR(e, "item=" + item.name);
}
} else {
ret_item = nullopt;
ret_item = std::nullopt;
}
lua_pop(L, 2); // Pop item and error handler
return true;
}
bool ScriptApiItem::item_OnSecondaryUse(Optional<ItemStack> &ret_item,
bool ScriptApiItem::item_OnSecondaryUse(std::optional<ItemStack> &ret_item,
ServerActiveObject *user, const PointedThing &pointed)
{
SCRIPTAPI_PRECHECKHEADER
@ -146,7 +146,7 @@ bool ScriptApiItem::item_OnSecondaryUse(Optional<ItemStack> &ret_item,
throw WRAP_LUAERROR(e, "item=" + item.name);
}
} else {
ret_item = nullopt;
ret_item = std::nullopt;
}
lua_pop(L, 2); // Pop item and error handler
return true;

View file

@ -21,7 +21,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "cpp_api/s_base.h"
#include "irr_v3d.h"
#include "util/Optional.h"
#include <optional>
struct PointedThing;
struct ItemStack;
@ -37,7 +37,7 @@ class ScriptApiItem
{
public:
/*
* Functions with Optional<ItemStack> are for callbacks where Lua may
* Functions with std::optional<ItemStack> are for callbacks where Lua may
* want to prevent the engine from modifying the inventory after it's done.
* This has a longer backstory where on_use may need to empty the player's
* inventory without the engine interfering (see issue #6546).
@ -45,11 +45,11 @@ public:
bool item_OnDrop(ItemStack &item,
ServerActiveObject *dropper, v3f pos);
bool item_OnPlace(Optional<ItemStack> &item,
bool item_OnPlace(std::optional<ItemStack> &item,
ServerActiveObject *placer, const PointedThing &pointed);
bool item_OnUse(Optional<ItemStack> &item,
bool item_OnUse(std::optional<ItemStack> &item,
ServerActiveObject *user, const PointedThing &pointed);
bool item_OnSecondaryUse(Optional<ItemStack> &item,
bool item_OnSecondaryUse(std::optional<ItemStack> &item,
ServerActiveObject *user, const PointedThing &pointed);
bool item_OnCraft(ItemStack &item, ServerActiveObject *user,
const InventoryList *old_craft_grid, const InventoryLocation &craft_inv);

View file

@ -446,7 +446,7 @@ int ModApiEnvMod::l_place_node(lua_State *L)
return 1;
}
// Create item to place
Optional<ItemStack> item = ItemStack(ndef->get(n).name, 1, 0, idef);
std::optional<ItemStack> item = ItemStack(ndef->get(n).name, 1, 0, idef);
// Make pointed position
PointedThing pointed;
pointed.type = POINTEDTHING_NODE;

View file

@ -716,7 +716,7 @@ int ObjectRef::l_set_nametag_attributes(lua_State *L)
if (read_color(L, -1, &color))
prop->nametag_bgcolor = color;
} else {
prop->nametag_bgcolor = nullopt;
prop->nametag_bgcolor = std::nullopt;
}
}
lua_pop(L, 1);