diff options
Diffstat (limited to 'src/script/lua_api')
-rw-r--r-- | src/script/lua_api/l_http.cpp | 13 |
1 files changed, 5 insertions, 8 deletions
diff --git a/src/script/lua_api/l_http.cpp b/src/script/lua_api/l_http.cpp index f27f789ad..2ff651cb5 100644 --- a/src/script/lua_api/l_http.cpp +++ b/src/script/lua_api/l_http.cpp @@ -53,9 +53,8 @@ void ModApiHttp::read_http_fetch_request(lua_State *L, HTTPFetchRequest &req) lua_getfield(L, 1, "post_data"); if (lua_istable(L, 2)) { lua_pushnil(L); - while (lua_next(L, 2) != 0) - { - req.post_fields[luaL_checkstring(L, -2)] = luaL_checkstring(L, -1); + while (lua_next(L, 2) != 0) { + req.post_fields[readParam<std::string>(L, -2)] = readParam<std::string>(L, -1); lua_pop(L, 1); } } else if (lua_isstring(L, 2)) { @@ -66,10 +65,8 @@ void ModApiHttp::read_http_fetch_request(lua_State *L, HTTPFetchRequest &req) lua_getfield(L, 1, "extra_headers"); if (lua_istable(L, 2)) { lua_pushnil(L); - while (lua_next(L, 2) != 0) - { - const char *header = luaL_checkstring(L, -1); - req.extra_headers.emplace_back(header); + while (lua_next(L, 2) != 0) { + req.extra_headers.emplace_back(readParam<std::string>(L, -1)); lua_pop(L, 1); } } @@ -83,7 +80,7 @@ void ModApiHttp::push_http_fetch_result(lua_State *L, HTTPFetchResult &res, bool setboolfield(L, -1, "timeout", res.timeout); setboolfield(L, -1, "completed", completed); setintfield(L, -1, "code", res.response_code); - setstringfield(L, -1, "data", res.data.c_str()); + setstringfield(L, -1, "data", res.data); } // http_api.fetch_async(HTTPRequest definition) |