aboutsummaryrefslogtreecommitdiff
path: root/src/script/lua_api/l_http.cpp
diff options
context:
space:
mode:
authorElias Fleckenstein <eliasfleckenstein@web.de>2020-07-18 13:53:15 +0200
committerElias Fleckenstein <eliasfleckenstein@web.de>2020-07-18 13:53:15 +0200
commitffe3c2ae0db6fed0f2b08b71bfa69f3d3df3bb1f (patch)
treecc7d9f74a43215c5d8e3965a2bfc2aea5867a7a0 /src/script/lua_api/l_http.cpp
parent45aa2516b2fc675df7049bc9ed713600c95b6423 (diff)
parent82731d0d3d8bfe9e56f89466991f13c037f3a61e (diff)
downloaddragonfireclient-ffe3c2ae0db6fed0f2b08b71bfa69f3d3df3bb1f.tar.xz
Update to minetest 5.4.0-dev
Diffstat (limited to 'src/script/lua_api/l_http.cpp')
-rw-r--r--src/script/lua_api/l_http.cpp51
1 files changed, 50 insertions, 1 deletions
diff --git a/src/script/lua_api/l_http.cpp b/src/script/lua_api/l_http.cpp
index 2ff651cb5..ec43bf174 100644
--- a/src/script/lua_api/l_http.cpp
+++ b/src/script/lua_api/l_http.cpp
@@ -83,6 +83,24 @@ void ModApiHttp::push_http_fetch_result(lua_State *L, HTTPFetchResult &res, bool
setstringfield(L, -1, "data", res.data);
}
+// http_api.fetch_sync(HTTPRequest definition)
+int ModApiHttp::l_http_fetch_sync(lua_State *L)
+{
+ NO_MAP_LOCK_REQUIRED;
+
+ HTTPFetchRequest req;
+ read_http_fetch_request(L, req);
+
+ infostream << "Mod performs HTTP request with URL " << req.url << std::endl;
+
+ HTTPFetchResult res;
+ httpfetch_sync(req, res);
+
+ push_http_fetch_result(L, res, true);
+
+ return 1;
+}
+
// http_api.fetch_async(HTTPRequest definition)
int ModApiHttp::l_http_fetch_async(lua_State *L)
{
@@ -180,11 +198,42 @@ int ModApiHttp::l_request_http_api(lua_State *L)
return 1;
}
+
+int ModApiHttp::l_get_http_api(lua_State *L)
+{
+ NO_MAP_LOCK_REQUIRED;
+
+ lua_newtable(L);
+ HTTP_API(fetch_async);
+ HTTP_API(fetch_async_get);
+ HTTP_API(fetch_sync);
+
+ return 1;
+}
+
#endif
void ModApiHttp::Initialize(lua_State *L, int top)
{
#if USE_CURL
- API_FCT(request_http_api);
+
+ bool isMainmenu = false;
+#ifndef SERVER
+ isMainmenu = ModApiBase::getGuiEngine(L) != nullptr;
+#endif
+
+ if (isMainmenu) {
+ API_FCT(get_http_api);
+ } else {
+ API_FCT(request_http_api);
+ }
+
+#endif
+}
+
+void ModApiHttp::InitializeAsync(lua_State *L, int top)
+{
+#if USE_CURL
+ API_FCT(get_http_api);
#endif
}