Added two new stack disciplines to LuaStack
This commit is contained in:
@@ -625,7 +625,7 @@ void HttpClientRequest::set_content(const eng::string &content) {
|
||||
content_assigned_ = true;
|
||||
}
|
||||
|
||||
void HttpClientRequest::set_verify_certificate(LuaStack &LS, LuaSlot val) {
|
||||
void HttpClientRequest::set_verify_certificate(LuaCoreStack &LS, LuaSlot val) {
|
||||
if (!LS.isboolean(val)) {
|
||||
check_fail(util::ss("verifycertificate must be a boolean"));
|
||||
return;
|
||||
@@ -633,7 +633,7 @@ void HttpClientRequest::set_verify_certificate(LuaStack &LS, LuaSlot val) {
|
||||
set_verify_certificate(LS.ckboolean(val));
|
||||
}
|
||||
|
||||
void HttpClientRequest::set_method(LuaStack &LS, LuaSlot val) {
|
||||
void HttpClientRequest::set_method(LuaCoreStack &LS, LuaSlot val) {
|
||||
if (!LS.isstring(val)) {
|
||||
check_fail(util::ss("method must be a string"));
|
||||
return;
|
||||
@@ -641,7 +641,7 @@ void HttpClientRequest::set_method(LuaStack &LS, LuaSlot val) {
|
||||
set_method(LS.ckstring(val));
|
||||
}
|
||||
|
||||
void HttpClientRequest::set_host(LuaStack &LS, LuaSlot val) {
|
||||
void HttpClientRequest::set_host(LuaCoreStack &LS, LuaSlot val) {
|
||||
if (!LS.isstring(val)) {
|
||||
check_fail(util::ss("host must be a string"));
|
||||
return;
|
||||
@@ -649,7 +649,7 @@ void HttpClientRequest::set_host(LuaStack &LS, LuaSlot val) {
|
||||
set_host(LS.ckstring(val));
|
||||
}
|
||||
|
||||
void HttpClientRequest::set_port(LuaStack &LS, LuaSlot val) {
|
||||
void HttpClientRequest::set_port(LuaCoreStack &LS, LuaSlot val) {
|
||||
if (!LS.isint(val)) {
|
||||
check_fail(util::ss("port must be an int"));
|
||||
return;
|
||||
@@ -657,7 +657,7 @@ void HttpClientRequest::set_port(LuaStack &LS, LuaSlot val) {
|
||||
set_port(LS.ckint(val));
|
||||
}
|
||||
|
||||
void HttpClientRequest::set_path(LuaStack &LS, LuaSlot val) {
|
||||
void HttpClientRequest::set_path(LuaCoreStack &LS, LuaSlot val) {
|
||||
if (!LS.isstring(val)) {
|
||||
check_fail(util::ss("path must be a string"));
|
||||
return;
|
||||
@@ -665,7 +665,7 @@ void HttpClientRequest::set_path(LuaStack &LS, LuaSlot val) {
|
||||
set_path(LS.ckstring(val));
|
||||
}
|
||||
|
||||
void HttpClientRequest::set_param(LuaStack &LS, LuaSlot key, LuaSlot val) {
|
||||
void HttpClientRequest::set_param(LuaCoreStack &LS, LuaSlot key, LuaSlot val) {
|
||||
if (!LS.isstring(key)) {
|
||||
check_fail(util::ss("url parameter key must be a string"));
|
||||
return;
|
||||
@@ -677,20 +677,20 @@ void HttpClientRequest::set_param(LuaStack &LS, LuaSlot key, LuaSlot val) {
|
||||
set_param(LS.ckstring(key), LS.ckstring(val));
|
||||
}
|
||||
|
||||
void HttpClientRequest::set_params(LuaStack &LS0, LuaSlot tab) {
|
||||
void HttpClientRequest::set_params(LuaCoreStack &LS0, LuaSlot tab) {
|
||||
if (!LS0.istable(tab)) {
|
||||
check_fail(util::ss("params must be a table"));
|
||||
return;
|
||||
}
|
||||
LuaVar key, val;
|
||||
LuaStack LS(LS0.state(), key, val);
|
||||
LuaOldStack LS(LS0.state(), key, val);
|
||||
LS.set(key, LuaNil);
|
||||
while (LS.next(tab, key, val)) {
|
||||
set_param(LS, key, val);
|
||||
}
|
||||
}
|
||||
|
||||
void HttpClientRequest::set_url(LuaStack &LS, LuaSlot val) {
|
||||
void HttpClientRequest::set_url(LuaCoreStack &LS, LuaSlot val) {
|
||||
if (!LS.isstring(val)) {
|
||||
check_fail(util::ss("url must be a string"));
|
||||
return;
|
||||
@@ -698,7 +698,7 @@ void HttpClientRequest::set_url(LuaStack &LS, LuaSlot val) {
|
||||
set_url(LS.ckstring(val));
|
||||
}
|
||||
|
||||
void HttpClientRequest::set_mime_type(LuaStack &LS, LuaSlot val) {
|
||||
void HttpClientRequest::set_mime_type(LuaCoreStack &LS, LuaSlot val) {
|
||||
if (!LS.isstring(val)) {
|
||||
check_fail(util::ss("mime type must be a string"));
|
||||
return;
|
||||
@@ -706,7 +706,7 @@ void HttpClientRequest::set_mime_type(LuaStack &LS, LuaSlot val) {
|
||||
set_mime_type(LS.ckstring(val));
|
||||
}
|
||||
|
||||
void HttpClientRequest::set_content(LuaStack &LS, LuaSlot val) {
|
||||
void HttpClientRequest::set_content(LuaCoreStack &LS, LuaSlot val) {
|
||||
if (!LS.isstring(val)) {
|
||||
check_fail(util::ss("content must be a string"));
|
||||
return;
|
||||
@@ -714,7 +714,7 @@ void HttpClientRequest::set_content(LuaStack &LS, LuaSlot val) {
|
||||
set_content(LS.ckstring(val));
|
||||
}
|
||||
|
||||
void HttpClientRequest::set_jsonvalue(LuaStack &LS, LuaSlot val) {
|
||||
void HttpClientRequest::set_jsonvalue(LuaCoreStack &LS, LuaSlot val) {
|
||||
eng::string out;
|
||||
eng::string err = json::encode(LS, val, out, false, HttpParser::MAX_CONTENT_LENGTH);
|
||||
if (!err.empty()) {
|
||||
@@ -736,7 +736,7 @@ void HttpClientRequest::set_defaults() {
|
||||
|
||||
void HttpClientRequest::configure(LuaKeywordParser &kp) {
|
||||
LuaVar val;
|
||||
LuaStack LS(kp.state(), val);
|
||||
LuaOldStack LS(kp.state(), val);
|
||||
if (kp.parse(val, "method")) {
|
||||
set_method(LS, val);
|
||||
}
|
||||
@@ -977,7 +977,7 @@ void HttpServerResponse::set_content(const eng::string &content) {
|
||||
content_assigned_ = true;
|
||||
}
|
||||
|
||||
void HttpServerResponse::set_status(LuaStack &LS, LuaSlot val) {
|
||||
void HttpServerResponse::set_status(LuaCoreStack &LS, LuaSlot val) {
|
||||
int status = 0;
|
||||
if (LS.isstring(val)) {
|
||||
eng::string s = LS.ckstring(val);
|
||||
@@ -995,7 +995,7 @@ void HttpServerResponse::set_status(LuaStack &LS, LuaSlot val) {
|
||||
set_status(status);
|
||||
}
|
||||
|
||||
void HttpServerResponse::set_max_age(LuaStack &LS, LuaSlot val) {
|
||||
void HttpServerResponse::set_max_age(LuaCoreStack &LS, LuaSlot val) {
|
||||
if (!LS.isint(val)) {
|
||||
check_fail(util::ss("max-age must be an int"));
|
||||
return;
|
||||
@@ -1003,7 +1003,7 @@ void HttpServerResponse::set_max_age(LuaStack &LS, LuaSlot val) {
|
||||
set_max_age(LS.ckint(val));
|
||||
}
|
||||
|
||||
void HttpServerResponse::set_mime_type(LuaStack &LS, LuaSlot val) {
|
||||
void HttpServerResponse::set_mime_type(LuaCoreStack &LS, LuaSlot val) {
|
||||
if (!LS.isstring(val)) {
|
||||
check_fail(util::ss("mime type must be a string"));
|
||||
return;
|
||||
@@ -1011,7 +1011,7 @@ void HttpServerResponse::set_mime_type(LuaStack &LS, LuaSlot val) {
|
||||
set_mime_type(LS.ckstring(val));
|
||||
}
|
||||
|
||||
void HttpServerResponse::set_content(LuaStack &LS, LuaSlot val) {
|
||||
void HttpServerResponse::set_content(LuaCoreStack &LS, LuaSlot val) {
|
||||
if (!LS.isstring(val)) {
|
||||
check_fail(util::ss("content must be a string"));
|
||||
return;
|
||||
@@ -1019,7 +1019,7 @@ void HttpServerResponse::set_content(LuaStack &LS, LuaSlot val) {
|
||||
set_content(LS.ckstring(val));
|
||||
}
|
||||
|
||||
void HttpServerResponse::set_jsonvalue(LuaStack &LS, LuaSlot val) {
|
||||
void HttpServerResponse::set_jsonvalue(LuaCoreStack &LS, LuaSlot val) {
|
||||
eng::string out;
|
||||
eng::string err = json::encode(LS, val, out, false, HttpParser::MAX_CONTENT_LENGTH);
|
||||
if (!err.empty()) {
|
||||
@@ -1032,7 +1032,7 @@ void HttpServerResponse::set_jsonvalue(LuaStack &LS, LuaSlot val) {
|
||||
|
||||
void HttpServerResponse::configure(LuaKeywordParser &kp) {
|
||||
LuaVar val;
|
||||
LuaStack LS(kp.state(), val);
|
||||
LuaOldStack LS(kp.state(), val);
|
||||
if (kp.parse(val, "status")) {
|
||||
set_status(LS, val);
|
||||
}
|
||||
@@ -1468,9 +1468,9 @@ bool HttpParser::parse_content(std::string_view &view, bool closed) {
|
||||
return true;
|
||||
}
|
||||
|
||||
void HttpParser::store(LuaStack &LS0, LuaSlot tab) const {
|
||||
void HttpParser::store(LuaCoreStack &LS0, LuaSlot tab) const {
|
||||
LuaVar ptab, djson;
|
||||
LuaStack LS(LS0.state(), ptab, djson);
|
||||
LuaOldStack LS(LS0.state(), ptab, djson);
|
||||
|
||||
LS.newtable(tab);
|
||||
if (!is_request_) {
|
||||
@@ -1633,7 +1633,7 @@ void HttpParser::parse_request(std::string_view view, bool closed) {
|
||||
if (status_ == 0) status_ = 200;
|
||||
}
|
||||
|
||||
void HttpParser::store_fail(LuaStack &LS, LuaSlot tab, int status_code, std::string_view error) {
|
||||
void HttpParser::store_fail(LuaCoreStack &LS, LuaSlot tab, int status_code, std::string_view error) {
|
||||
HttpParser parser;
|
||||
parser.fail(status_code, error);
|
||||
parser.store(LS, tab);
|
||||
@@ -1659,7 +1659,7 @@ void HttpClientRequestMap::deserialize(StreamBuffer *sb) {
|
||||
LuaDefine(http_fixurl, "url", "validate URL and repair minor flaws in the URL syntax") {
|
||||
LuaArg url;
|
||||
LuaRet fixed;
|
||||
LuaStack LS(L, url, fixed);
|
||||
LuaOldStack LS(L, url, fixed);
|
||||
ParsedURL parsed(LS.ckstring(url));
|
||||
if (!parsed.valid) {
|
||||
luaL_error(L, "invalid URL, not fixable");
|
||||
@@ -1715,7 +1715,7 @@ LuaDefine(http_clientrequest, "request",
|
||||
"|that would be sent.") {
|
||||
LuaArg tab;
|
||||
LuaRet str;
|
||||
LuaStack LS(L, tab, str);
|
||||
LuaOldStack LS(L, tab, str);
|
||||
LuaKeywordParser kp(LS, tab);
|
||||
HttpClientRequest req;
|
||||
req.configure(kp);
|
||||
@@ -1774,7 +1774,7 @@ LuaDefine(http_clientresponse, "response",
|
||||
"|an actual HTTP response string. This is for debugging only.") {
|
||||
LuaArg text;
|
||||
LuaRet tab;
|
||||
LuaStack LS(L, text, tab);
|
||||
LuaOldStack LS(L, text, tab);
|
||||
HttpParser parser;
|
||||
parser.parse_response(LS.ckstring(text), true, "GET");
|
||||
parser.store(LS, tab);
|
||||
@@ -1829,7 +1829,7 @@ LuaDefine(http_serverrequest, "request",
|
||||
"|an actual HTTP request string. This is for debugging only.") {
|
||||
LuaArg text;
|
||||
LuaRet tab;
|
||||
LuaStack LS(L, text, tab);
|
||||
LuaOldStack LS(L, text, tab);
|
||||
HttpParser parser;
|
||||
parser.parse_request(LS.ckstring(text), true);
|
||||
parser.store(LS, tab);
|
||||
@@ -1887,7 +1887,7 @@ LuaDefine(http_serverresponse, "response",
|
||||
"|that would be sent.") {
|
||||
LuaArg tab;
|
||||
LuaRet str;
|
||||
LuaStack LS(L, tab, str);
|
||||
LuaOldStack LS(L, tab, str);
|
||||
LuaKeywordParser kp(LS, tab);
|
||||
HttpServerResponse resp;
|
||||
resp.configure(kp);
|
||||
@@ -1901,7 +1901,7 @@ LuaDefine(http_serverresponse, "response",
|
||||
LuaDefine(http_validmime, "(mt)", "") {
|
||||
LuaArg str;
|
||||
LuaRet ok;
|
||||
LuaStack LS(L, str, ok);
|
||||
LuaOldStack LS(L, str, ok);
|
||||
LS.set(ok, valid_mime_type(LS.ckstring(str)));
|
||||
return LS.result();
|
||||
}
|
||||
@@ -1909,7 +1909,7 @@ LuaDefine(http_validmime, "(mt)", "") {
|
||||
LuaDefine(http_statusstring, "(statuscode)", "Convert a 3-digit status code to a string") {
|
||||
LuaArg code;
|
||||
LuaRet str;
|
||||
LuaStack LS(L, code, str);
|
||||
LuaOldStack LS(L, code, str);
|
||||
int icode = LS.ckint(code);
|
||||
LS.set(str, status_code_to_string(icode));
|
||||
return LS.result();
|
||||
@@ -1918,7 +1918,7 @@ LuaDefine(http_statusstring, "(statuscode)", "Convert a 3-digit status code to a
|
||||
LuaDefine(http_statuscode, "(statusstring)", "Convert a string to a 3-digit status code") {
|
||||
LuaArg str;
|
||||
LuaRet code;
|
||||
LuaStack LS(L, code, str);
|
||||
LuaOldStack LS(L, code, str);
|
||||
eng::string sstr = LS.ckstring(str);
|
||||
LS.set(code, status_code_from_string(sstr));
|
||||
int iresult = LS.result();
|
||||
|
||||
Reference in New Issue
Block a user