2013-08-11 04:09:45 +02:00
|
|
|
/*
|
|
|
|
Minetest
|
|
|
|
Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2.1 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU Lesser General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public License along
|
|
|
|
with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "scripting_mainmenu.h"
|
|
|
|
#include "log.h"
|
|
|
|
#include "filesys.h"
|
|
|
|
#include "cpp_api/s_internal.h"
|
|
|
|
#include "lua_api/l_base.h"
|
|
|
|
#include "lua_api/l_mainmenu.h"
|
|
|
|
#include "lua_api/l_util.h"
|
2013-09-09 22:50:25 +02:00
|
|
|
#include "lua_api/l_settings.h"
|
2013-08-11 04:09:45 +02:00
|
|
|
|
|
|
|
extern "C" {
|
|
|
|
#include "lualib.h"
|
|
|
|
}
|
2014-04-15 19:41:07 +02:00
|
|
|
|
2014-04-15 21:10:30 +02:00
|
|
|
#define MAINMENU_NUM_ASYNC_THREADS 4
|
2014-04-15 19:41:07 +02:00
|
|
|
|
|
|
|
|
2013-08-11 04:09:45 +02:00
|
|
|
MainMenuScripting::MainMenuScripting(GUIEngine* guiengine)
|
|
|
|
{
|
|
|
|
setGuiEngine(guiengine);
|
|
|
|
|
|
|
|
//TODO add security
|
|
|
|
|
|
|
|
luaL_openlibs(getStack());
|
|
|
|
|
|
|
|
SCRIPTAPI_PRECHECKHEADER
|
|
|
|
|
2014-04-15 19:41:07 +02:00
|
|
|
lua_newtable(L);
|
|
|
|
lua_setglobal(L, "engine");
|
|
|
|
lua_getglobal(L, "engine");
|
|
|
|
int top = lua_gettop(L);
|
|
|
|
|
2013-08-11 04:09:45 +02:00
|
|
|
lua_pushstring(L, DIR_DELIM);
|
|
|
|
lua_setglobal(L, "DIR_DELIM");
|
|
|
|
|
|
|
|
lua_newtable(L);
|
|
|
|
lua_setglobal(L, "gamedata");
|
|
|
|
|
|
|
|
// Initialize our lua_api modules
|
2014-04-15 21:10:30 +02:00
|
|
|
initializeModApi(L, top);
|
2013-08-11 04:09:45 +02:00
|
|
|
lua_pop(L, 1);
|
|
|
|
|
2014-04-15 19:41:07 +02:00
|
|
|
infostream << "SCRIPTAPI: Initialized main menu modules" << std::endl;
|
2013-08-11 04:09:45 +02:00
|
|
|
}
|
|
|
|
|
2013-11-26 18:15:31 +01:00
|
|
|
/******************************************************************************/
|
2014-04-15 21:10:30 +02:00
|
|
|
void MainMenuScripting::initializeModApi(lua_State *L, int top)
|
2013-08-11 04:09:45 +02:00
|
|
|
{
|
2014-04-15 19:41:07 +02:00
|
|
|
// Initialize mod API modules
|
2013-08-11 04:09:45 +02:00
|
|
|
ModApiMainMenu::Initialize(L, top);
|
|
|
|
ModApiUtil::Initialize(L, top);
|
2013-09-09 22:50:25 +02:00
|
|
|
|
|
|
|
// Register reference classes (userdata)
|
|
|
|
LuaSettings::Register(L);
|
2013-11-26 18:15:31 +01:00
|
|
|
|
|
|
|
// Register functions to async environment
|
2014-04-15 21:10:30 +02:00
|
|
|
ModApiMainMenu::InitializeAsync(asyncEngine);
|
|
|
|
ModApiUtil::InitializeAsync(asyncEngine);
|
2013-11-26 18:15:31 +01:00
|
|
|
|
|
|
|
// Initialize async environment
|
|
|
|
//TODO possibly make number of async threads configurable
|
2014-04-15 21:10:30 +02:00
|
|
|
asyncEngine.initialize(MAINMENU_NUM_ASYNC_THREADS);
|
2013-11-26 18:15:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************/
|
2014-04-15 21:10:30 +02:00
|
|
|
void MainMenuScripting::step() {
|
|
|
|
asyncEngine.step(getStack(), m_errorhandler);
|
2013-11-26 18:15:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************/
|
2014-04-15 21:10:30 +02:00
|
|
|
unsigned int MainMenuScripting::queueAsync(std::string serialized_func,
|
2014-04-15 19:41:07 +02:00
|
|
|
std::string serialized_param) {
|
2014-04-15 21:10:30 +02:00
|
|
|
return asyncEngine.queueAsyncJob(serialized_func, serialized_param);
|
2013-08-11 04:09:45 +02:00
|
|
|
}
|
2014-04-15 19:41:07 +02:00
|
|
|
|