diff options
Diffstat (limited to 'src/scripting/luascript.cpp')
-rw-r--r-- | src/scripting/luascript.cpp | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/src/scripting/luascript.cpp b/src/scripting/luascript.cpp index a9c43b72..dc6230ca 100644 --- a/src/scripting/luascript.cpp +++ b/src/scripting/luascript.cpp @@ -21,6 +21,9 @@ #include "luascript.h" + +#include "scripting/luautil.h" + #include "game-server/being.h" #include "utils/logger.h" @@ -61,6 +64,30 @@ void LuaScript::push(Thing *v) ++nbArgs; } +void LuaScript::push(const std::list<InventoryItem> &itemList) +{ + assert(nbArgs >= 0); + int position = 0; + + lua_createtable(mState, itemList.size(), 0); + int itemTable = lua_gettop(mState); + + for (std::list<InventoryItem>::const_iterator i = itemList.begin(); + i != itemList.end(); + i++) + { + // create the item structure + std::map<std::string, int> item; + item["id"] = i->itemId; + item["amount"] = i->amount; + // add the item structure to the item table under the next index + lua_pushinteger(mState, ++position); + pushSTLContainer<std::string, int>(mState, item); + lua_settable(mState, itemTable); + } + ++nbArgs; +} + int LuaScript::execute() { assert(nbArgs >= 0); @@ -182,3 +209,14 @@ bool LuaScript::loadSpecialActionsScript(const std::string &file) } return true; } + +bool LuaScript::loadCraftScript(const std::string &file) +{ + Script::craftScript = new LuaScript(); + if (!Script::craftScript->loadFile(file)) + { + Script::craftScript = NULL; + return false; + } + return true; +} |