HTTP stuff now uses keyword parser.
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
#include <climits>
|
||||
#include "wrap-string.hpp"
|
||||
#include "wrap-set.hpp"
|
||||
#include "wrap-sstream.hpp"
|
||||
|
||||
LuaSpecial LuaRegistry(LUA_REGISTRYINDEX);
|
||||
LuaNilMarker LuaNil;
|
||||
@@ -468,8 +469,10 @@ void LuaStack::setvisited(LuaSlot tab, bool visited) const {
|
||||
LuaKeywordParser::LuaKeywordParser(lua_State *L, int slot) {
|
||||
L_ = L;
|
||||
slot_ = slot;
|
||||
if (!lua_istable(L_, slot_)) {
|
||||
luaL_error(L_, "expected an argument which is a table full of keywords");
|
||||
not_table_ = !lua_istable(L_, slot_);
|
||||
if (not_table_) {
|
||||
lua_newtable(L_);
|
||||
lua_replace(L_, slot_);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -485,20 +488,32 @@ bool LuaKeywordParser::parse(LuaSlot out, const char *kw) {
|
||||
}
|
||||
};
|
||||
|
||||
void LuaKeywordParser::check_unparsed_keywords() {
|
||||
eng::string LuaKeywordParser::final_check() {
|
||||
if (not_table_) {
|
||||
return "expected a keyword table";
|
||||
}
|
||||
if (lua_nkeys(L_, slot_) != int(parsed_.size())) {
|
||||
lua_pushnil(L_);
|
||||
while (lua_next(L_, slot_) != 0) {
|
||||
lua_pop(L_, 1); // Don't need the value.
|
||||
if (!lua_isstring(L_, -1)) {
|
||||
luaL_error(L_, "keyword table contains non-string key");
|
||||
return "keyword table contains non-string key";
|
||||
}
|
||||
const char *kw = lua_tostring(L_, -1);
|
||||
if (parsed_.find(kw) == parsed_.end()) {
|
||||
luaL_error(L_, "keyword %s not known", kw);
|
||||
eng::ostringstream oss;
|
||||
oss << "keyword " << kw << " not known";
|
||||
return oss.str();
|
||||
}
|
||||
}
|
||||
assert(false && "should never get here in check_unparsed_keywords");
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
void LuaKeywordParser::final_check_throw() {
|
||||
eng::string err = final_check();
|
||||
if (!err.empty()) {
|
||||
luaL_error(L_, "%s", err.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user