LCOV - code coverage report
Current view: top level - src/script/cpp_api - s_mainmenu.cpp (source / functions) Hit Total Coverage
Test: report Lines: 17 41 41.5 %
Date: 2015-07-11 18:23:49 Functions: 3 5 60.0 %

          Line data    Source code
       1             : /*
       2             : Minetest
       3             : Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
       4             : 
       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.
       9             : 
      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.
      14             : 
      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.
      18             : */
      19             : 
      20             : #include "cpp_api/s_mainmenu.h"
      21             : #include "cpp_api/s_internal.h"
      22             : #include "common/c_converter.h"
      23             : 
      24           0 : void ScriptApiMainMenu::setMainMenuErrorMessage(std::string errormessage)
      25             : {
      26           0 :         SCRIPTAPI_PRECHECKHEADER
      27             : 
      28           0 :         lua_getglobal(L, "gamedata");
      29           0 :         int gamedata_idx = lua_gettop(L);
      30           0 :         lua_pushstring(L, "errormessage");
      31           0 :         lua_pushstring(L, errormessage.c_str());
      32           0 :         lua_settable(L, gamedata_idx);
      33           0 :         lua_pop(L, 1);
      34           0 : }
      35             : 
      36           0 : void ScriptApiMainMenu::handleMainMenuEvent(std::string text)
      37             : {
      38           0 :         SCRIPTAPI_PRECHECKHEADER
      39             : 
      40             :         // Get handler function
      41           0 :         lua_getglobal(L, "core");
      42           0 :         lua_getfield(L, -1, "event_handler");
      43           0 :         lua_remove(L, -2); // Remove core
      44           0 :         if (lua_isnil(L, -1)) {
      45           0 :                 lua_pop(L, 1); // Pop event_handler
      46           0 :                 return;
      47             :         }
      48           0 :         luaL_checktype(L, -1, LUA_TFUNCTION);
      49             : 
      50             :         // Call it
      51           0 :         lua_pushstring(L, text.c_str());
      52           0 :         if (lua_pcall(L, 1, 0, m_errorhandler))
      53           0 :                 scriptError();
      54             : }
      55             : 
      56           3 : void ScriptApiMainMenu::handleMainMenuButtons(const StringMap &fields)
      57             : {
      58           6 :         SCRIPTAPI_PRECHECKHEADER
      59             : 
      60             :         // Get handler function
      61           3 :         lua_getglobal(L, "core");
      62           3 :         lua_getfield(L, -1, "button_handler");
      63           3 :         lua_remove(L, -2); // Remove core
      64           3 :         if (lua_isnil(L, -1)) {
      65           0 :                 lua_pop(L, 1); // Pop button handler
      66           0 :                 return;
      67             :         }
      68           3 :         luaL_checktype(L, -1, LUA_TFUNCTION);
      69             : 
      70             :         // Convert fields to a Lua table
      71           3 :         lua_newtable(L);
      72           3 :         StringMap::const_iterator it;
      73          18 :         for (it = fields.begin(); it != fields.end(); ++it) {
      74          15 :                 const std::string &name = it->first;
      75          15 :                 const std::string &value = it->second;
      76          15 :                 lua_pushstring(L, name.c_str());
      77          15 :                 lua_pushlstring(L, value.c_str(), value.size());
      78          15 :                 lua_settable(L, -3);
      79             :         }
      80             : 
      81             :         // Call it
      82           3 :         if (lua_pcall(L, 1, 0, m_errorhandler))
      83           0 :                 scriptError();
      84           3 : }
      85             : 

Generated by: LCOV version 1.11