mirror of
https://github.com/The-Powder-Toy/The-Powder-Toy.git
synced 2025-09-01 20:12:50 +02:00
split http.request into http.get and http.post (for api reasons)
It's cleaner together, but it's not a good api.
This commit is contained in:
@@ -3819,10 +3819,12 @@ static int http_request_finish(lua_State *l)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int http_request(lua_State *l)
|
static int http_request(lua_State *l, bool isPost)
|
||||||
{
|
{
|
||||||
ByteString uri(luaL_checkstring(l, 1));
|
ByteString uri(luaL_checkstring(l, 1));
|
||||||
std::map<ByteString, ByteString> post_data;
|
std::map<ByteString, ByteString> post_data;
|
||||||
|
if (isPost)
|
||||||
|
{
|
||||||
if (lua_istable(l, 2))
|
if (lua_istable(l, 2))
|
||||||
{
|
{
|
||||||
lua_pushnil(l);
|
lua_pushnil(l);
|
||||||
@@ -3833,11 +3835,13 @@ static int http_request(lua_State *l)
|
|||||||
lua_pop(l, 2);
|
lua_pop(l, 2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
std::map<ByteString, ByteString> headers;
|
std::map<ByteString, ByteString> headers;
|
||||||
if (lua_istable(l, 3))
|
if (lua_istable(l, isPost ? 3 : 2))
|
||||||
{
|
{
|
||||||
lua_pushnil(l);
|
lua_pushnil(l);
|
||||||
while (lua_next(l, 3))
|
while (lua_next(l, isPost ? 3 : 2))
|
||||||
{
|
{
|
||||||
lua_pushvalue(l, -2);
|
lua_pushvalue(l, -2);
|
||||||
headers.emplace(lua_tostring(l, -1), lua_tostring(l, -2));
|
headers.emplace(lua_tostring(l, -1), lua_tostring(l, -2));
|
||||||
@@ -3855,6 +3859,17 @@ static int http_request(lua_State *l)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int LuaScriptInterface::http_get(lua_State * l)
|
||||||
|
{
|
||||||
|
return http_request(l, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
int LuaScriptInterface::http_post(lua_State * l)
|
||||||
|
{
|
||||||
|
return http_request(l, true);
|
||||||
|
}
|
||||||
|
|
||||||
void LuaScriptInterface::initHttpAPI()
|
void LuaScriptInterface::initHttpAPI()
|
||||||
{
|
{
|
||||||
luaL_newmetatable(l, "HTTPRequest");
|
luaL_newmetatable(l, "HTTPRequest");
|
||||||
@@ -3871,7 +3886,8 @@ void LuaScriptInterface::initHttpAPI()
|
|||||||
lua_setfield(l, -2, "finish");
|
lua_setfield(l, -2, "finish");
|
||||||
lua_setfield(l, -2, "__index");
|
lua_setfield(l, -2, "__index");
|
||||||
struct luaL_Reg httpAPIMethods [] = {
|
struct luaL_Reg httpAPIMethods [] = {
|
||||||
{"request", http_request},
|
{"get", http_get},
|
||||||
|
{"post", http_post},
|
||||||
{NULL, NULL}
|
{NULL, NULL}
|
||||||
};
|
};
|
||||||
luaL_register(l, "http", httpAPIMethods);
|
luaL_register(l, "http", httpAPIMethods);
|
||||||
|
@@ -181,6 +181,8 @@ class LuaScriptInterface: public CommandInterface
|
|||||||
static int event_getmodifiers(lua_State * l);
|
static int event_getmodifiers(lua_State * l);
|
||||||
|
|
||||||
void initHttpAPI();
|
void initHttpAPI();
|
||||||
|
static int http_get(lua_State * l);
|
||||||
|
static int http_post(lua_State * l);
|
||||||
|
|
||||||
std::vector<LuaSmartRef> lua_el_func_v, lua_gr_func_v, lua_cd_func_v;
|
std::vector<LuaSmartRef> lua_el_func_v, lua_gr_func_v, lua_cd_func_v;
|
||||||
std::vector<int> lua_el_mode_v;
|
std::vector<int> lua_el_mode_v;
|
||||||
|
Reference in New Issue
Block a user