3 Copyright (C) 2020 Elias Fleckenstein <eliasfleckenstein@web.de>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation; either version 2.1 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 #include "inventorymanager.h"
21 #include "lua_api/l_base.h"
23 #define GET_MOVE_ACTION \
24 LuaInventoryAction *o = checkobject(L, 1); \
25 if (o->m_action->getType() == IAction::Craft) \
27 MoveAction *act = dynamic_cast<MoveAction *>(o->m_action);
29 class LuaInventoryAction : public ModApiBase
32 InventoryAction *m_action;
34 static void readFullInventoryLocationInto(lua_State *L, InventoryLocation *loc,
35 std::string *list, s16 *index);
37 static const char className[];
38 static const luaL_Reg methods[];
43 static int gc_object(lua_State *L);
45 // __tostring metamethod
46 static int mt_tostring(lua_State *L);
49 static int l_apply(lua_State *L);
51 // from(self, location, list, index)
52 static int l_from(lua_State *L);
54 // to(self, location, list, index)
55 static int l_to(lua_State *L);
57 // craft(self, location)
58 static int l_craft(lua_State *L);
60 // set_count(self, count)
61 static int l_set_count(lua_State *L);
64 LuaInventoryAction(const IAction &type);
65 ~LuaInventoryAction();
67 // LuaInventoryAction(inventory action type)
68 // Creates an LuaInventoryAction and leaves it on top of stack
69 static int create_object(lua_State *L);
70 // Not callable from Lua
71 static int create(lua_State *L, const IAction &type);
72 static LuaInventoryAction *checkobject(lua_State *L, int narg);
73 static void Register(lua_State *L);