More work refactoring ckint/tryint/isint
This commit is contained in:
@@ -623,59 +623,66 @@ void HttpClientRequest::set_content(const eng::string &content) {
|
||||
}
|
||||
|
||||
void HttpClientRequest::set_verify_certificate(LuaCoreStack &LS, LuaSlot val) {
|
||||
if (!LS.isboolean(val)) {
|
||||
auto tval = LS.tryboolean(val);
|
||||
if (!tval) {
|
||||
check_fail(util::ss("verifycertificate must be a boolean"));
|
||||
return;
|
||||
}
|
||||
set_verify_certificate(LS.ckboolean(val));
|
||||
set_verify_certificate(*tval);
|
||||
}
|
||||
|
||||
void HttpClientRequest::set_method(LuaCoreStack &LS, LuaSlot val) {
|
||||
if (!LS.isstring(val)) {
|
||||
auto tval = LS.trystring(val);
|
||||
if (!tval) {
|
||||
check_fail(util::ss("method must be a string"));
|
||||
return;
|
||||
}
|
||||
set_method(LS.ckstring(val));
|
||||
set_method(*tval);
|
||||
}
|
||||
|
||||
void HttpClientRequest::set_host(LuaCoreStack &LS, LuaSlot val) {
|
||||
if (!LS.isstring(val)) {
|
||||
auto tval = LS.trystring(val);
|
||||
if (!tval) {
|
||||
check_fail(util::ss("host must be a string"));
|
||||
return;
|
||||
}
|
||||
set_host(LS.ckstring(val));
|
||||
set_host(*tval);
|
||||
}
|
||||
|
||||
void HttpClientRequest::set_port(LuaCoreStack &LS, LuaSlot val) {
|
||||
if (!LS.isint(val)) {
|
||||
auto tval = LS.tryint(val);
|
||||
if (!tval) {
|
||||
check_fail(util::ss("port must be an int"));
|
||||
return;
|
||||
}
|
||||
set_port(LS.ckint(val));
|
||||
set_port(*tval);
|
||||
}
|
||||
|
||||
void HttpClientRequest::set_path(LuaCoreStack &LS, LuaSlot val) {
|
||||
if (!LS.isstring(val)) {
|
||||
auto tval = LS.trystring(val);
|
||||
if (!tval) {
|
||||
check_fail(util::ss("path must be a string"));
|
||||
return;
|
||||
}
|
||||
set_path(LS.ckstring(val));
|
||||
set_path(*tval);
|
||||
}
|
||||
|
||||
void HttpClientRequest::set_param(LuaCoreStack &LS, LuaSlot key, LuaSlot val) {
|
||||
if (!LS.isstring(key)) {
|
||||
auto tkey = LS.trystring(key);
|
||||
auto tval = LS.trystring(val);
|
||||
if (!tkey) {
|
||||
check_fail(util::ss("url parameter key must be a string"));
|
||||
return;
|
||||
}
|
||||
if (!LS.isstring(val)) {
|
||||
if (!tval) {
|
||||
check_fail(util::ss("url parameter val must be a string"));
|
||||
return;
|
||||
}
|
||||
set_param(LS.ckstring(key), LS.ckstring(val));
|
||||
set_param(*tkey, *tval);
|
||||
}
|
||||
|
||||
void HttpClientRequest::set_params(LuaCoreStack &LS0, LuaSlot tab) {
|
||||
if (!LS0.istable(tab)) {
|
||||
if (!LS0.trytable(tab)) {
|
||||
check_fail(util::ss("params must be a table"));
|
||||
return;
|
||||
}
|
||||
@@ -688,27 +695,30 @@ void HttpClientRequest::set_params(LuaCoreStack &LS0, LuaSlot tab) {
|
||||
}
|
||||
|
||||
void HttpClientRequest::set_url(LuaCoreStack &LS, LuaSlot val) {
|
||||
if (!LS.isstring(val)) {
|
||||
auto tval = LS.trystring(val);
|
||||
if (!tval) {
|
||||
check_fail(util::ss("url must be a string"));
|
||||
return;
|
||||
}
|
||||
set_url(LS.ckstring(val));
|
||||
set_url(*tval);
|
||||
}
|
||||
|
||||
void HttpClientRequest::set_mime_type(LuaCoreStack &LS, LuaSlot val) {
|
||||
if (!LS.isstring(val)) {
|
||||
auto tval = LS.trystring(val);
|
||||
if (!tval) {
|
||||
check_fail(util::ss("mime type must be a string"));
|
||||
return;
|
||||
}
|
||||
set_mime_type(LS.ckstring(val));
|
||||
set_mime_type(*tval);
|
||||
}
|
||||
|
||||
void HttpClientRequest::set_content(LuaCoreStack &LS, LuaSlot val) {
|
||||
if (!LS.isstring(val)) {
|
||||
auto tval = LS.trystring(val);
|
||||
if (!tval) {
|
||||
check_fail(util::ss("content must be a string"));
|
||||
return;
|
||||
}
|
||||
set_content(LS.ckstring(val));
|
||||
set_content(*tval);
|
||||
}
|
||||
|
||||
void HttpClientRequest::set_jsonvalue(LuaCoreStack &LS, LuaSlot val) {
|
||||
@@ -976,15 +986,16 @@ void HttpServerResponse::set_content(const eng::string &content) {
|
||||
|
||||
void HttpServerResponse::set_status(LuaCoreStack &LS, LuaSlot val) {
|
||||
int status = 0;
|
||||
if (LS.isstring(val)) {
|
||||
eng::string s = LS.ckstring(val);
|
||||
status = status_code_from_string(s);
|
||||
auto vstring = LS.trystring(val);
|
||||
auto vint = LS.tryint(val);
|
||||
if (vstring) {
|
||||
status = status_code_from_string(*vstring);
|
||||
if (status == 0) {
|
||||
check_fail(util::ss("unrecognized status code: ", s));
|
||||
check_fail(util::ss("unrecognized status code: ", *vstring));
|
||||
return;
|
||||
}
|
||||
} else if (LS.isint(val)) {
|
||||
status = LS.ckint(val);
|
||||
} else if (vint) {
|
||||
status = *vint;
|
||||
} else {
|
||||
check_fail(util::ss("status must be an integer"));
|
||||
return;
|
||||
@@ -993,27 +1004,30 @@ void HttpServerResponse::set_status(LuaCoreStack &LS, LuaSlot val) {
|
||||
}
|
||||
|
||||
void HttpServerResponse::set_max_age(LuaCoreStack &LS, LuaSlot val) {
|
||||
if (!LS.isint(val)) {
|
||||
auto vint = LS.tryint(val);
|
||||
if (!vint) {
|
||||
check_fail(util::ss("max-age must be an int"));
|
||||
return;
|
||||
}
|
||||
set_max_age(LS.ckint(val));
|
||||
set_max_age(*vint);
|
||||
}
|
||||
|
||||
void HttpServerResponse::set_mime_type(LuaCoreStack &LS, LuaSlot val) {
|
||||
if (!LS.isstring(val)) {
|
||||
auto vstring = LS.trystring(val);
|
||||
if (!vstring) {
|
||||
check_fail(util::ss("mime type must be a string"));
|
||||
return;
|
||||
}
|
||||
set_mime_type(LS.ckstring(val));
|
||||
set_mime_type(*vstring);
|
||||
}
|
||||
|
||||
void HttpServerResponse::set_content(LuaCoreStack &LS, LuaSlot val) {
|
||||
if (!LS.isstring(val)) {
|
||||
auto vstring = LS.trystring(val);
|
||||
if (!vstring) {
|
||||
check_fail(util::ss("content must be a string"));
|
||||
return;
|
||||
}
|
||||
set_content(LS.ckstring(val));
|
||||
set_content(*vstring);
|
||||
}
|
||||
|
||||
void HttpServerResponse::set_jsonvalue(LuaCoreStack &LS, LuaSlot val) {
|
||||
|
||||
Reference in New Issue
Block a user