summaryrefslogtreecommitdiff
path: root/src/script/lua_api/l_mainmenu.cpp
diff options
context:
space:
mode:
authorsapier <Sapier at GMX dot net>2013-11-26 18:15:31 +0100
committersapier <Sapier at GMX dot net>2013-11-29 22:09:14 +0100
commit2e66aca35722e7fee786027d545fe371786fc01f (patch)
treef6d3ec721d23680bb493bd66054379b9327a1c7a /src/script/lua_api/l_mainmenu.cpp
parentb08d7558de53325d184b3ddf0476cb84fc08d0ad (diff)
downloadminetest-2e66aca35722e7fee786027d545fe371786fc01f.tar.gz
minetest-2e66aca35722e7fee786027d545fe371786fc01f.tar.bz2
minetest-2e66aca35722e7fee786027d545fe371786fc01f.zip
Fix modstore/favourites hang by adding asynchronous lua job support
Diffstat (limited to 'src/script/lua_api/l_mainmenu.cpp')
-rw-r--r--src/script/lua_api/l_mainmenu.cpp72
1 files changed, 47 insertions, 25 deletions
diff --git a/src/script/lua_api/l_mainmenu.cpp b/src/script/lua_api/l_mainmenu.cpp
index 498ac0383..42ddd0b14 100644
--- a/src/script/lua_api/l_mainmenu.cpp
+++ b/src/script/lua_api/l_mainmenu.cpp
@@ -20,6 +20,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "lua_api/l_mainmenu.h"
#include "lua_api/l_internal.h"
#include "common/c_content.h"
+#include "lua_api/l_async_events.h"
#include "guiEngine.h"
#include "guiMainMenu.h"
#include "guiKeyChangeMenu.h"
@@ -200,9 +201,6 @@ int ModApiMainMenu::l_get_textlist_index(lua_State *L)
/******************************************************************************/
int ModApiMainMenu::l_get_worlds(lua_State *L)
{
- GUIEngine* engine = getGuiEngine(L);
- assert(engine != 0);
-
std::vector<WorldSpec> worlds = getAvailableWorlds();
lua_newtable(L);
@@ -237,9 +235,6 @@ int ModApiMainMenu::l_get_worlds(lua_State *L)
/******************************************************************************/
int ModApiMainMenu::l_get_games(lua_State *L)
{
- GUIEngine* engine = getGuiEngine(L);
- assert(engine != 0);
-
std::vector<SubgameSpec> games = getAvailableGames();
lua_newtable(L);
@@ -365,9 +360,6 @@ int ModApiMainMenu::l_get_modstore_details(lua_State *L)
/******************************************************************************/
int ModApiMainMenu::l_get_modstore_list(lua_State *L)
{
- GUIEngine* engine = getGuiEngine(L);
- assert(engine != 0);
-
std::string listtype = "local";
if (!lua_isnone(L,1)) {
@@ -421,9 +413,6 @@ int ModApiMainMenu::l_get_modstore_list(lua_State *L)
/******************************************************************************/
int ModApiMainMenu::l_get_favorites(lua_State *L)
{
- GUIEngine* engine = getGuiEngine(L);
- assert(engine != 0);
-
std::string listtype = "local";
if (!lua_isnone(L,1)) {
@@ -545,9 +534,6 @@ int ModApiMainMenu::l_get_favorites(lua_State *L)
/******************************************************************************/
int ModApiMainMenu::l_delete_favorite(lua_State *L)
{
- GUIEngine* engine = getGuiEngine(L);
- assert(engine != 0);
-
std::vector<ServerListSpec> servers;
std::string listtype = "local";
@@ -599,9 +585,6 @@ int ModApiMainMenu::l_show_keys_menu(lua_State *L)
/******************************************************************************/
int ModApiMainMenu::l_create_world(lua_State *L)
{
- GUIEngine* engine = getGuiEngine(L);
- assert(engine != 0);
-
const char *name = luaL_checkstring(L, 1);
int gameidx = luaL_checkinteger(L,2) -1;
@@ -632,9 +615,6 @@ int ModApiMainMenu::l_create_world(lua_State *L)
/******************************************************************************/
int ModApiMainMenu::l_delete_world(lua_State *L)
{
- GUIEngine* engine = getGuiEngine(L);
- assert(engine != 0);
-
int worldidx = luaL_checkinteger(L,1) -1;
std::vector<WorldSpec> worlds = getAvailableWorlds();
@@ -962,9 +942,6 @@ int ModApiMainMenu::l_sound_stop(lua_State *L)
/******************************************************************************/
int ModApiMainMenu::l_download_file(lua_State *L)
{
- GUIEngine* engine = getGuiEngine(L);
- assert(engine != 0);
-
const char *url = luaL_checkstring(L, 1);
const char *target = luaL_checkstring(L, 2);
@@ -972,7 +949,7 @@ int ModApiMainMenu::l_download_file(lua_State *L)
std::string absolute_destination = fs::RemoveRelativePathComponents(target);
if (ModApiMainMenu::isMinetestPath(absolute_destination)) {
- if (engine->downloadFile(url,absolute_destination)) {
+ if (GUIEngine::downloadFile(url,absolute_destination)) {
lua_pushboolean(L,true);
return 1;
}
@@ -991,6 +968,28 @@ int ModApiMainMenu::l_gettext(lua_State *L)
}
/******************************************************************************/
+int ModApiMainMenu::l_do_async_callback(lua_State *L)
+{
+ GUIEngine* engine = getGuiEngine(L);
+
+ const char* serialized_fct_raw = luaL_checkstring(L, 1);
+ unsigned int lenght_fct = luaL_checkint(L, 2);
+
+ const char* serialized_params_raw = luaL_checkstring(L, 3);
+ unsigned int lenght_params = luaL_checkint(L, 4);
+
+ assert(serialized_fct_raw != 0);
+ assert(serialized_params_raw != 0);
+
+ std::string serialized_fct = std::string(serialized_fct_raw,lenght_fct);
+ std::string serialized_params = std::string(serialized_params_raw,lenght_params);
+
+ lua_pushinteger(L,engine->DoAsync(serialized_fct,serialized_params));
+
+ return 1;
+}
+
+/******************************************************************************/
void ModApiMainMenu::Initialize(lua_State *L, int top)
{
API_FCT(update_formspec);
@@ -1024,4 +1023,27 @@ void ModApiMainMenu::Initialize(lua_State *L, int top)
API_FCT(sound_play);
API_FCT(sound_stop);
API_FCT(gettext);
+ API_FCT(do_async_callback);
+}
+
+/******************************************************************************/
+void ModApiMainMenu::InitializeAsync(AsyncEngine& engine)
+{
+
+ ASYNC_API_FCT(get_worlds);
+ ASYNC_API_FCT(get_games);
+ ASYNC_API_FCT(get_favorites);
+ ASYNC_API_FCT(get_modpath);
+ ASYNC_API_FCT(get_gamepath);
+ ASYNC_API_FCT(get_texturepath);
+ ASYNC_API_FCT(get_dirlist);
+ ASYNC_API_FCT(create_dir);
+ ASYNC_API_FCT(delete_dir);
+ ASYNC_API_FCT(copy_dir);
+ //ASYNC_API_FCT(extract_zip); //TODO remove dependency to GuiEngine
+ ASYNC_API_FCT(get_version);
+ ASYNC_API_FCT(download_file);
+ ASYNC_API_FCT(get_modstore_details);
+ ASYNC_API_FCT(get_modstore_list);
+ //ASYNC_API_FCT(gettext); (gettext lib isn't threadsafe)
}