LCOV - code coverage report
Current view: top level - src/script - scripting_mainmenu.cpp (source / functions) Hit Total Coverage
Test: report Lines: 25 27 92.6 %
Date: 2015-07-11 18:23:49 Functions: 5 7 71.4 %

          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 "scripting_mainmenu.h"
      21             : #include "mods.h"
      22             : #include "porting.h"
      23             : #include "log.h"
      24             : #include "cpp_api/s_internal.h"
      25             : #include "lua_api/l_base.h"
      26             : #include "lua_api/l_mainmenu.h"
      27             : #include "lua_api/l_util.h"
      28             : #include "lua_api/l_settings.h"
      29             : 
      30             : extern "C" {
      31             : #include "lualib.h"
      32             : }
      33             : 
      34             : #define MAINMENU_NUM_ASYNC_THREADS 4
      35             : 
      36             : 
      37           1 : MainMenuScripting::MainMenuScripting(GUIEngine* guiengine)
      38             : {
      39           1 :         setGuiEngine(guiengine);
      40             : 
      41           2 :         SCRIPTAPI_PRECHECKHEADER
      42             : 
      43           1 :         lua_getglobal(L, "core");
      44           1 :         int top = lua_gettop(L);
      45             : 
      46           1 :         lua_newtable(L);
      47           1 :         lua_setglobal(L, "gamedata");
      48             : 
      49             :         // Initialize our lua_api modules
      50           1 :         initializeModApi(L, top);
      51           1 :         lua_pop(L, 1);
      52             : 
      53             :         // Push builtin initialization type
      54           1 :         lua_pushstring(L, "mainmenu");
      55           1 :         lua_setglobal(L, "INIT");
      56             : 
      57           1 :         infostream << "SCRIPTAPI: Initialized main menu modules" << std::endl;
      58           1 : }
      59             : 
      60             : /******************************************************************************/
      61           1 : void MainMenuScripting::initializeModApi(lua_State *L, int top)
      62             : {
      63             :         // Initialize mod API modules
      64           1 :         ModApiMainMenu::Initialize(L, top);
      65           1 :         ModApiUtil::Initialize(L, top);
      66             : 
      67             :         // Register reference classes (userdata)
      68           1 :         LuaSettings::Register(L);
      69             : 
      70             :         // Register functions to async environment
      71           1 :         ModApiMainMenu::InitializeAsync(asyncEngine);
      72           1 :         ModApiUtil::InitializeAsync(asyncEngine);
      73             : 
      74             :         // Initialize async environment
      75             :         //TODO possibly make number of async threads configurable
      76           1 :         asyncEngine.initialize(MAINMENU_NUM_ASYNC_THREADS);
      77           1 : }
      78             : 
      79             : /******************************************************************************/
      80          91 : void MainMenuScripting::step() {
      81          91 :         asyncEngine.step(getStack(), m_errorhandler);
      82          91 : }
      83             : 
      84             : /******************************************************************************/
      85           0 : unsigned int MainMenuScripting::queueAsync(std::string serialized_func,
      86             :                 std::string serialized_param) {
      87           0 :         return asyncEngine.queueAsyncJob(serialized_func, serialized_param);
      88           3 : }
      89             : 

Generated by: LCOV version 1.11