Start refactoring LuaStack
This commit is contained in:
@@ -171,7 +171,7 @@ void AnimStep::config_store_number(lua_State *L, int idx, float *target, float o
|
|||||||
void AnimStep::configure(LuaKeywordParser &kp, const AnimStep &aqback) {
|
void AnimStep::configure(LuaKeywordParser &kp, const AnimStep &aqback) {
|
||||||
lua_State *L = kp.state();
|
lua_State *L = kp.state();
|
||||||
LuaVar value;
|
LuaVar value;
|
||||||
LuaOldStack LS(L, value);
|
LuaExtStack LS(L, value);
|
||||||
|
|
||||||
if (kp.parse(value, "action")) {
|
if (kp.parse(value, "action")) {
|
||||||
config_store_string(L, value.index(), &action_, 0, "action");
|
config_store_string(L, value.index(), &action_, 0, "action");
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ eng::string Gui::menu_debug_string() const {
|
|||||||
LuaDefine(gui_menu_item, "action,label", "add a menu item to the current gui") {
|
LuaDefine(gui_menu_item, "action,label", "add a menu item to the current gui") {
|
||||||
Gui *gui = Gui::fetch_global_pointer(L);
|
Gui *gui = Gui::fetch_global_pointer(L);
|
||||||
LuaArg laction, llabel;
|
LuaArg laction, llabel;
|
||||||
LuaOldStack LS(L, laction, llabel);
|
LuaDefStack LS(L, laction, llabel);
|
||||||
eng::string action = LS.ckstring(laction);
|
eng::string action = LS.ckstring(laction);
|
||||||
eng::string label = LS.ckstring(llabel);
|
eng::string label = LS.ckstring(llabel);
|
||||||
if (!sv::has_prefix(action, "cb_")) {
|
if (!sv::has_prefix(action, "cb_")) {
|
||||||
|
|||||||
@@ -683,7 +683,7 @@ void HttpClientRequest::set_params(LuaCoreStack &LS0, LuaSlot tab) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
LuaVar key, val;
|
LuaVar key, val;
|
||||||
LuaOldStack LS(LS0.state(), key, val);
|
LuaDefStack LS(LS0.state(), key, val);
|
||||||
LS.set(key, LuaNil);
|
LS.set(key, LuaNil);
|
||||||
while (LS.next(tab, key, val)) {
|
while (LS.next(tab, key, val)) {
|
||||||
set_param(LS, key, val);
|
set_param(LS, key, val);
|
||||||
@@ -736,7 +736,7 @@ void HttpClientRequest::set_defaults() {
|
|||||||
|
|
||||||
void HttpClientRequest::configure(LuaKeywordParser &kp) {
|
void HttpClientRequest::configure(LuaKeywordParser &kp) {
|
||||||
LuaVar val;
|
LuaVar val;
|
||||||
LuaOldStack LS(kp.state(), val);
|
LuaExtStack LS(kp.state(), val);
|
||||||
if (kp.parse(val, "method")) {
|
if (kp.parse(val, "method")) {
|
||||||
set_method(LS, val);
|
set_method(LS, val);
|
||||||
}
|
}
|
||||||
@@ -1032,7 +1032,7 @@ void HttpServerResponse::set_jsonvalue(LuaCoreStack &LS, LuaSlot val) {
|
|||||||
|
|
||||||
void HttpServerResponse::configure(LuaKeywordParser &kp) {
|
void HttpServerResponse::configure(LuaKeywordParser &kp) {
|
||||||
LuaVar val;
|
LuaVar val;
|
||||||
LuaOldStack LS(kp.state(), val);
|
LuaExtStack LS(kp.state(), val);
|
||||||
if (kp.parse(val, "status")) {
|
if (kp.parse(val, "status")) {
|
||||||
set_status(LS, val);
|
set_status(LS, val);
|
||||||
}
|
}
|
||||||
@@ -1470,7 +1470,7 @@ bool HttpParser::parse_content(std::string_view &view, bool closed) {
|
|||||||
|
|
||||||
void HttpParser::store(LuaCoreStack &LS0, LuaSlot tab) const {
|
void HttpParser::store(LuaCoreStack &LS0, LuaSlot tab) const {
|
||||||
LuaVar ptab, djson;
|
LuaVar ptab, djson;
|
||||||
LuaOldStack LS(LS0.state(), ptab, djson);
|
LuaExtStack LS(LS0.state(), ptab, djson);
|
||||||
|
|
||||||
LS.newtable(tab);
|
LS.newtable(tab);
|
||||||
if (!is_request_) {
|
if (!is_request_) {
|
||||||
@@ -1659,7 +1659,7 @@ void HttpClientRequestMap::deserialize(StreamBuffer *sb) {
|
|||||||
LuaDefine(http_fixurl, "url", "validate URL and repair minor flaws in the URL syntax") {
|
LuaDefine(http_fixurl, "url", "validate URL and repair minor flaws in the URL syntax") {
|
||||||
LuaArg url;
|
LuaArg url;
|
||||||
LuaRet fixed;
|
LuaRet fixed;
|
||||||
LuaOldStack LS(L, url, fixed);
|
LuaDefStack LS(L, url, fixed);
|
||||||
ParsedURL parsed(LS.ckstring(url));
|
ParsedURL parsed(LS.ckstring(url));
|
||||||
if (!parsed.valid) {
|
if (!parsed.valid) {
|
||||||
luaL_error(L, "invalid URL, not fixable");
|
luaL_error(L, "invalid URL, not fixable");
|
||||||
@@ -1715,7 +1715,7 @@ LuaDefine(http_clientrequest, "request",
|
|||||||
"|that would be sent.") {
|
"|that would be sent.") {
|
||||||
LuaArg tab;
|
LuaArg tab;
|
||||||
LuaRet str;
|
LuaRet str;
|
||||||
LuaOldStack LS(L, tab, str);
|
LuaDefStack LS(L, tab, str);
|
||||||
LuaKeywordParser kp(LS, tab);
|
LuaKeywordParser kp(LS, tab);
|
||||||
HttpClientRequest req;
|
HttpClientRequest req;
|
||||||
req.configure(kp);
|
req.configure(kp);
|
||||||
@@ -1774,7 +1774,7 @@ LuaDefine(http_clientresponse, "response",
|
|||||||
"|an actual HTTP response string. This is for debugging only.") {
|
"|an actual HTTP response string. This is for debugging only.") {
|
||||||
LuaArg text;
|
LuaArg text;
|
||||||
LuaRet tab;
|
LuaRet tab;
|
||||||
LuaOldStack LS(L, text, tab);
|
LuaDefStack LS(L, text, tab);
|
||||||
HttpParser parser;
|
HttpParser parser;
|
||||||
parser.parse_response(LS.ckstring(text), true, "GET");
|
parser.parse_response(LS.ckstring(text), true, "GET");
|
||||||
parser.store(LS, tab);
|
parser.store(LS, tab);
|
||||||
@@ -1829,7 +1829,7 @@ LuaDefine(http_serverrequest, "request",
|
|||||||
"|an actual HTTP request string. This is for debugging only.") {
|
"|an actual HTTP request string. This is for debugging only.") {
|
||||||
LuaArg text;
|
LuaArg text;
|
||||||
LuaRet tab;
|
LuaRet tab;
|
||||||
LuaOldStack LS(L, text, tab);
|
LuaDefStack LS(L, text, tab);
|
||||||
HttpParser parser;
|
HttpParser parser;
|
||||||
parser.parse_request(LS.ckstring(text), true);
|
parser.parse_request(LS.ckstring(text), true);
|
||||||
parser.store(LS, tab);
|
parser.store(LS, tab);
|
||||||
@@ -1887,7 +1887,7 @@ LuaDefine(http_serverresponse, "response",
|
|||||||
"|that would be sent.") {
|
"|that would be sent.") {
|
||||||
LuaArg tab;
|
LuaArg tab;
|
||||||
LuaRet str;
|
LuaRet str;
|
||||||
LuaOldStack LS(L, tab, str);
|
LuaDefStack LS(L, tab, str);
|
||||||
LuaKeywordParser kp(LS, tab);
|
LuaKeywordParser kp(LS, tab);
|
||||||
HttpServerResponse resp;
|
HttpServerResponse resp;
|
||||||
resp.configure(kp);
|
resp.configure(kp);
|
||||||
@@ -1901,7 +1901,7 @@ LuaDefine(http_serverresponse, "response",
|
|||||||
LuaDefine(http_validmime, "(mt)", "") {
|
LuaDefine(http_validmime, "(mt)", "") {
|
||||||
LuaArg str;
|
LuaArg str;
|
||||||
LuaRet ok;
|
LuaRet ok;
|
||||||
LuaOldStack LS(L, str, ok);
|
LuaDefStack LS(L, str, ok);
|
||||||
LS.set(ok, valid_mime_type(LS.ckstring(str)));
|
LS.set(ok, valid_mime_type(LS.ckstring(str)));
|
||||||
return LS.result();
|
return LS.result();
|
||||||
}
|
}
|
||||||
@@ -1909,7 +1909,7 @@ LuaDefine(http_validmime, "(mt)", "") {
|
|||||||
LuaDefine(http_statusstring, "(statuscode)", "Convert a 3-digit status code to a string") {
|
LuaDefine(http_statusstring, "(statuscode)", "Convert a 3-digit status code to a string") {
|
||||||
LuaArg code;
|
LuaArg code;
|
||||||
LuaRet str;
|
LuaRet str;
|
||||||
LuaOldStack LS(L, code, str);
|
LuaDefStack LS(L, code, str);
|
||||||
int icode = LS.ckint(code);
|
int icode = LS.ckint(code);
|
||||||
LS.set(str, status_code_to_string(icode));
|
LS.set(str, status_code_to_string(icode));
|
||||||
return LS.result();
|
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") {
|
LuaDefine(http_statuscode, "(statusstring)", "Convert a string to a 3-digit status code") {
|
||||||
LuaArg str;
|
LuaArg str;
|
||||||
LuaRet code;
|
LuaRet code;
|
||||||
LuaOldStack LS(L, code, str);
|
LuaDefStack LS(L, code, str);
|
||||||
eng::string sstr = LS.ckstring(str);
|
eng::string sstr = LS.ckstring(str);
|
||||||
LS.set(code, status_code_from_string(sstr));
|
LS.set(code, status_code_from_string(sstr));
|
||||||
int iresult = LS.result();
|
int iresult = LS.result();
|
||||||
|
|||||||
@@ -311,7 +311,7 @@ static bool decode_number(lua_State *L, std::string_view &v) {
|
|||||||
// is OK.
|
// is OK.
|
||||||
if (sv::valid_number(n, true, true, false, false)) {
|
if (sv::valid_number(n, true, true, false, false)) {
|
||||||
int64_t i = sv::to_int64(n);
|
int64_t i = sv::to_int64(n);
|
||||||
if (!LuaOldStack::int64_storable(i)) return false;
|
if (!LuaCoreStack::int64_storable(i)) return false;
|
||||||
lua_pushnumber(L, double(i));
|
lua_pushnumber(L, double(i));
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
@@ -361,7 +361,7 @@ static bool decode_int_string(lua_State *L, std::string_view &v) {
|
|||||||
// Make sure the number fits in a lua double,
|
// Make sure the number fits in a lua double,
|
||||||
// and push it on the stack.
|
// and push it on the stack.
|
||||||
int64_t i = sv::to_int64(n);
|
int64_t i = sv::to_int64(n);
|
||||||
if (!LuaOldStack::int64_storable(i)) {
|
if (!LuaCoreStack::int64_storable(i)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
lua_pushnumber(L, double(i));
|
lua_pushnumber(L, double(i));
|
||||||
@@ -661,7 +661,7 @@ LuaDefine(json_encode, "data, indent, maxlen",
|
|||||||
"|") {
|
"|") {
|
||||||
LuaArg data, indent, maxlen;
|
LuaArg data, indent, maxlen;
|
||||||
LuaRet encoded;
|
LuaRet encoded;
|
||||||
LuaOldStack LS(L, data, indent, maxlen, encoded);
|
LuaDefStack LS(L, data, indent, maxlen, encoded);
|
||||||
eng::string out;
|
eng::string out;
|
||||||
eng::string error = json::encode(LS, data, out, LS.ckboolean(indent), LS.ckint(maxlen));
|
eng::string error = json::encode(LS, data, out, LS.ckboolean(indent), LS.ckint(maxlen));
|
||||||
if (!error.empty()) {
|
if (!error.empty()) {
|
||||||
@@ -695,7 +695,7 @@ LuaDefine(json_decode, "data",
|
|||||||
"|") {
|
"|") {
|
||||||
LuaArg encoded;
|
LuaArg encoded;
|
||||||
LuaRet data;
|
LuaRet data;
|
||||||
LuaOldStack LS(L, encoded, data);
|
LuaDefStack LS(L, encoded, data);
|
||||||
std::string_view v = LS.ckstringview(encoded);
|
std::string_view v = LS.ckstringview(encoded);
|
||||||
bool ok = json::decode(LS, data, v);
|
bool ok = json::decode(LS, data, v);
|
||||||
if (!ok) {
|
if (!ok) {
|
||||||
@@ -707,7 +707,7 @@ LuaDefine(json_decode, "data",
|
|||||||
// LuaDefine(base64_encode, "data", "") {
|
// LuaDefine(base64_encode, "data", "") {
|
||||||
// LuaArg str;
|
// LuaArg str;
|
||||||
// LuaRet ret;
|
// LuaRet ret;
|
||||||
// LuaOldStack LS(L, str, ret);
|
// LuaDefStack LS(L, str, ret);
|
||||||
// eng::string cstr = LS.ckstring(str);
|
// eng::string cstr = LS.ckstring(str);
|
||||||
// eng::ostringstream oss;
|
// eng::ostringstream oss;
|
||||||
// util::base64_encode(cstr, &oss);
|
// util::base64_encode(cstr, &oss);
|
||||||
@@ -718,7 +718,7 @@ LuaDefine(json_decode, "data",
|
|||||||
// LuaDefine(base64_decode, "data", "") {
|
// LuaDefine(base64_decode, "data", "") {
|
||||||
// LuaArg str;
|
// LuaArg str;
|
||||||
// LuaRet ret;
|
// LuaRet ret;
|
||||||
// LuaOldStack LS(L, str, ret);
|
// LuaDefStack LS(L, str, ret);
|
||||||
// eng::string cstr = LS.ckstring(str);
|
// eng::string cstr = LS.ckstring(str);
|
||||||
// eng::ostringstream oss;
|
// eng::ostringstream oss;
|
||||||
// util::base64_decode(cstr, &oss);
|
// util::base64_decode(cstr, &oss);
|
||||||
|
|||||||
@@ -181,6 +181,7 @@ public:
|
|||||||
|
|
||||||
friend class LuaCoreStack;
|
friend class LuaCoreStack;
|
||||||
friend class LuaOldStack;
|
friend class LuaOldStack;
|
||||||
|
friend class LuaDefStack;
|
||||||
friend class LuaExtStack;
|
friend class LuaExtStack;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -275,6 +276,8 @@ class LuaCoreStack : public eng::nevernew {
|
|||||||
protected:
|
protected:
|
||||||
lua_State *L_;
|
lua_State *L_;
|
||||||
|
|
||||||
|
LuaCoreStack(lua_State *L) : L_(L) {}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// Push any value on the stack, by type.
|
// Push any value on the stack, by type.
|
||||||
void push_any_value(LuaNewTableMarker s) const { lua_newtable(L_); }
|
void push_any_value(LuaNewTableMarker s) const { lua_newtable(L_); }
|
||||||
@@ -549,8 +552,7 @@ private:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
template<class... SS>
|
template<class... SS>
|
||||||
LuaOldStack(lua_State *L, SS & ... stackslots) {
|
LuaOldStack(lua_State *L, SS & ... stackslots) : LuaCoreStack(L) {
|
||||||
L_ = L;
|
|
||||||
count_slots<0, 0, 0>(stackslots...);
|
count_slots<0, 0, 0>(stackslots...);
|
||||||
if (lua_gettop(L) < narg_) {
|
if (lua_gettop(L) < narg_) {
|
||||||
luaL_error(L, "not enough arguments to function");
|
luaL_error(L, "not enough arguments to function");
|
||||||
@@ -624,8 +626,7 @@ private:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
template<class... SS>
|
template<class... SS>
|
||||||
LuaDefStack(lua_State *L, SS & ... stackslots) {
|
LuaDefStack(lua_State *L, SS & ... stackslots) : LuaCoreStack(L) {
|
||||||
L_ = L;
|
|
||||||
count_slots<0, 0, 0>(stackslots...);
|
count_slots<0, 0, 0>(stackslots...);
|
||||||
if (lua_gettop(L_) != narg_) {
|
if (lua_gettop(L_) != narg_) {
|
||||||
luaL_error(L_, "function expects exactly %d arguments", narg_);
|
luaL_error(L_, "function expects exactly %d arguments", narg_);
|
||||||
@@ -642,11 +643,12 @@ public:
|
|||||||
assign_slots(1, 1 + nret_, 1 + nret_ + narg_, stackslots...);
|
assign_slots(1, 1 + nret_, 1 + nret_ + narg_, stackslots...);
|
||||||
}
|
}
|
||||||
|
|
||||||
~LuaDefStack() {
|
int result() {
|
||||||
if (!lua_isthrowing(L_)) {
|
lua_settop(L_, nret_);
|
||||||
lua_settop(L_, nret_);
|
return nret_;
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
~LuaDefStack() { }
|
||||||
};
|
};
|
||||||
|
|
||||||
class LuaExtStack : public LuaCoreStack {
|
class LuaExtStack : public LuaCoreStack {
|
||||||
@@ -673,8 +675,7 @@ private:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
template<class... SS>
|
template<class... SS>
|
||||||
LuaExtStack(lua_State *L, SS & ... stackslots) {
|
LuaExtStack(lua_State *L, SS & ... stackslots) : LuaCoreStack(L) {
|
||||||
L_ = L;
|
|
||||||
count_slots<0>(stackslots...);
|
count_slots<0>(stackslots...);
|
||||||
lua_checkstack(L_, nvar_ + 20);
|
lua_checkstack(L_, nvar_ + 20);
|
||||||
oldtop_ = lua_gettop(L_);
|
oldtop_ = lua_gettop(L_);
|
||||||
@@ -685,8 +686,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<class... SS>
|
template<class... SS>
|
||||||
LuaExtStack(const LuaCoreStack &LS0, SS & ... stackslots) {
|
LuaExtStack(const LuaCoreStack &LS0, SS & ... stackslots) : LuaCoreStack(LS0.state()) {
|
||||||
L_ = LS0.state();
|
|
||||||
count_slots<0>(stackslots...);
|
count_slots<0>(stackslots...);
|
||||||
lua_checkstack(L_, nvar_ + 20);
|
lua_checkstack(L_, nvar_ + 20);
|
||||||
oldtop_ = lua_gettop(L_);
|
oldtop_ = lua_gettop(L_);
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ bool table_equal(LuaCoreStack &LS, LuaSlot t1, LuaSlot t2) {
|
|||||||
LuaDefine(table_equal, "table1,table2", "return true if two tables contain the same keys and values") {
|
LuaDefine(table_equal, "table1,table2", "return true if two tables contain the same keys and values") {
|
||||||
LuaArg t1, t2;
|
LuaArg t1, t2;
|
||||||
LuaRet eql;
|
LuaRet eql;
|
||||||
LuaOldStack LS(L, t1, t2, eql);
|
LuaDefStack LS(L, t1, t2, eql);
|
||||||
LS.set(eql, table_equal(LS, t1, t2));
|
LS.set(eql, table_equal(LS, t1, t2));
|
||||||
return LS.result();
|
return LS.result();
|
||||||
}
|
}
|
||||||
@@ -121,7 +121,7 @@ LuaDefine(table_count, "table", "return the number of keys in table") {
|
|||||||
LuaDefine(table_clear, "table,metaflag", "clear all keys, and optionally the metatable") {
|
LuaDefine(table_clear, "table,metaflag", "clear all keys, and optionally the metatable") {
|
||||||
LuaArg tab, clearmeta;
|
LuaArg tab, clearmeta;
|
||||||
LuaVar metatable, metafield;
|
LuaVar metatable, metafield;
|
||||||
LuaOldStack LS(L, tab, clearmeta, metatable, metafield);
|
LuaDefStack LS(L, tab, clearmeta, metatable, metafield);
|
||||||
LS.checktable(tab, "table");
|
LS.checktable(tab, "table");
|
||||||
if (LS.ckboolean(clearmeta)) {
|
if (LS.ckboolean(clearmeta)) {
|
||||||
LS.getmetatable(metatable, tab);
|
LS.getmetatable(metatable, tab);
|
||||||
@@ -142,7 +142,7 @@ LuaDefine(table_clear, "table,metaflag", "clear all keys, and optionally the met
|
|||||||
LuaDefine(table_getflagbits, "table", "get the table's flag bits (debugging only)") {
|
LuaDefine(table_getflagbits, "table", "get the table's flag bits (debugging only)") {
|
||||||
LuaArg tab;
|
LuaArg tab;
|
||||||
LuaRet bits;
|
LuaRet bits;
|
||||||
LuaOldStack LS(L, tab, bits);
|
LuaDefStack LS(L, tab, bits);
|
||||||
uint16_t ubits = lua_getflagbits(L, tab.index());
|
uint16_t ubits = lua_getflagbits(L, tab.index());
|
||||||
LS.set(bits, ubits);
|
LS.set(bits, ubits);
|
||||||
return LS.result();
|
return LS.result();
|
||||||
@@ -150,7 +150,7 @@ LuaDefine(table_getflagbits, "table", "get the table's flag bits (debugging only
|
|||||||
|
|
||||||
LuaDefine(table_setflagbits, "table,bits", "set the table's flag bits (debugging only)") {
|
LuaDefine(table_setflagbits, "table,bits", "set the table's flag bits (debugging only)") {
|
||||||
LuaArg tab, bits;
|
LuaArg tab, bits;
|
||||||
LuaOldStack LS(L, tab, bits);
|
LuaDefStack LS(L, tab, bits);
|
||||||
uint16_t ubits = LS.ckinteger(bits);
|
uint16_t ubits = LS.ckinteger(bits);
|
||||||
lua_setflagbits(L, tab.index(), ubits);
|
lua_setflagbits(L, tab.index(), ubits);
|
||||||
return LS.result();
|
return LS.result();
|
||||||
@@ -232,7 +232,7 @@ int deque_make_room(lua_State *L, int deque, int left, int fill, int max) {
|
|||||||
LuaDefine(deque_create, "", "create a deque") {
|
LuaDefine(deque_create, "", "create a deque") {
|
||||||
LuaRet rdeque;
|
LuaRet rdeque;
|
||||||
LuaVar classobj;
|
LuaVar classobj;
|
||||||
LuaOldStack LS(L, rdeque, classobj);
|
LuaDefStack LS(L, rdeque, classobj);
|
||||||
const int imax = 4;
|
const int imax = 4;
|
||||||
eng::string err = LS.getclass(classobj, "deque");
|
eng::string err = LS.getclass(classobj, "deque");
|
||||||
if (err != "") {
|
if (err != "") {
|
||||||
@@ -251,7 +251,7 @@ LuaDefine(deque_create, "", "create a deque") {
|
|||||||
|
|
||||||
LuaDefine(deque_pushl, "deque,value", "push onto the left end of a deque") {
|
LuaDefine(deque_pushl, "deque,value", "push onto the left end of a deque") {
|
||||||
LuaArg deque, elt;
|
LuaArg deque, elt;
|
||||||
LuaOldStack LS(L, deque, elt);
|
LuaDefStack LS(L, deque, elt);
|
||||||
int left, fill, max;
|
int left, fill, max;
|
||||||
deque_get_info(L, deque.index(), &left, &fill, &max);
|
deque_get_info(L, deque.index(), &left, &fill, &max);
|
||||||
max = deque_make_room(L, deque.index(), left, fill, max);
|
max = deque_make_room(L, deque.index(), left, fill, max);
|
||||||
@@ -265,7 +265,7 @@ LuaDefine(deque_pushl, "deque,value", "push onto the left end of a deque") {
|
|||||||
|
|
||||||
LuaDefine(deque_pushr, "deque,value", "push onto the right end of a deque") {
|
LuaDefine(deque_pushr, "deque,value", "push onto the right end of a deque") {
|
||||||
LuaArg deque, elt;
|
LuaArg deque, elt;
|
||||||
LuaOldStack LS(L, deque, elt);
|
LuaDefStack LS(L, deque, elt);
|
||||||
int left, fill, max;
|
int left, fill, max;
|
||||||
deque_get_info(L, deque.index(), &left, &fill, &max);
|
deque_get_info(L, deque.index(), &left, &fill, &max);
|
||||||
max = deque_make_room(L, deque.index(), left, fill, max);
|
max = deque_make_room(L, deque.index(), left, fill, max);
|
||||||
@@ -279,7 +279,7 @@ LuaDefine(deque_pushr, "deque,value", "push onto the right end of a deque") {
|
|||||||
LuaDefine(deque_popl, "deque", "pop the left end of a deque") {
|
LuaDefine(deque_popl, "deque", "pop the left end of a deque") {
|
||||||
LuaArg deque;
|
LuaArg deque;
|
||||||
LuaRet result;
|
LuaRet result;
|
||||||
LuaOldStack LS(L, deque, result);
|
LuaDefStack LS(L, deque, result);
|
||||||
int left, fill, max;
|
int left, fill, max;
|
||||||
deque_get_info(L, deque.index(), &left, &fill, &max);
|
deque_get_info(L, deque.index(), &left, &fill, &max);
|
||||||
if (fill == 0) {
|
if (fill == 0) {
|
||||||
@@ -297,7 +297,7 @@ LuaDefine(deque_popl, "deque", "pop the left end of a deque") {
|
|||||||
LuaDefine(deque_popr, "deque", "pop the right end of a deque") {
|
LuaDefine(deque_popr, "deque", "pop the right end of a deque") {
|
||||||
LuaArg deque;
|
LuaArg deque;
|
||||||
LuaRet result;
|
LuaRet result;
|
||||||
LuaOldStack LS(L, deque, result);
|
LuaDefStack LS(L, deque, result);
|
||||||
int left, fill, max;
|
int left, fill, max;
|
||||||
deque_get_info(L, deque.index(), &left, &fill, &max);
|
deque_get_info(L, deque.index(), &left, &fill, &max);
|
||||||
if (fill == 0) {
|
if (fill == 0) {
|
||||||
@@ -315,7 +315,7 @@ LuaDefine(deque_popr, "deque", "pop the right end of a deque") {
|
|||||||
LuaDefine(deque_nthl, "deque,n", "return the nth item from the left end of a deque") {
|
LuaDefine(deque_nthl, "deque,n", "return the nth item from the left end of a deque") {
|
||||||
LuaArg deque, nn;
|
LuaArg deque, nn;
|
||||||
LuaRet result;
|
LuaRet result;
|
||||||
LuaOldStack LS(L, deque, nn, result);
|
LuaDefStack LS(L, deque, nn, result);
|
||||||
int left, fill, max;
|
int left, fill, max;
|
||||||
deque_get_info(L, deque.index(), &left, &fill, &max);
|
deque_get_info(L, deque.index(), &left, &fill, &max);
|
||||||
int n = LS.ckint(nn);
|
int n = LS.ckint(nn);
|
||||||
@@ -331,7 +331,7 @@ LuaDefine(deque_nthl, "deque,n", "return the nth item from the left end of a deq
|
|||||||
LuaDefine(deque_nthr, "deque,n", "return the nth item from the right end of a deque") {
|
LuaDefine(deque_nthr, "deque,n", "return the nth item from the right end of a deque") {
|
||||||
LuaArg deque, nn;
|
LuaArg deque, nn;
|
||||||
LuaRet result;
|
LuaRet result;
|
||||||
LuaOldStack LS(L, deque, nn, result);
|
LuaDefStack LS(L, deque, nn, result);
|
||||||
int left, fill, max;
|
int left, fill, max;
|
||||||
deque_get_info(L, deque.index(), &left, &fill, &max);
|
deque_get_info(L, deque.index(), &left, &fill, &max);
|
||||||
int n = LS.ckint(nn);
|
int n = LS.ckint(nn);
|
||||||
@@ -346,7 +346,7 @@ LuaDefine(deque_nthr, "deque,n", "return the nth item from the right end of a de
|
|||||||
|
|
||||||
LuaDefine(deque_setl, "deque,n,value", "set the nth item from the left end of a deque") {
|
LuaDefine(deque_setl, "deque,n,value", "set the nth item from the left end of a deque") {
|
||||||
LuaArg deque, nn, val;
|
LuaArg deque, nn, val;
|
||||||
LuaOldStack LS(L, deque, nn, val);
|
LuaDefStack LS(L, deque, nn, val);
|
||||||
int left, fill, max;
|
int left, fill, max;
|
||||||
deque_get_info(L, deque.index(), &left, &fill, &max);
|
deque_get_info(L, deque.index(), &left, &fill, &max);
|
||||||
int n = LS.ckint(nn);
|
int n = LS.ckint(nn);
|
||||||
@@ -361,7 +361,7 @@ LuaDefine(deque_setl, "deque,n,value", "set the nth item from the left end of a
|
|||||||
|
|
||||||
LuaDefine(deque_setr, "deque,n,value", "set the nth item from the right end of a deque") {
|
LuaDefine(deque_setr, "deque,n,value", "set the nth item from the right end of a deque") {
|
||||||
LuaArg deque, nn, val;
|
LuaArg deque, nn, val;
|
||||||
LuaOldStack LS(L, deque, nn, val);
|
LuaDefStack LS(L, deque, nn, val);
|
||||||
int left, fill, max;
|
int left, fill, max;
|
||||||
deque_get_info(L, deque.index(), &left, &fill, &max);
|
deque_get_info(L, deque.index(), &left, &fill, &max);
|
||||||
int n = LS.ckint(nn);
|
int n = LS.ckint(nn);
|
||||||
@@ -378,7 +378,7 @@ LuaDefine(deque_findl, "deque,value", "find the first occurence of value in dequ
|
|||||||
LuaArg deque, val;
|
LuaArg deque, val;
|
||||||
LuaRet pos;
|
LuaRet pos;
|
||||||
LuaVar check;
|
LuaVar check;
|
||||||
LuaOldStack LS(L, deque, val, pos, check);
|
LuaDefStack LS(L, deque, val, pos, check);
|
||||||
int left, fill, max;
|
int left, fill, max;
|
||||||
deque_get_info(L, deque.index(), &left, &fill, &max);
|
deque_get_info(L, deque.index(), &left, &fill, &max);
|
||||||
for (int i = 0; i < fill; i++) {
|
for (int i = 0; i < fill; i++) {
|
||||||
@@ -397,7 +397,7 @@ LuaDefine(deque_findr, "deque,value", "find the first occurrence of value in deq
|
|||||||
LuaArg deque, val;
|
LuaArg deque, val;
|
||||||
LuaRet pos;
|
LuaRet pos;
|
||||||
LuaVar check;
|
LuaVar check;
|
||||||
LuaOldStack LS(L, deque, val, pos, check);
|
LuaDefStack LS(L, deque, val, pos, check);
|
||||||
int left, fill, max;
|
int left, fill, max;
|
||||||
deque_get_info(L, deque.index(), &left, &fill, &max);
|
deque_get_info(L, deque.index(), &left, &fill, &max);
|
||||||
int base = left + fill - 1;
|
int base = left + fill - 1;
|
||||||
@@ -416,7 +416,7 @@ LuaDefine(deque_findr, "deque,value", "find the first occurrence of value in deq
|
|||||||
LuaDefine(deque_size, "deque", "return the number of items in the deque") {
|
LuaDefine(deque_size, "deque", "return the number of items in the deque") {
|
||||||
LuaArg deque;
|
LuaArg deque;
|
||||||
LuaRet size;
|
LuaRet size;
|
||||||
LuaOldStack LS(L, deque, size);
|
LuaDefStack LS(L, deque, size);
|
||||||
LS.checktable(deque, "deque");
|
LS.checktable(deque, "deque");
|
||||||
LS.rawget(size, deque, DEQUE_FILL);
|
LS.rawget(size, deque, DEQUE_FILL);
|
||||||
LS.checknumber(size, "deque size");
|
LS.checknumber(size, "deque size");
|
||||||
@@ -537,7 +537,7 @@ static void auxsort (lua_State *L, int tab, int l, int u) {
|
|||||||
bool table_getpairs(LuaCoreStack &LS0, LuaSlot tab, LuaSlot pairs, bool sort) {
|
bool table_getpairs(LuaCoreStack &LS0, LuaSlot tab, LuaSlot pairs, bool sort) {
|
||||||
lua_State *L = LS0.state();
|
lua_State *L = LS0.state();
|
||||||
LuaVar key, value;
|
LuaVar key, value;
|
||||||
LuaOldStack LS(L, key, value);
|
LuaExtStack LS(L, key, value);
|
||||||
bool sorted = true;
|
bool sorted = true;
|
||||||
// Create the table, store the initial 1.
|
// Create the table, store the initial 1.
|
||||||
int total = lua_nkeys(L, tab.index());
|
int total = lua_nkeys(L, tab.index());
|
||||||
@@ -558,7 +558,6 @@ bool table_getpairs(LuaCoreStack &LS0, LuaSlot tab, LuaSlot pairs, bool sort) {
|
|||||||
if (sort) {
|
if (sort) {
|
||||||
auxsort(L, pairs.index(), 1, total);
|
auxsort(L, pairs.index(), 1, total);
|
||||||
}
|
}
|
||||||
LS.result();
|
|
||||||
return sorted;
|
return sorted;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -602,7 +601,7 @@ LuaDefine(table_sortedpairs, "table",
|
|||||||
"|") {
|
"|") {
|
||||||
LuaArg tab;
|
LuaArg tab;
|
||||||
LuaRet closure, rtab, key;
|
LuaRet closure, rtab, key;
|
||||||
LuaOldStack LS(L, tab, closure, rtab, key);
|
LuaDefStack LS(L, tab, closure, rtab, key);
|
||||||
bool sorted = table_getpairs(LS, tab, rtab, true);
|
bool sorted = table_getpairs(LS, tab, rtab, true);
|
||||||
if (!sorted) {
|
if (!sorted) {
|
||||||
luaL_error(L, "Cannot sort the table keys");
|
luaL_error(L, "Cannot sort the table keys");
|
||||||
@@ -625,7 +624,7 @@ LuaDefine(table_semisortedpairs, "table",
|
|||||||
"|") {
|
"|") {
|
||||||
LuaArg tab;
|
LuaArg tab;
|
||||||
LuaRet closure, rtab, key;
|
LuaRet closure, rtab, key;
|
||||||
LuaOldStack LS(L, tab, closure, rtab, key);
|
LuaDefStack LS(L, tab, closure, rtab, key);
|
||||||
table_getpairs(LS, tab, rtab, true);
|
table_getpairs(LS, tab, rtab, true);
|
||||||
LS.set(closure, lfn_table_nextsortedpair);
|
LS.set(closure, lfn_table_nextsortedpair);
|
||||||
LS.set(key, LuaNil);
|
LS.set(key, LuaNil);
|
||||||
@@ -665,7 +664,7 @@ LuaDefine(genlt, "obj1,obj2",
|
|||||||
"|") {
|
"|") {
|
||||||
LuaArg o1,o2;
|
LuaArg o1,o2;
|
||||||
LuaRet lt;
|
LuaRet lt;
|
||||||
LuaOldStack LS(L, o1, o2, lt);
|
LuaDefStack LS(L, o1, o2, lt);
|
||||||
int ltf = lua_genlt(L, o1.index(), o2.index());
|
int ltf = lua_genlt(L, o1.index(), o2.index());
|
||||||
LS.set(lt, ltf ? true:false);
|
LS.set(lt, ltf ? true:false);
|
||||||
return LS.result();
|
return LS.result();
|
||||||
|
|||||||
Reference in New Issue
Block a user