Added two new stack disciplines to LuaStack

This commit is contained in:
2023-04-06 20:12:03 -04:00
parent b8df2bbc89
commit 7f000bc0fd
26 changed files with 401 additions and 271 deletions

View File

@@ -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;
LuaStack LS(L, value); LuaOldStack 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");

View File

@@ -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;
LuaStack LS(L, laction, llabel); LuaOldStack 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_")) {

View File

@@ -625,7 +625,7 @@ void HttpClientRequest::set_content(const eng::string &content) {
content_assigned_ = true; 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)) { if (!LS.isboolean(val)) {
check_fail(util::ss("verifycertificate must be a boolean")); check_fail(util::ss("verifycertificate must be a boolean"));
return; return;
@@ -633,7 +633,7 @@ void HttpClientRequest::set_verify_certificate(LuaStack &LS, LuaSlot val) {
set_verify_certificate(LS.ckboolean(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)) { if (!LS.isstring(val)) {
check_fail(util::ss("method must be a string")); check_fail(util::ss("method must be a string"));
return; return;
@@ -641,7 +641,7 @@ void HttpClientRequest::set_method(LuaStack &LS, LuaSlot val) {
set_method(LS.ckstring(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)) { if (!LS.isstring(val)) {
check_fail(util::ss("host must be a string")); check_fail(util::ss("host must be a string"));
return; return;
@@ -649,7 +649,7 @@ void HttpClientRequest::set_host(LuaStack &LS, LuaSlot val) {
set_host(LS.ckstring(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)) { if (!LS.isint(val)) {
check_fail(util::ss("port must be an int")); check_fail(util::ss("port must be an int"));
return; return;
@@ -657,7 +657,7 @@ void HttpClientRequest::set_port(LuaStack &LS, LuaSlot val) {
set_port(LS.ckint(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)) { if (!LS.isstring(val)) {
check_fail(util::ss("path must be a string")); check_fail(util::ss("path must be a string"));
return; return;
@@ -665,7 +665,7 @@ void HttpClientRequest::set_path(LuaStack &LS, LuaSlot val) {
set_path(LS.ckstring(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)) { if (!LS.isstring(key)) {
check_fail(util::ss("url parameter key must be a string")); check_fail(util::ss("url parameter key must be a string"));
return; return;
@@ -677,20 +677,20 @@ void HttpClientRequest::set_param(LuaStack &LS, LuaSlot key, LuaSlot val) {
set_param(LS.ckstring(key), LS.ckstring(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)) { if (!LS0.istable(tab)) {
check_fail(util::ss("params must be a table")); check_fail(util::ss("params must be a table"));
return; return;
} }
LuaVar key, val; LuaVar key, val;
LuaStack LS(LS0.state(), key, val); LuaOldStack 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);
} }
} }
void HttpClientRequest::set_url(LuaStack &LS, LuaSlot val) { void HttpClientRequest::set_url(LuaCoreStack &LS, LuaSlot val) {
if (!LS.isstring(val)) { if (!LS.isstring(val)) {
check_fail(util::ss("url must be a string")); check_fail(util::ss("url must be a string"));
return; return;
@@ -698,7 +698,7 @@ void HttpClientRequest::set_url(LuaStack &LS, LuaSlot val) {
set_url(LS.ckstring(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)) { if (!LS.isstring(val)) {
check_fail(util::ss("mime type must be a string")); check_fail(util::ss("mime type must be a string"));
return; return;
@@ -706,7 +706,7 @@ void HttpClientRequest::set_mime_type(LuaStack &LS, LuaSlot val) {
set_mime_type(LS.ckstring(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)) { if (!LS.isstring(val)) {
check_fail(util::ss("content must be a string")); check_fail(util::ss("content must be a string"));
return; return;
@@ -714,7 +714,7 @@ void HttpClientRequest::set_content(LuaStack &LS, LuaSlot val) {
set_content(LS.ckstring(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 out;
eng::string err = json::encode(LS, val, out, false, HttpParser::MAX_CONTENT_LENGTH); eng::string err = json::encode(LS, val, out, false, HttpParser::MAX_CONTENT_LENGTH);
if (!err.empty()) { if (!err.empty()) {
@@ -736,7 +736,7 @@ void HttpClientRequest::set_defaults() {
void HttpClientRequest::configure(LuaKeywordParser &kp) { void HttpClientRequest::configure(LuaKeywordParser &kp) {
LuaVar val; LuaVar val;
LuaStack LS(kp.state(), val); LuaOldStack LS(kp.state(), val);
if (kp.parse(val, "method")) { if (kp.parse(val, "method")) {
set_method(LS, val); set_method(LS, val);
} }
@@ -977,7 +977,7 @@ void HttpServerResponse::set_content(const eng::string &content) {
content_assigned_ = true; content_assigned_ = true;
} }
void HttpServerResponse::set_status(LuaStack &LS, LuaSlot val) { void HttpServerResponse::set_status(LuaCoreStack &LS, LuaSlot val) {
int status = 0; int status = 0;
if (LS.isstring(val)) { if (LS.isstring(val)) {
eng::string s = LS.ckstring(val); eng::string s = LS.ckstring(val);
@@ -995,7 +995,7 @@ void HttpServerResponse::set_status(LuaStack &LS, LuaSlot val) {
set_status(status); 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)) { if (!LS.isint(val)) {
check_fail(util::ss("max-age must be an int")); check_fail(util::ss("max-age must be an int"));
return; return;
@@ -1003,7 +1003,7 @@ void HttpServerResponse::set_max_age(LuaStack &LS, LuaSlot val) {
set_max_age(LS.ckint(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)) { if (!LS.isstring(val)) {
check_fail(util::ss("mime type must be a string")); check_fail(util::ss("mime type must be a string"));
return; return;
@@ -1011,7 +1011,7 @@ void HttpServerResponse::set_mime_type(LuaStack &LS, LuaSlot val) {
set_mime_type(LS.ckstring(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)) { if (!LS.isstring(val)) {
check_fail(util::ss("content must be a string")); check_fail(util::ss("content must be a string"));
return; return;
@@ -1019,7 +1019,7 @@ void HttpServerResponse::set_content(LuaStack &LS, LuaSlot val) {
set_content(LS.ckstring(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 out;
eng::string err = json::encode(LS, val, out, false, HttpParser::MAX_CONTENT_LENGTH); eng::string err = json::encode(LS, val, out, false, HttpParser::MAX_CONTENT_LENGTH);
if (!err.empty()) { if (!err.empty()) {
@@ -1032,7 +1032,7 @@ void HttpServerResponse::set_jsonvalue(LuaStack &LS, LuaSlot val) {
void HttpServerResponse::configure(LuaKeywordParser &kp) { void HttpServerResponse::configure(LuaKeywordParser &kp) {
LuaVar val; LuaVar val;
LuaStack LS(kp.state(), val); LuaOldStack LS(kp.state(), val);
if (kp.parse(val, "status")) { if (kp.parse(val, "status")) {
set_status(LS, val); set_status(LS, val);
} }
@@ -1468,9 +1468,9 @@ bool HttpParser::parse_content(std::string_view &view, bool closed) {
return true; return true;
} }
void HttpParser::store(LuaStack &LS0, LuaSlot tab) const { void HttpParser::store(LuaCoreStack &LS0, LuaSlot tab) const {
LuaVar ptab, djson; LuaVar ptab, djson;
LuaStack LS(LS0.state(), ptab, djson); LuaOldStack LS(LS0.state(), ptab, djson);
LS.newtable(tab); LS.newtable(tab);
if (!is_request_) { if (!is_request_) {
@@ -1633,7 +1633,7 @@ void HttpParser::parse_request(std::string_view view, bool closed) {
if (status_ == 0) status_ = 200; 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; HttpParser parser;
parser.fail(status_code, error); parser.fail(status_code, error);
parser.store(LS, tab); 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") { LuaDefine(http_fixurl, "url", "validate URL and repair minor flaws in the URL syntax") {
LuaArg url; LuaArg url;
LuaRet fixed; LuaRet fixed;
LuaStack LS(L, url, fixed); LuaOldStack 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;
LuaStack LS(L, tab, str); LuaOldStack 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;
LuaStack LS(L, text, tab); LuaOldStack 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;
LuaStack LS(L, text, tab); LuaOldStack 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;
LuaStack LS(L, tab, str); LuaOldStack 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;
LuaStack LS(L, str, ok); LuaOldStack 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;
LuaStack LS(L, code, str); LuaOldStack 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;
LuaStack LS(L, code, str); LuaOldStack 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();

View File

@@ -87,17 +87,17 @@ public:
void set_mime_type(const eng::string &mime_type); void set_mime_type(const eng::string &mime_type);
void set_content(const eng::string &content); void set_content(const eng::string &content);
void set_verify_certificate(LuaStack &LS, LuaSlot val); void set_verify_certificate(LuaCoreStack &LS, LuaSlot val);
void set_method(LuaStack &LS, LuaSlot val); void set_method(LuaCoreStack &LS, LuaSlot val);
void set_host(LuaStack &LS, LuaSlot val); void set_host(LuaCoreStack &LS, LuaSlot val);
void set_port(LuaStack &LS, LuaSlot val); void set_port(LuaCoreStack &LS, LuaSlot val);
void set_path(LuaStack &LS, LuaSlot path); void set_path(LuaCoreStack &LS, LuaSlot path);
void set_param(LuaStack &LS, LuaSlot key, LuaSlot val); void set_param(LuaCoreStack &LS, LuaSlot key, LuaSlot val);
void set_params(LuaStack &LS, LuaSlot tab); void set_params(LuaCoreStack &LS, LuaSlot tab);
void set_url(LuaStack &LS, LuaSlot val); void set_url(LuaCoreStack &LS, LuaSlot val);
void set_mime_type(LuaStack &LS, LuaSlot val); void set_mime_type(LuaCoreStack &LS, LuaSlot val);
void set_content(LuaStack &LS, LuaSlot val); void set_content(LuaCoreStack &LS, LuaSlot val);
void set_jsonvalue(LuaStack &LS, LuaSlot val); void set_jsonvalue(LuaCoreStack &LS, LuaSlot val);
// Set default values for method and port. // Set default values for method and port.
// This must be done after setting regular values. // This must be done after setting regular values.
@@ -198,11 +198,11 @@ public:
void set_mime_type(const eng::string &mime_type); void set_mime_type(const eng::string &mime_type);
void set_content(const eng::string &content); void set_content(const eng::string &content);
void set_status(LuaStack &LS, LuaSlot val); void set_status(LuaCoreStack &LS, LuaSlot val);
void set_max_age(LuaStack &LS, LuaSlot val); void set_max_age(LuaCoreStack &LS, LuaSlot val);
void set_mime_type(LuaStack &LS, LuaSlot val); void set_mime_type(LuaCoreStack &LS, LuaSlot val);
void set_content(LuaStack &LS, LuaSlot val); void set_content(LuaCoreStack &LS, LuaSlot val);
void set_jsonvalue(LuaStack &LS, LuaSlot val); void set_jsonvalue(LuaCoreStack &LS, LuaSlot val);
// Set default values. // Set default values.
// //
@@ -388,7 +388,7 @@ public:
// Store the parsed fields into a lua table. // Store the parsed fields into a lua table.
// //
void store(LuaStack &LS, LuaSlot tab) const; void store(LuaCoreStack &LS, LuaSlot tab) const;
// The parser will not try to parse content longer than this. // The parser will not try to parse content longer than this.
// //
@@ -420,7 +420,7 @@ public:
// Synthesize an error and store it in lua. // Synthesize an error and store it in lua.
// //
static void store_fail(LuaStack &LS, LuaSlot tab, int status, std::string_view error); static void store_fail(LuaCoreStack &LS, LuaSlot tab, int status, std::string_view error);
}; };
class HttpClientRequestMap : public eng::map<int64_t, HttpClientRequest> { class HttpClientRequestMap : public eng::map<int64_t, HttpClientRequest> {

View File

@@ -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 (!LuaStack::int64_storable(i)) return false; if (!LuaOldStack::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 (!LuaStack::int64_storable(i)) { if (!LuaOldStack::int64_storable(i)) {
return false; return false;
} }
lua_pushnumber(L, double(i)); lua_pushnumber(L, double(i));
@@ -515,7 +515,7 @@ static bool decode_value(lua_State *L, std::string_view &v) {
namespace json { namespace json {
eng::string encode(LuaStack &LS, LuaSlot in, eng::string &out, bool indent, int maxlen) { eng::string encode(LuaCoreStack &LS, LuaSlot in, eng::string &out, bool indent, int maxlen) {
eng::ostringstream oss; eng::ostringstream oss;
// Call the recursive encoder. Clean up any crap on the lua stack afterward. // Call the recursive encoder. Clean up any crap on the lua stack afterward.
@@ -540,7 +540,7 @@ eng::string encode(LuaStack &LS, LuaSlot in, eng::string &out, bool indent, int
} }
} }
bool decode(LuaStack &LS, LuaSlot out, std::string_view v) { bool decode(LuaCoreStack &LS, LuaSlot out, std::string_view v) {
lua_State *L = LS.state(); lua_State *L = LS.state();
// Try to read a single value from the view. // Try to read a single value from the view.
@@ -661,7 +661,7 @@ LuaDefine(json_encode, "data, indent, maxlen",
"|") { "|") {
LuaArg data, indent, maxlen; LuaArg data, indent, maxlen;
LuaRet encoded; LuaRet encoded;
LuaStack LS(L, data, indent, maxlen, encoded); LuaOldStack 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;
LuaStack LS(L, encoded, data); LuaOldStack 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;
// LuaStack LS(L, str, ret); // LuaOldStack 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;
// LuaStack LS(L, str, ret); // LuaOldStack 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);

View File

@@ -17,7 +17,7 @@ namespace json {
// Returns an error message. If the error message is an // Returns an error message. If the error message is an
// empty string, then the encoding was successful. // empty string, then the encoding was successful.
// //
eng::string encode(LuaStack &LS, LuaSlot in, eng::string &out, bool indent, int maxlen); eng::string encode(LuaCoreStack &LS, LuaSlot in, eng::string &out, bool indent, int maxlen);
// Decode json. // Decode json.
// //
@@ -27,7 +27,7 @@ namespace json {
// In that case, we return false and set 'out' to the // In that case, we return false and set 'out' to the
// token 'error'. // token 'error'.
// //
bool decode(LuaStack &LS, LuaSlot out, std::string_view in); bool decode(LuaCoreStack &LS, LuaSlot out, std::string_view in);
} }
#endif // JSON_HPP #endif // JSON_HPP

View File

@@ -9,7 +9,7 @@
#include <iostream> #include <iostream>
LuaConsole::LuaConsole() { LuaConsole::LuaConsole() {
lua_state_ = LuaStack::newstate(eng::l_alloc); lua_state_ = LuaOldStack::newstate(eng::l_alloc);
clear_raw_input(); clear_raw_input();
} }

View File

@@ -10,8 +10,8 @@
LuaSnap::LuaSnap() { LuaSnap::LuaSnap() {
state_ = LuaStack::newstate(eng::l_alloc); state_ = LuaOldStack::newstate(eng::l_alloc);
LuaStack LS(state_); LuaOldStack LS(state_);
// Create the persist table and the unpersist table. // Create the persist table and the unpersist table.
// //
@@ -36,7 +36,7 @@ void LuaSnap::serialize(StreamBuffer *sb) {
// lua variables that we'll need. // lua variables that we'll need.
LuaVar key, value; LuaVar key, value;
LuaRet permstable, regcopy; LuaRet permstable, regcopy;
LuaStack LS(state_, permstable, regcopy, key, value); LuaOldStack LS(state_, permstable, regcopy, key, value);
// Construct a copy of the registry table. // Construct a copy of the registry table.
LS.set(regcopy, LuaNewTable); LS.set(regcopy, LuaNewTable);
@@ -93,7 +93,7 @@ void LuaSnap::deserialize(StreamBuffer *sb) {
// Set up a stack frame. // Set up a stack frame.
LuaArg permstable, regcopy; LuaArg permstable, regcopy;
LuaVar key, value; LuaVar key, value;
LuaStack LS(state_, permstable, regcopy, key, value); LuaOldStack LS(state_, permstable, regcopy, key, value);
assert(LS.istable(regcopy)); assert(LS.istable(regcopy));

View File

@@ -236,7 +236,7 @@ eng::string LuaCoreStack::classname(LuaSlot tab) const {
eng::string result; eng::string result;
if ((istable(tab)) && (gettabletype(tab) == LUA_TT_CLASS)) { if ((istable(tab)) && (gettabletype(tab) == LUA_TT_CLASS)) {
LuaVar classes, name, dup; LuaVar classes, name, dup;
LuaStack LS(L_, classes, name, dup); LuaOldStack LS(L_, classes, name, dup);
// Get the classes table from the registry. // Get the classes table from the registry.
LS.rawget(classes, LuaRegistry, "classes"); LS.rawget(classes, LuaRegistry, "classes");
@@ -268,7 +268,7 @@ eng::string LuaCoreStack::classname(LuaSlot tab) const {
eng::string LuaCoreStack::getclass(LuaSlot classtab, LuaSlot classname) const { eng::string LuaCoreStack::getclass(LuaSlot classtab, LuaSlot classname) const {
lua_checkstack(L_, 20); lua_checkstack(L_, 20);
LuaVar globtab, cname; LuaVar globtab, cname;
LuaStack LS(L_, globtab, cname); LuaOldStack LS(L_, globtab, cname);
LS.getglobaltable(globtab); LS.getglobaltable(globtab);
if (LS.isstring(classname)) { if (LS.isstring(classname)) {
@@ -329,7 +329,7 @@ eng::string LuaCoreStack::getclass(LuaSlot tab, std::string_view name) const {
void LuaCoreStack::makeclass(LuaSlot classtab, LuaSlot classname) const { void LuaCoreStack::makeclass(LuaSlot classtab, LuaSlot classname) const {
lua_checkstack(L_, 20); lua_checkstack(L_, 20);
LuaVar classes, globtab, cname; LuaVar classes, globtab, cname;
LuaStack LS(L_, classes, globtab, cname); LuaOldStack LS(L_, classes, globtab, cname);
// Validate the class name. // Validate the class name.
assert(LS.validclassname(classname)); assert(LS.validclassname(classname));
@@ -371,7 +371,7 @@ void LuaCoreStack::makeclass(LuaSlot tab, std::string_view name) const {
void LuaCoreStack::maketan(LuaSlot tab, int64_t id) const { void LuaCoreStack::maketan(LuaSlot tab, int64_t id) const {
LuaVar tangibles, metatab; LuaVar tangibles, metatab;
LuaStack LS(L_, tangibles, metatab); LuaOldStack LS(L_, tangibles, metatab);
// Try to get the existing tangible. // Try to get the existing tangible.
LS.rawget(tangibles, LuaRegistry, "tangibles"); LS.rawget(tangibles, LuaRegistry, "tangibles");

View File

@@ -1,20 +1,20 @@
///////////////////////////////////////////////////////// /////////////////////////////////////////////////////////
// //
// //
// LUASTACK // LuaOldStack
// //
// The standard lua C API asks you to work with a stack machine. You're supposed // The standard lua C API asks you to work with a stack machine. You're supposed
// to manually push and pop values on the lua stack. I find this difficult, I // to manually push and pop values on the lua stack. I find this difficult, I
// find it hard to remember what stack position contains what value. // find it hard to remember what stack position contains what value.
// //
// To make it easier, I've created this module, "LuaStack." This module // To make it easier, I've created this module, "LuaOldStack." This module
// creates the illusion that you're working with local variables that contain // creates the illusion that you're working with local variables that contain
// lua values. // lua values.
// //
// Of course, this is all using the lua stack under the covers. Lua // Of course, this is all using the lua stack under the covers. Lua
// local variables are actually just lua stack addresses. But that's // local variables are actually just lua stack addresses. But that's
// all kept fairly well hidden. When you use Lua local variables, and // all kept fairly well hidden. When you use Lua local variables, and
// the accessors inside class LuaStack, it appears that you're // the accessors inside class LuaOldStack, it appears that you're
// manipulating data using local variables instead of using a stack. // manipulating data using local variables instead of using a stack.
// For people like me, that's easier to think about. // For people like me, that's easier to think about.
// //
@@ -31,7 +31,7 @@
// LuaVar loc1, loc2, loc3; // Declare local variables for other purposes. // LuaVar loc1, loc2, loc3; // Declare local variables for other purposes.
// //
// // Assign every local var a stack index. // // Assign every local var a stack index.
// LuaStack LS(L, arg1, arg2, ret1, loc1, loc2, loc3); // LuaOldStack LS(L, arg1, arg2, ret1, loc1, loc2, loc3);
// //
// // manipulate the data in the lua local variables... // // manipulate the data in the lua local variables...
// LS.rawget(loc1, arg1, arg2); // LS.rawget(loc1, arg1, arg2);
@@ -39,15 +39,15 @@
// } // }
// //
// Class LuaArg, LuaRet, and LuaVar are all lua local variables. // Class LuaArg, LuaRet, and LuaVar are all lua local variables.
// The luastack constructor assigns each one of them a position on // The LuaOldStack constructor assigns each one of them a position on
// the lua stack. It also makes sure that the arguments are in // the lua stack. It also makes sure that the arguments are in
// the LuaArg variables, and it makes sure that the LuaRet values // the LuaArg variables, and it makes sure that the LuaRet values
// are the only thing left on the stack at return time. // are the only thing left on the stack at return time.
// //
// Class LuaStack provides a complete catalog of accessors // Class LuaOldStack provides a complete catalog of accessors
// like 'rawget' - roughly speaking, it provides equivalents to // like 'rawget' - roughly speaking, it provides equivalents to
// every major accessor in the lua API. However, the accessors // every major accessor in the lua API. However, the accessors
// provided by LuaStack take input and output from lua locals, not // provided by LuaOldStack take input and output from lua locals, not
// from the stack. For example, consider this: // from the stack. For example, consider this:
// //
// LS.rawget(value, tab, key); // LS.rawget(value, tab, key);
@@ -56,20 +56,20 @@
// This does a rawget on 'table', with the specified 'key', and // This does a rawget on 'table', with the specified 'key', and
// stores the result in 'value'. Nothing is added to or removed // stores the result in 'value'. Nothing is added to or removed
// from the lua stack. In general, none of the accessors in class // from the lua stack. In general, none of the accessors in class
// LuaStack add anything to the stack, or pop anything from the // LuaOldStack add anything to the stack, or pop anything from the
// stack. // stack.
// //
// Class LuaStack can also do automatic type conversions. For // Class LuaOldStack can also do automatic type conversions. For
// example, suppose you do this: // example, suppose you do this:
// //
// LS.rawget(value, tab, key); // LS.rawget(value, tab, key);
// //
// Nominally, you would expect value, tab, and key to be lua local // Nominally, you would expect value, tab, and key to be lua local
// variables. But if you pass a eng::string for key, then LuaStack will // variables. But if you pass a eng::string for key, then LuaOldStack will
// automatically convert it. In general, class LuaStack can // automatically convert it. In general, class LuaOldStack can
// convert lua_Integer, lua_Number, eng::string, bool, and LuaNil. // convert lua_Integer, lua_Number, eng::string, bool, and LuaNil.
// //
// On output, LuaStack can convert lua_Integers, lua_Numbers, and // On output, LuaOldStack can convert lua_Integers, lua_Numbers, and
// eng::strings. In this case, strict type checking is done. If // eng::strings. In this case, strict type checking is done. If
// there is a type mismatch, a lua error is thrown. // there is a type mismatch, a lua error is thrown.
// //
@@ -90,20 +90,20 @@
///////////////////////////////////////////////////////// /////////////////////////////////////////////////////////
// //
// //
// LuaStack type checking // LuaOldStack type checking
// //
// LuaStack contains accessors for type checking. These include: // LuaOldStack contains accessors for type checking. These include:
// //
// bool LuaStack::isnumber(LuaSlot s) // bool LuaOldStack::isnumber(LuaSlot s)
// bool LuaStack::isinteger(LuaSlot s) // bool LuaOldStack::isinteger(LuaSlot s)
// bool LuaStack::isstring(LuaSlot s) // bool LuaOldStack::isstring(LuaSlot s)
// etc... // etc...
// //
// And it also contains operations that throw errors: // And it also contains operations that throw errors:
// //
// void LuaStack::checknumber(LuaSlot s) // void LuaOldStack::checknumber(LuaSlot s)
// void LuaStack::checkinteger(LuaSlot s) // void LuaOldStack::checkinteger(LuaSlot s)
// void LuaStack::checkstring(LuaSlot s) // void LuaOldStack::checkstring(LuaSlot s)
// etc... // etc...
// //
// These are different from the lua builtins in that they are strict. // These are different from the lua builtins in that they are strict.
@@ -112,10 +112,10 @@
// //
// These functions do checking and also conversion at the same time: // These functions do checking and also conversion at the same time:
// //
// lua_Integer LuaStack::ckinteger(LuaSlot s) // lua_Integer LuaOldStack::ckinteger(LuaSlot s)
// lua_Number LuaStack::cknumber(LuaSlot s) // lua_Number LuaOldStack::cknumber(LuaSlot s)
// eng::string LuaStack::ckstring(LuaSlot s) // eng::string LuaOldStack::ckstring(LuaSlot s)
// lua_State *LuaStack::ckthread(LuaSlot s) // lua_State *LuaOldStack::ckthread(LuaSlot s)
// //
// Like the other operations, they are strict. // Like the other operations, they are strict.
// //
@@ -151,8 +151,8 @@
///////////////////////////////////////////////////////// /////////////////////////////////////////////////////////
#ifndef LUASTACK_HPP #ifndef LuaOldStack_HPP
#define LUASTACK_HPP #define LuaOldStack_HPP
#include "wrap-string.hpp" #include "wrap-string.hpp"
#include "wrap-set.hpp" #include "wrap-set.hpp"
@@ -180,7 +180,7 @@ public:
} }
friend class LuaCoreStack; friend class LuaCoreStack;
friend class LuaStack; friend class LuaOldStack;
friend class LuaExtStack; friend class LuaExtStack;
}; };
@@ -476,7 +476,7 @@ public:
static bool int64_storable(int64_t v) { return (v <= MAXINT) && (v >= -MAXINT); } static bool int64_storable(int64_t v) { return (v <= MAXINT) && (v >= -MAXINT); }
}; };
class LuaStack : public LuaCoreStack { class LuaOldStack : public LuaCoreStack {
private: private:
int narg_; int narg_;
int ngap_; int ngap_;
@@ -549,7 +549,7 @@ private:
public: public:
template<class... SS> template<class... SS>
LuaStack(lua_State *L, SS & ... stackslots) { LuaOldStack(lua_State *L, SS & ... stackslots) {
L_ = 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_) {
@@ -573,10 +573,140 @@ public:
return nret_; return nret_;
} }
~LuaStack() {}; ~LuaOldStack() {};
}; };
class LuaDefStack : public LuaCoreStack {
private:
int nret_;
int narg_;
int nvar_;
template<class... SS>
void assign_slots(int retp, int argp, int varp, LuaRet &v, SS & ... stackslots) {
v.index_ = retp;
assign_slots(retp+1, argp, varp, stackslots...);
}
template<class... SS>
void assign_slots(int retp, int argp, int varp, LuaArg &v, SS & ... stackslots) {
v.index_ = argp;
assign_slots(retp, argp + 1, varp, stackslots...);
}
template<class... SS>
void assign_slots(int retp, int argp, int varp, LuaVar &v, SS & ... stackslots) {
v.index_ = varp;
assign_slots(retp, argp, varp+1, stackslots...);
}
void assign_slots(int retp, int argp, int varp) {}
template<int NRET, int NARG, int NVAR, class... SS>
void count_slots(LuaRet &v, SS & ... stackslots)
{
count_slots<NRET+1, NARG, NVAR>(stackslots...);
}
template<int NRET, int NARG, int NVAR, class... SS>
void count_slots(LuaArg &v, SS & ... stackslots)
{
count_slots<NRET, NARG+1, NVAR>(stackslots...);
}
template<int NRET, int NARG, int NVAR, class... SS>
void count_slots(LuaVar &v, SS & ... stackslots)
{
count_slots<NRET, NARG, NVAR+1>(stackslots...);
}
template<int NRET, int NARG, int NVAR>
void count_slots() {
nret_ = NRET;
narg_ = NARG;
nvar_ = NVAR;
}
public:
template<class... SS>
LuaDefStack(lua_State *L, SS & ... stackslots) {
L_ = L;
count_slots<0, 0, 0>(stackslots...);
if (lua_gettop(L_) != narg_) {
luaL_error(L_, "function expects exactly %d arguments", narg_);
}
int tot = narg_ + nvar_ + nret_;
lua_checkstack(L, tot + 20);
for (int i = 0; i < nret_; i ++) {
lua_pushnil(L_);
lua_insert(L_, i + 1);
}
for (int i = 0; i < nvar_; i++) {
lua_pushnil(L_);
}
assign_slots(1, 1 + nret_, 1 + nret_ + narg_, stackslots...);
}
~LuaDefStack() {
if (!lua_isthrowing(L_)) {
lua_settop(L_, nret_);
};
}
};
class LuaExtStack : public LuaCoreStack {
private:
int oldtop_;
int nvar_;
template<class... SS>
void assign_slots(int varp, LuaVar &v, SS & ... stackslots) {
v.index_ = varp;
assign_slots(varp+1, stackslots...);
}
void assign_slots(int varp) {}
template<int NVAR, class... SS>
void count_slots(LuaVar &v, SS & ... stackslots)
{
count_slots<NVAR+1>(stackslots...);
}
template<int NVAR>
void count_slots() {
nvar_ = NVAR;
}
public:
template<class... SS>
LuaExtStack(lua_State *L, SS & ... stackslots) {
L_ = L;
count_slots<0>(stackslots...);
lua_checkstack(L_, nvar_ + 20);
oldtop_ = lua_gettop(L_);
for (int i = 0; i < nvar_; i++) {
lua_pushnil(L_);
}
assign_slots(oldtop_ + 1, stackslots...);
}
template<class... SS>
LuaExtStack(const LuaCoreStack &LS0, SS & ... stackslots) {
L_ = LS0.state();
count_slots<0>(stackslots...);
lua_checkstack(L_, nvar_ + 20);
oldtop_ = lua_gettop(L_);
for (int i = 0; i < nvar_; i++) {
lua_pushnil(L_);
}
assign_slots(oldtop_ + 1, stackslots...);
}
~LuaExtStack() {
if (!lua_isthrowing(L_)) {
lua_settop(L_, oldtop_);
}
}
void forcediscard() {
lua_settop(L_, oldtop_);
}
};
// This is a helper class to help parse tables full of keywords. // This is a helper class to help parse tables full of keywords.
class LuaKeywordParser { class LuaKeywordParser {
struct cmp_char { struct cmp_char {
@@ -595,7 +725,7 @@ public:
// If the slot is not a table, sets the not_table // If the slot is not a table, sets the not_table
// flag and creates a dummy table in the slot. // flag and creates a dummy table in the slot.
LuaKeywordParser(lua_State *L, int slot); LuaKeywordParser(lua_State *L, int slot);
LuaKeywordParser(const LuaStack &LS, LuaSlot slot) : LuaKeywordParser(LS.state(), slot.index()) {} LuaKeywordParser(const LuaCoreStack &LS, LuaSlot slot) : LuaKeywordParser(LS.state(), slot.index()) {}
// Fetch a value from the table. This never throws. // Fetch a value from the table. This never throws.
// Return true if the value is non-nil. // Return true if the value is non-nil.
@@ -682,4 +812,4 @@ public:
#define LuaAssert(L, x) if (!(x)) { luaL_error((L), "Assert failed: %s (file %s line %d)", LuaStringify(x), __FILE__, __LINE__); } #define LuaAssert(L, x) if (!(x)) { luaL_error((L), "Assert failed: %s (file %s line %d)", LuaStringify(x), __FILE__, __LINE__); }
#define LuaAssertStrEq(L, x, y) { eng::string _s1_(x); eng::string _s2_(y); if (_s1_ != _s2_) luaL_error((L), "Assert failed: value=%s (file %s line %d)", _s1_.c_str(), __FILE__, __LINE__); } #define LuaAssertStrEq(L, x, y) { eng::string _s1_(x); eng::string _s2_(y); if (_s1_ != _s2_) luaL_error((L), "Assert failed: value=%s (file %s line %d)", _s1_.c_str(), __FILE__, __LINE__); }
#endif // LUASTACK_HPP #endif // LuaOldStack_HPP

View File

@@ -830,7 +830,7 @@ void PlaneMap::untrack_all() {
void PlaneScan::configure(LuaKeywordParser &kp) { void PlaneScan::configure(LuaKeywordParser &kp) {
lua_State *L = kp.state(); lua_State *L = kp.state();
LuaVar val, vx, vy, vz; LuaVar val, vx, vy, vz;
LuaStack LS(L, val, vx, vy, vz); LuaOldStack LS(L, val, vx, vy, vz);
bool have_plane = false; bool have_plane = false;
bool have_center = false; bool have_center = false;

View File

@@ -10,7 +10,7 @@
class PrintMachine { class PrintMachine {
public: public:
LuaVar tabchpos_; LuaVar tabchpos_;
LuaStack LS_; LuaOldStack LS_;
int next_id_; int next_id_;
bool indent_; bool indent_;
std::ostream *output_; std::ostream *output_;
@@ -103,7 +103,7 @@ public:
lua_State *L = LS_.state(); lua_State *L = LS_.state();
lua_checkstack(L, 20); lua_checkstack(L, 20);
LuaVar loffset, pairs, key, val, lchpos, nextseq; LuaVar loffset, pairs, key, val, lchpos, nextseq;
LuaStack LS(L, loffset, pairs, key, val, lchpos, nextseq); LuaOldStack LS(L, loffset, pairs, key, val, lchpos, nextseq);
// Determine the extended type of the object. If the // Determine the extended type of the object. If the
// expand flag is true, try to coerce it to a general table. // expand flag is true, try to coerce it to a general table.
@@ -212,7 +212,7 @@ public:
} }
// Atomic print interface. // Atomic print interface.
PrintMachine(LuaStack &LS0, LuaSlot root, bool quote, std::ostream *os) : PrintMachine(LuaCoreStack &LS0, LuaSlot root, bool quote, std::ostream *os) :
LS_(LS0.state(), tabchpos_) { LS_(LS0.state(), tabchpos_) {
output_ = os; output_ = os;
atomic_print(LS_.xtype(root), root, quote); atomic_print(LS_.xtype(root), root, quote);
@@ -220,7 +220,7 @@ public:
} }
// Pretty print interface. // Pretty print interface.
PrintMachine(LuaStack &LS0, LuaSlot root, bool indent, int level, bool expand, std::ostream *os) : PrintMachine(LuaCoreStack &LS0, LuaSlot root, bool indent, int level, bool expand, std::ostream *os) :
LS_(LS0.state(), tabchpos_) { LS_(LS0.state(), tabchpos_) {
next_id_ = 1; next_id_ = 1;
indent_ = indent; indent_ = indent;
@@ -248,7 +248,7 @@ public:
void PrettyPrintOptions::parse(LuaKeywordParser &kp) { void PrettyPrintOptions::parse(LuaKeywordParser &kp) {
LuaVar option; LuaVar option;
LuaStack LS(kp.state(), option); LuaOldStack LS(kp.state(), option);
if (kp.parse(option, "indent")) { if (kp.parse(option, "indent")) {
indent = LS.ckboolean(option); indent = LS.ckboolean(option);
} }
@@ -261,11 +261,11 @@ void PrettyPrintOptions::parse(LuaKeywordParser &kp) {
LS.result(); LS.result();
} }
void atomic_print(LuaStack &LS, LuaSlot val, bool quote, std::ostream *os) { void atomic_print(LuaCoreStack &LS, LuaSlot val, bool quote, std::ostream *os) {
PrintMachine pm(LS, val, quote, os); PrintMachine pm(LS, val, quote, os);
} }
void pprint(LuaStack &LS, LuaSlot val, const PrettyPrintOptions &opts, std::ostream *os) { void pprint(LuaCoreStack &LS, LuaSlot val, const PrettyPrintOptions &opts, std::ostream *os) {
PrintMachine pm(LS, val, opts.indent, opts.level, opts.expand, os); PrintMachine pm(LS, val, opts.indent, opts.level, opts.expand, os);
} }
@@ -279,7 +279,7 @@ LuaDefine(string_pprint, "obj1, obj2, ...",
"|") { "|") {
int n = lua_gettop(L); int n = lua_gettop(L);
LuaRet result; LuaRet result;
LuaStack LS(L, result); LuaOldStack LS(L, result);
util::ostringstream oss; util::ostringstream oss;
for (int i = 1; i <= n; i++) { for (int i = 1; i <= n; i++) {
LuaSpecial root(i); LuaSpecial root(i);
@@ -310,7 +310,7 @@ LuaDefine(string_pprintx, "options",
LuaArg loptions; LuaArg loptions;
LuaRet result; LuaRet result;
LuaVar value; LuaVar value;
LuaStack LS(L, loptions, result, value); LuaOldStack LS(L, loptions, result, value);
PrettyPrintOptions options; PrettyPrintOptions options;
LuaKeywordParser kp(LS, loptions); LuaKeywordParser kp(LS, loptions);
options.parse(kp); options.parse(kp);
@@ -333,7 +333,7 @@ LuaDefine(string_print, "obj",
"|") { "|") {
LuaArg val; LuaArg val;
LuaRet result; LuaRet result;
LuaStack LS(L, val, result); LuaOldStack LS(L, val, result);
eng::ostringstream oss; eng::ostringstream oss;
atomic_print(LS, val, false, &oss); atomic_print(LS, val, false, &oss);
LS.set(result, oss.str()); LS.set(result, oss.str());
@@ -350,7 +350,7 @@ LuaDefine(tostring, "obj",
"|") { "|") {
LuaArg val; LuaArg val;
LuaRet result; LuaRet result;
LuaStack LS(L, val, result); LuaOldStack LS(L, val, result);
eng::ostringstream oss; eng::ostringstream oss;
atomic_print(LS, val, false, &oss); atomic_print(LS, val, false, &oss);
LS.set(result, oss.str()); LS.set(result, oss.str());
@@ -360,7 +360,7 @@ LuaDefine(tostring, "obj",
LuaDefine(string_isidentifier, "str", "return true if the string is a valid lua identifier") { LuaDefine(string_isidentifier, "str", "return true if the string is a valid lua identifier") {
LuaArg str; LuaArg str;
LuaRet result; LuaRet result;
LuaStack LS(L, str, result); LuaOldStack LS(L, str, result);
if (LS.isstring(str)) { if (LS.isstring(str)) {
eng::string s = LS.ckstring(str); eng::string s = LS.ckstring(str);
LS.set(result, sv::is_lua_id(s)); LS.set(result, sv::is_lua_id(s));

View File

@@ -36,10 +36,10 @@ struct PrettyPrintOptions {
// it just prints "<table>". This routine is the heart of the lua // it just prints "<table>". This routine is the heart of the lua
// primitives 'print' and 'tostring'. // primitives 'print' and 'tostring'.
// //
void atomic_print(LuaStack &LS, LuaSlot val, bool quote, std::ostream *os); void atomic_print(LuaCoreStack &LS, LuaSlot val, bool quote, std::ostream *os);
// Pretty print to a stream. // Pretty print to a stream.
// //
void pprint(LuaStack &LS, LuaSlot val, const PrettyPrintOptions &opts, std::ostream *os); void pprint(LuaCoreStack &LS, LuaSlot val, const PrettyPrintOptions &opts, std::ostream *os);
#endif // PPRINT_HPP #endif // PPRINT_HPP

View File

@@ -12,14 +12,14 @@ class DeserializeError {
class Deserializer { class Deserializer {
LuaVar id_to_value_; LuaVar id_to_value_;
LuaStack LS_; LuaOldStack LS_;
eng::string &error_; eng::string &error_;
StreamBuffer *sb_; StreamBuffer *sb_;
int next_id_; int next_id_;
void deserialize_table_r(LuaSlot target) { void deserialize_table_r(LuaSlot target) {
LuaVar key, val; LuaVar key, val;
LuaStack LS(LS_.state(), key, val); LuaOldStack LS(LS_.state(), key, val);
LS.newtable(target); LS.newtable(target);
LS.rawset(id_to_value_, next_id_++, target); LS.rawset(id_to_value_, next_id_++, target);
bool hasmeta = sb_->read_bool(); bool hasmeta = sb_->read_bool();
@@ -104,7 +104,7 @@ class Deserializer {
} }
public: public:
Deserializer(LuaStack &LS0, LuaSlot val, StreamBuffer *sb, eng::string &error) : Deserializer(LuaCoreStack &LS0, LuaSlot val, StreamBuffer *sb, eng::string &error) :
LS_(LS0.state(), id_to_value_), error_(error), sb_(sb), next_id_(1) { LS_(LS0.state(), id_to_value_), error_(error), sb_(sb), next_id_(1) {
LS_.newtable(id_to_value_); LS_.newtable(id_to_value_);
int top = lua_gettop(LS_.state()); int top = lua_gettop(LS_.state());
@@ -137,14 +137,14 @@ public:
class Serializer { class Serializer {
LuaVar lookup_; LuaVar lookup_;
LuaVar value_to_id_; LuaVar value_to_id_;
LuaStack LS_; LuaOldStack LS_;
eng::string &error_; eng::string &error_;
StreamBuffer *sb_; StreamBuffer *sb_;
int next_id_; int next_id_;
void serialize_table_r(LuaSlot tab) { void serialize_table_r(LuaSlot tab) {
LuaVar key, val; LuaVar key, val;
LuaStack SLS(LS_.state(), key, val); LuaOldStack SLS(LS_.state(), key, val);
sb_->write_uint8(LUA_TT_GENERAL); sb_->write_uint8(LUA_TT_GENERAL);
SLS.getmetatable(val, tab); SLS.getmetatable(val, tab);
if (SLS.isnil(val)) { if (SLS.isnil(val)) {
@@ -265,7 +265,7 @@ class Serializer {
} }
public: public:
Serializer(LuaStack &LS0, LuaSlot val, StreamBuffer *sb, eng::string &error) : Serializer(LuaCoreStack &LS0, LuaSlot val, StreamBuffer *sb, eng::string &error) :
LS_(LS0.state(), lookup_, value_to_id_), error_(error), sb_(sb), next_id_(1) { LS_(LS0.state(), lookup_, value_to_id_), error_(error), sb_(sb), next_id_(1) {
LS_.newtable(value_to_id_); LS_.newtable(value_to_id_);
sb_->write_uint16(0xD096); sb_->write_uint16(0xD096);
@@ -274,13 +274,13 @@ public:
} }
}; };
eng::string serialize_lua(LuaStack &LS0, LuaSlot val, StreamBuffer *sb) { eng::string serialize_lua(LuaCoreStack &LS0, LuaSlot val, StreamBuffer *sb) {
eng::string error; eng::string error;
Serializer sz(LS0, val, sb, error); Serializer sz(LS0, val, sb, error);
return error; return error;
}; };
eng::string deserialize_lua(LuaStack &LS0, LuaSlot val, StreamBuffer *sb) { eng::string deserialize_lua(LuaCoreStack &LS0, LuaSlot val, StreamBuffer *sb) {
eng::string error; eng::string error;
Deserializer dsz(LS0, val, sb, error); Deserializer dsz(LS0, val, sb, error);
if (!error.empty()) { if (!error.empty()) {
@@ -328,7 +328,7 @@ LuaDefine(table_serialize, "value",
"|") { "|") {
LuaArg value; LuaArg value;
LuaRet str; LuaRet str;
LuaStack LS(L, value, str); LuaOldStack LS(L, value, str);
StreamBuffer sb; StreamBuffer sb;
eng::string error = serialize_lua(LS, value, &sb); eng::string error = serialize_lua(LS, value, &sb);
if (!error.empty()) { if (!error.empty()) {
@@ -347,7 +347,7 @@ LuaDefine(table_deserialize, "binary",
"|") { "|") {
LuaArg str; LuaArg str;
LuaRet value; LuaRet value;
LuaStack LS(L, value, str); LuaOldStack LS(L, value, str);
std::string_view s = LS.ckstringview(str); std::string_view s = LS.ckstringview(str);
StreamBuffer sb(s); StreamBuffer sb(s);
eng::string error = deserialize_lua(LS, value, &sb); eng::string error = deserialize_lua(LS, value, &sb);

View File

@@ -25,7 +25,7 @@
// If there is an error, returns an error message. In this case, the // If there is an error, returns an error message. In this case, the
// streambuffer contains garbage. // streambuffer contains garbage.
// //
eng::string serialize_lua(LuaStack &LS0, LuaSlot val, StreamBuffer *sb); eng::string serialize_lua(LuaCoreStack &LS0, LuaSlot val, StreamBuffer *sb);
// deserialize_lua // deserialize_lua
// //
@@ -35,6 +35,6 @@ eng::string serialize_lua(LuaStack &LS0, LuaSlot val, StreamBuffer *sb);
// If there is an error, returns an error message. In this case, the // If there is an error, returns an error message. In this case, the
// streambuffer is likely only partially consumed. // streambuffer is likely only partially consumed.
// //
eng::string deserialize_lua(LuaStack &LS0, LuaSlot val, StreamBuffer *sb); eng::string deserialize_lua(LuaCoreStack &LS0, LuaSlot val, StreamBuffer *sb);
#endif // SERIALIZELUA_HPP #endif // SERIALIZELUA_HPP

View File

@@ -21,7 +21,7 @@
LuaDefine(makeclass, "classname", "create a class if it doesn't already exist") { LuaDefine(makeclass, "classname", "create a class if it doesn't already exist") {
LuaArg classname; LuaArg classname;
LuaRet classtab; LuaRet classtab;
LuaStack LS(L, classname, classtab); LuaOldStack LS(L, classname, classtab);
if (!LS.isstring(classname)) { if (!LS.isstring(classname)) {
luaL_error(L, "class name must be a string"); luaL_error(L, "class name must be a string");
} }
@@ -35,7 +35,7 @@ LuaDefine(makeclass, "classname", "create a class if it doesn't already exist")
LuaDefine(getclass, "classname", "get the classtab with the specified name") { LuaDefine(getclass, "classname", "get the classtab with the specified name") {
LuaArg classname; LuaArg classname;
LuaRet classtab; LuaRet classtab;
LuaStack LS(L, classname, classtab); LuaOldStack LS(L, classname, classtab);
eng::string err = LS.getclass(classtab, classname); eng::string err = LS.getclass(classtab, classname);
if (err != "") { if (err != "") {
luaL_error(L, "%s", err.c_str()); luaL_error(L, "%s", err.c_str());
@@ -46,7 +46,7 @@ LuaDefine(getclass, "classname", "get the classtab with the specified name") {
LuaDefine(classname, "classtable", "get the class name from a class table") { LuaDefine(classname, "classtable", "get the class name from a class table") {
LuaArg table; LuaArg table;
LuaRet result; LuaRet result;
LuaStack LS(L, table, result); LuaOldStack LS(L, table, result);
eng::string rstr = LS.classname(table); eng::string rstr = LS.classname(table);
if (rstr == "") { if (rstr == "") {
LS.set(result, LuaNil); LS.set(result, LuaNil);
@@ -67,7 +67,7 @@ static void get_reg_name(std::string_view name, std::string_view &classname, std
} }
} }
static void get_info_table(LuaStack &LS, LuaSlot db, LuaSlot info, const eng::string &fn) { static void get_info_table(LuaCoreStack &LS, LuaSlot db, LuaSlot info, const eng::string &fn) {
LS.rawget(info, db, fn); LS.rawget(info, db, fn);
if (!LS.istable(info)) { if (!LS.istable(info)) {
LS.set(info, LuaNewTable); LS.set(info, LuaNewTable);
@@ -76,9 +76,9 @@ static void get_info_table(LuaStack &LS, LuaSlot db, LuaSlot info, const eng::st
LS.rawset(info, "name", fn); LS.rawset(info, "name", fn);
} }
static void calculate_loadresult(LuaStack &LS0, LuaSlot info, const eng::string &fn, const eng::string &code) { static void calculate_loadresult(LuaCoreStack &LS0, LuaSlot info, const eng::string &fn, const eng::string &code) {
LuaVar loadresult; LuaVar loadresult;
LuaStack LS(LS0.state(), loadresult); LuaOldStack LS(LS0.state(), loadresult);
if (code == "") { if (code == "") {
LS.rawset(info, "loadresult", "missing or empty source file"); LS.rawset(info, "loadresult", "missing or empty source file");
} else { } else {
@@ -93,8 +93,8 @@ static void calculate_loadresult(LuaStack &LS0, LuaSlot info, const eng::string
void SourceDB::diff(const SourceDB &auth, StreamBuffer *sb) { void SourceDB::diff(const SourceDB &auth, StreamBuffer *sb) {
LuaVar sdb, sfn, sinfo, shash, sseq; LuaVar sdb, sfn, sinfo, shash, sseq;
LuaVar mdb, mfn, minfo, mhash, mseq, mcode; LuaVar mdb, mfn, minfo, mhash, mseq, mcode;
LuaStack SLS(lua_state_, sdb, sfn, sinfo, shash, sseq); LuaOldStack SLS(lua_state_, sdb, sfn, sinfo, shash, sseq);
LuaStack MLS(auth.lua_state_, mdb, mfn, minfo, mhash, mseq, mcode); LuaOldStack MLS(auth.lua_state_, mdb, mfn, minfo, mhash, mseq, mcode);
sb->write_int32(0); sb->write_int32(0);
int wc_after = sb->total_writes(); int wc_after = sb->total_writes();
int nupdates = 0; int nupdates = 0;
@@ -152,7 +152,7 @@ void SourceDB::diff(const SourceDB &auth, StreamBuffer *sb) {
bool SourceDB::patch(StreamBuffer *sb, DebugCollector *dbc) { bool SourceDB::patch(StreamBuffer *sb, DebugCollector *dbc) {
lua_State *L = lua_state_; lua_State *L = lua_state_;
LuaVar db, info; LuaVar db, info;
LuaStack LS(L, db, info); LuaOldStack LS(L, db, info);
LS.rawget(db, LuaRegistry, "sourcedb"); LS.rawget(db, LuaRegistry, "sourcedb");
int nupdates = sb->read_int32(); int nupdates = sb->read_int32();
for (int i = 0; i < nupdates; i++) { for (int i = 0; i < nupdates; i++) {
@@ -179,7 +179,7 @@ bool SourceDB::patch(StreamBuffer *sb, DebugCollector *dbc) {
void SourceDB::set(const eng::string &fn, const eng::string &code, int sequence) { void SourceDB::set(const eng::string &fn, const eng::string &code, int sequence) {
lua_State *L = lua_state_; lua_State *L = lua_state_;
LuaVar db, info; LuaVar db, info;
LuaStack LS(L, db, info); LuaOldStack LS(L, db, info);
LS.rawget(db, LuaRegistry, "sourcedb"); LS.rawget(db, LuaRegistry, "sourcedb");
get_info_table(LS, db, info, fn); get_info_table(LS, db, info, fn);
LS.rawset(info, "sequence", sequence); LS.rawset(info, "sequence", sequence);
@@ -193,7 +193,7 @@ void SourceDB::set(const eng::string &fn, const eng::string &code, int sequence)
eng::string SourceDB::get(const eng::string &fn) { eng::string SourceDB::get(const eng::string &fn) {
lua_State *L = lua_state_; lua_State *L = lua_state_;
LuaVar db, info, code, sequence, loadresult; LuaVar db, info, code, sequence, loadresult;
LuaStack LS(L, db, info, code, sequence, loadresult); LuaOldStack LS(L, db, info, code, sequence, loadresult);
LS.rawget(db, LuaRegistry, "sourcedb"); LS.rawget(db, LuaRegistry, "sourcedb");
LS.rawget(info, db, fn); LS.rawget(info, db, fn);
if (!LS.istable(info)) { if (!LS.istable(info)) {
@@ -220,7 +220,7 @@ eng::string SourceDB::get(const eng::string &fn) {
void SourceDB::update(const util::LuaSourceVec &source) { void SourceDB::update(const util::LuaSourceVec &source) {
lua_State *L = lua_state_; lua_State *L = lua_state_;
LuaVar sourcedb, info; LuaVar sourcedb, info;
LuaStack LS(L, sourcedb, info); LuaOldStack LS(L, sourcedb, info);
// Get and clear the source database. // Get and clear the source database.
LS.rawget(sourcedb, LuaRegistry, "sourcedb"); LS.rawget(sourcedb, LuaRegistry, "sourcedb");
@@ -250,7 +250,7 @@ void SourceDB::update(const util::LuaSourceVec &source) {
// //
static void source_clear_globals(lua_State *L) { static void source_clear_globals(lua_State *L) {
LuaVar classname, classtab, key, globtab, classes; LuaVar classname, classtab, key, globtab, classes;
LuaStack LS(L, classname, classtab, key, globtab, classes); LuaOldStack LS(L, classname, classtab, key, globtab, classes);
LS.getglobaltable(globtab); LS.getglobaltable(globtab);
LS.cleartable(globtab, true); LS.cleartable(globtab, true);
@@ -271,7 +271,7 @@ static void source_clear_globals(lua_State *L) {
// //
static void source_load_cfunctions(lua_State *L) { static void source_load_cfunctions(lua_State *L) {
LuaVar classobj; LuaVar classobj;
LuaStack LS(L, classobj); LuaOldStack LS(L, classobj);
for (auto r = LuaFunctionReg::All; r != nullptr; r=r->next()) { for (auto r = LuaFunctionReg::All; r != nullptr; r=r->next()) {
lua_CFunction func = r->get_func(); lua_CFunction func = r->get_func();
if ((func != nullptr) && (!r->get_sandbox())) { if ((func != nullptr) && (!r->get_sandbox())) {
@@ -294,7 +294,7 @@ static void source_load_cfunctions(lua_State *L) {
// //
static void source_load_cconstants(lua_State *L) { static void source_load_cconstants(lua_State *L) {
LuaVar classobj, value; LuaVar classobj, value;
LuaStack LS(L, classobj, value); LuaOldStack LS(L, classobj, value);
for (auto r = LuaConstantReg::All; r != nullptr; r=r->next()) { for (auto r = LuaConstantReg::All; r != nullptr; r=r->next()) {
if (r->get_tokenvalue().empty()) { if (r->get_tokenvalue().empty()) {
LS.set(value, r->get_numbervalue()); LS.set(value, r->get_numbervalue());
@@ -319,7 +319,7 @@ static void source_load_cconstants(lua_State *L) {
// //
static eng::string source_load_lfunctions(lua_State *L) { static eng::string source_load_lfunctions(lua_State *L) {
LuaVar sourcedb, key, info, seq, closure, err; LuaVar sourcedb, key, info, seq, closure, err;
LuaStack LS(L, sourcedb, key, info, seq, closure, err); LuaOldStack LS(L, sourcedb, key, info, seq, closure, err);
// Get the source database. // Get the source database.
LS.rawget(sourcedb, LuaRegistry, "sourcedb"); LS.rawget(sourcedb, LuaRegistry, "sourcedb");
@@ -364,7 +364,7 @@ static eng::string source_load_lfunctions(lua_State *L) {
eng::string SourceDB::rebuild() { eng::string SourceDB::rebuild() {
lua_State *L = lua_state_; lua_State *L = lua_state_;
LuaVar mathclass, httpclass, jsonnull; LuaVar mathclass, httpclass, jsonnull;
LuaStack LS(L, mathclass, httpclass, jsonnull); LuaOldStack LS(L, mathclass, httpclass, jsonnull);
source_clear_globals(L); source_clear_globals(L);
source_load_cfunctions(L); source_load_cfunctions(L);
source_load_cconstants(L); source_load_cconstants(L);
@@ -376,7 +376,7 @@ eng::string SourceDB::rebuild() {
void SourceDB::run_unittests() { void SourceDB::run_unittests() {
lua_State *L = lua_state_; lua_State *L = lua_state_;
LuaVar unittests, name, func, err, globtab; LuaVar unittests, name, func, err, globtab;
LuaStack LS(L, unittests, name, func, err, globtab); LuaOldStack LS(L, unittests, name, func, err, globtab);
LS.getglobaltable(globtab); LS.getglobaltable(globtab);
LS.rawget(unittests, globtab, "unittests"); LS.rawget(unittests, globtab, "unittests");
@@ -414,7 +414,7 @@ void SourceDB::run_unittests() {
void SourceDB::init(lua_State *L) { void SourceDB::init(lua_State *L) {
lua_state_ = L; lua_state_ = L;
LuaVar globtab, persist, unpersist, classname, classtab, funcname, funcp, rawfunc, nullstring; LuaVar globtab, persist, unpersist, classname, classtab, funcname, funcp, rawfunc, nullstring;
LuaStack LS(L, globtab, persist, unpersist, classname, classtab, funcname, funcp, rawfunc, nullstring); LuaOldStack LS(L, globtab, persist, unpersist, classname, classtab, funcname, funcp, rawfunc, nullstring);
LS.getglobaltable(globtab); LS.getglobaltable(globtab);
LS.rawset(LuaRegistry, "sourcedb", LuaNewTable); LS.rawset(LuaRegistry, "sourcedb", LuaNewTable);
@@ -470,10 +470,10 @@ void SourceDB::deserialize_source(util::LuaSourceVec *sv, StreamBuffer *sb) {
// This function should not touch the dlmalloc heap. // This function should not touch the dlmalloc heap.
void SourceDB::register_lua_builtins() { void SourceDB::register_lua_builtins() {
lua_State *L = LuaStack::newstate(nullptr); lua_State *L = LuaOldStack::newstate(nullptr);
luaL_openlibs(L); luaL_openlibs(L);
LuaVar globals, lclassname, lfuncname, classtab, func; LuaVar globals, lclassname, lfuncname, classtab, func;
LuaStack LS(L, globals, lclassname, lfuncname, classtab, func); LuaOldStack LS(L, globals, lclassname, lfuncname, classtab, func);
LS.getglobaltable(globals); LS.getglobaltable(globals);
// Iterate over the function registry, copying function pointers from // Iterate over the function registry, copying function pointers from
@@ -527,10 +527,10 @@ void SourceDB::register_lua_builtins() {
} }
eng::string SourceDB::function_docs(const LuaStack &LS0, LuaSlot fn) { eng::string SourceDB::function_docs(const LuaCoreStack &LS0, LuaSlot fn) {
lua_State *L = LS0.state(); lua_State *L = LS0.state();
LuaVar sourcedb, fname, finfo, code; LuaVar sourcedb, fname, finfo, code;
LuaStack LS(L, sourcedb, fname, finfo, code); LuaOldStack LS(L, sourcedb, fname, finfo, code);
if (LS.iscfunction(fn)) { if (LS.iscfunction(fn)) {
lua_CFunction cfn = lua_tocfunction(L, fn.index()); lua_CFunction cfn = lua_tocfunction(L, fn.index());
@@ -607,7 +607,7 @@ eng::string SourceDB::function_docs(const LuaStack &LS0, LuaSlot fn) {
// These should go away eventually. They're for debugging. // These should go away eventually. They're for debugging.
LuaDefine(coroutine_setnextid, "thread,id", "set the next id of a thread (debugging only)") { LuaDefine(coroutine_setnextid, "thread,id", "set the next id of a thread (debugging only)") {
LuaArg co, lid; LuaArg co, lid;
LuaStack LS(L, co, lid); LuaOldStack LS(L, co, lid);
lua_State *CO = LS.ckthread(co); lua_State *CO = LS.ckthread(co);
lua_Number id = LS.ckinteger(lid); lua_Number id = LS.ckinteger(lid);
lua_setnextid(CO, id); lua_setnextid(CO, id);
@@ -617,7 +617,7 @@ LuaDefine(coroutine_setnextid, "thread,id", "set the next id of a thread (debugg
LuaDefine(coroutine_getnextid, "thread", "get the next id of a thread (debugging only)") { LuaDefine(coroutine_getnextid, "thread", "get the next id of a thread (debugging only)") {
LuaArg co; LuaArg co;
LuaRet lid; LuaRet lid;
LuaStack LS(L, co, lid); LuaOldStack LS(L, co, lid);
lua_State *CO = LS.ckthread(co); lua_State *CO = LS.ckthread(co);
LS.set(lid, lua_getnextid(CO)); LS.set(lid, lua_getnextid(CO));
return LS.result(); return LS.result();
@@ -766,7 +766,7 @@ LuaSandboxBuiltin(math_log10, "", "");
LuaNumberConstant(math_pi, M_PI, ""); LuaNumberConstant(math_pi, M_PI, "");
LuaNumberConstant(math_huge, HUGE_VAL, ""); LuaNumberConstant(math_huge, HUGE_VAL, "");
LuaNumberConstant(math_nan, NAN, ""); LuaNumberConstant(math_nan, NAN, "");
LuaNumberConstant(math_maxint, LuaStack::MAXINT, ""); LuaNumberConstant(math_maxint, LuaOldStack::MAXINT, "");
// math.random and math.randomseed are in world-accessor.cpp, because // math.random and math.randomseed are in world-accessor.cpp, because
// generating random numbers must manipulate global state which is // generating random numbers must manipulate global state which is

View File

@@ -180,7 +180,7 @@ public:
static void register_lua_builtins(); static void register_lua_builtins();
// Get function documentation. // Get function documentation.
static eng::string function_docs(const LuaStack &LS, LuaSlot slot); static eng::string function_docs(const LuaCoreStack &LS, LuaSlot slot);
// Serialize and unserialize a source vector. // Serialize and unserialize a source vector.
// //

View File

@@ -5,7 +5,7 @@
#include "source.hpp" #include "source.hpp"
bool table_equal(LuaStack &LS, LuaSlot t1, LuaSlot t2) { bool table_equal(LuaCoreStack &LS, LuaSlot t1, LuaSlot t2) {
lua_State *L = LS.state(); lua_State *L = LS.state();
int top = lua_gettop(L); int top = lua_gettop(L);
LS.checktable(t1, "table1"); LS.checktable(t1, "table1");
@@ -33,7 +33,7 @@ bool table_equal(LuaStack &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;
LuaStack LS(L, t1, t2, eql); LuaOldStack 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;
LuaStack LS(L, tab, clearmeta, metatable, metafield); LuaOldStack 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;
LuaStack LS(L, tab, bits); LuaOldStack 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;
LuaStack LS(L, tab, bits); LuaOldStack 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;
LuaStack LS(L, rdeque, classobj); LuaOldStack 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;
LuaStack LS(L, deque, elt); LuaOldStack 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;
LuaStack LS(L, deque, elt); LuaOldStack 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;
LuaStack LS(L, deque, result); LuaOldStack 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;
LuaStack LS(L, deque, result); LuaOldStack 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;
LuaStack LS(L, deque, nn, result); LuaOldStack 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;
LuaStack LS(L, deque, nn, result); LuaOldStack 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;
LuaStack LS(L, deque, nn, val); LuaOldStack 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;
LuaStack LS(L, deque, nn, val); LuaOldStack 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;
LuaStack LS(L, deque, val, pos, check); LuaOldStack 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;
LuaStack LS(L, deque, val, pos, check); LuaOldStack 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;
LuaStack LS(L, deque, size); LuaOldStack 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");
@@ -534,10 +534,10 @@ static void auxsort (lua_State *L, int tab, int l, int u) {
} /* repeat the routine for the larger one */ } /* repeat the routine for the larger one */
} }
bool table_getpairs(LuaStack &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;
LuaStack LS(L, key, value); LuaOldStack 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());
@@ -602,7 +602,7 @@ LuaDefine(table_sortedpairs, "table",
"|") { "|") {
LuaArg tab; LuaArg tab;
LuaRet closure, rtab, key; LuaRet closure, rtab, key;
LuaStack LS(L, tab, closure, rtab, key); LuaOldStack 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 +625,7 @@ LuaDefine(table_semisortedpairs, "table",
"|") { "|") {
LuaArg tab; LuaArg tab;
LuaRet closure, rtab, key; LuaRet closure, rtab, key;
LuaStack LS(L, tab, closure, rtab, key); LuaOldStack 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 +665,7 @@ LuaDefine(genlt, "obj1,obj2",
"|") { "|") {
LuaArg o1,o2; LuaArg o1,o2;
LuaRet lt; LuaRet lt;
LuaStack LS(L, o1, o2, lt); LuaOldStack 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();

View File

@@ -16,14 +16,14 @@
// //
// True if two tables contain the same key/value pairs. // True if two tables contain the same key/value pairs.
// //
bool table_equal(LuaStack &LS0, LuaSlot tab1, LuaSlot tab2); bool table_equal(LuaCoreStack &LS0, LuaSlot tab1, LuaSlot tab2);
// table_getpairs // table_getpairs
// //
// Get a table containing the key-value pairs in tab. Optionally sort // Get a table containing the key-value pairs in tab. Optionally sort
// the pairs. Return true if all keys were sortable. // the pairs. Return true if all keys were sortable.
// //
bool table_getpairs(LuaStack &LS0, LuaSlot tab, LuaSlot pairs, bool sort); bool table_getpairs(LuaCoreStack &LS0, LuaSlot tab, LuaSlot pairs, bool sort);
#endif // TABLE_HPP #endif // TABLE_HPP

View File

@@ -5,9 +5,9 @@
#include <cmath> #include <cmath>
#include <iostream> #include <iostream>
static void tangible_getall(LuaStack &LS0, LuaSlot list, const util::IdVector &idv) { static void tangible_getall(LuaCoreStack &LS0, LuaSlot list, const util::IdVector &idv) {
LuaVar tangibles, tan; LuaVar tangibles, tan;
LuaStack LS(LS0.state(), tangibles, tan); LuaOldStack LS(LS0.state(), tangibles, tan);
LS.rawget(tangibles, LuaRegistry, "tangibles"); LS.rawget(tangibles, LuaRegistry, "tangibles");
assert(LS.istable(tangibles)); assert(LS.istable(tangibles));
LS.set(list, LuaNewTable); LS.set(list, LuaNewTable);
@@ -25,7 +25,7 @@ LuaDefine(tangible_animstate, "tan",
"|Returns six values: graphic,plane,x,y,z,facing.") { "|Returns six values: graphic,plane,x,y,z,facing.") {
LuaArg tanobj; LuaArg tanobj;
LuaRet graphic, plane, x, y, z, facing; LuaRet graphic, plane, x, y, z, facing;
LuaStack LS(L, tanobj, graphic, plane, x, y, z, facing); LuaOldStack LS(L, tanobj, graphic, plane, x, y, z, facing);
World *w = World::fetch_global_pointer(L); World *w = World::fetch_global_pointer(L);
Tangible *tan = w->tangible_get(LS, tanobj, false); Tangible *tan = w->tangible_get(LS, tanobj, false);
const AnimStep &aqback = tan->anim_queue_.back(); const AnimStep &aqback = tan->anim_queue_.back();
@@ -43,7 +43,7 @@ LuaDefine(tangible_xyz, "tan",
"|Returns three values: x, y, z") { "|Returns three values: x, y, z") {
LuaArg tanobj; LuaArg tanobj;
LuaRet x, y, z; LuaRet x, y, z;
LuaStack LS(L, tanobj, x, y, z); LuaOldStack LS(L, tanobj, x, y, z);
World *w = World::fetch_global_pointer(L); World *w = World::fetch_global_pointer(L);
Tangible *tan = w->tangible_get(LS, tanobj, false); Tangible *tan = w->tangible_get(LS, tanobj, false);
const AnimStep &aqback = tan->anim_queue_.back(); const AnimStep &aqback = tan->anim_queue_.back();
@@ -58,7 +58,7 @@ LuaDefine(tangible_animate, "tan,configtable",
"|The configtable is a table containing any of the following:" "|The configtable is a table containing any of the following:"
"|action,graphic,plane,x,y,z,facing") { "|action,graphic,plane,x,y,z,facing") {
LuaArg tanobj, config; LuaArg tanobj, config;
LuaStack LS(L, tanobj, config); LuaOldStack LS(L, tanobj, config);
LuaKeywordParser kp(LS, config); LuaKeywordParser kp(LS, config);
World *w = World::fetch_global_pointer(L); World *w = World::fetch_global_pointer(L);
Tangible *tan = w->tangible_get(LS, tanobj, false); Tangible *tan = w->tangible_get(LS, tanobj, false);
@@ -81,7 +81,7 @@ LuaDefine(tangible_setclass, "tan,class",
"|given an __index metamethod that points at the class table.") { "|given an __index metamethod that points at the class table.") {
LuaArg tanobj, classname; LuaArg tanobj, classname;
LuaVar classtab, mt; LuaVar classtab, mt;
LuaStack LS(L, tanobj, classname, classtab, mt); LuaOldStack LS(L, tanobj, classname, classtab, mt);
World *w = World::fetch_global_pointer(L); World *w = World::fetch_global_pointer(L);
w->tangible_get(LS, tanobj, false); w->tangible_get(LS, tanobj, false);
eng::string err = LS.getclass(classtab, classname); eng::string err = LS.getclass(classtab, classname);
@@ -100,7 +100,7 @@ LuaDefine(tangible_getclass, "tan",
LuaArg tanobj; LuaArg tanobj;
LuaVar mt, classtab; LuaVar mt, classtab;
LuaRet classname; LuaRet classname;
LuaStack LS(L, tanobj, mt, classtab, classname); LuaOldStack LS(L, tanobj, mt, classtab, classname);
World *w = World::fetch_global_pointer(L); World *w = World::fetch_global_pointer(L);
w->tangible_get(LS, tanobj, false); w->tangible_get(LS, tanobj, false);
LS.getmetatable(mt, tanobj); LS.getmetatable(mt, tanobj);
@@ -119,7 +119,7 @@ LuaDefine(tangible_delete, "tan",
"|This cannot be used to delete player tangibles," "|This cannot be used to delete player tangibles,"
"|To delete a player, use tangible.redirect") { "|To delete a player, use tangible.redirect") {
LuaArg tanobj; LuaArg tanobj;
LuaStack LS(L, tanobj); LuaOldStack LS(L, tanobj);
World *w = World::fetch_global_pointer(L); World *w = World::fetch_global_pointer(L);
Tangible *tan = w->tangible_get(LS, tanobj, true); Tangible *tan = w->tangible_get(LS, tanobj, true);
if (tan == nullptr) { if (tan == nullptr) {
@@ -140,7 +140,7 @@ LuaDefine(tangible_build, "config",
LuaArg config; LuaArg config;
LuaVar classname, classtab, mt; LuaVar classname, classtab, mt;
LuaRet database; LuaRet database;
LuaStack LS(L, config, classname, classtab, database, mt); LuaOldStack LS(L, config, classname, classtab, database, mt);
LuaKeywordParser kp(LS, config); LuaKeywordParser kp(LS, config);
// Get the class of the new tangible. // Get the class of the new tangible.
@@ -192,7 +192,7 @@ LuaDefine(tangible_get, "id",
LuaArg id; LuaArg id;
LuaVar tangibles; LuaVar tangibles;
LuaRet database; LuaRet database;
LuaStack LS(L, id, tangibles, database); LuaOldStack LS(L, id, tangibles, database);
int64_t nid = LS.ckinteger(id); int64_t nid = LS.ckinteger(id);
LS.rawget(tangibles, LuaRegistry, "tangibles"); LS.rawget(tangibles, LuaRegistry, "tangibles");
LS.rawget(database, tangibles, id); LS.rawget(database, tangibles, id);
@@ -205,7 +205,7 @@ LuaDefine(tangible_get, "id",
LuaDefine(tangible_redirect, "tan1,tan2,bulldozetan1", LuaDefine(tangible_redirect, "tan1,tan2,bulldozetan1",
"|Redirect is not working yet") { "|Redirect is not working yet") {
LuaArg actor1, actor2, bldz; LuaArg actor1, actor2, bldz;
LuaStack LS(L, actor1, actor2, bldz); LuaOldStack LS(L, actor1, actor2, bldz);
World *w = World::fetch_global_pointer(L); World *w = World::fetch_global_pointer(L);
bool bulldoze = LS.ckboolean(bldz); bool bulldoze = LS.ckboolean(bldz);
Tangible *tan1 = w->tangible_get(LS, actor1, false); Tangible *tan1 = w->tangible_get(LS, actor1, false);
@@ -231,7 +231,7 @@ LuaDefine(tangible_id, "tan",
"|in the released version.") { "|in the released version.") {
LuaArg tanobj; LuaArg tanobj;
LuaRet id; LuaRet id;
LuaStack LS(L, tanobj, id); LuaOldStack LS(L, tanobj, id);
int64_t tid = LS.tanid(tanobj); int64_t tid = LS.tanid(tanobj);
if (tid == 0) { if (tid == 0) {
luaL_error(L, "Not a tangible"); luaL_error(L, "Not a tangible");
@@ -244,7 +244,7 @@ LuaDefine(tangible_actor, "",
"|Return the current actor.") { "|Return the current actor.") {
LuaRet actor; LuaRet actor;
LuaVar tangibles; LuaVar tangibles;
LuaStack LS(L, tangibles, actor); LuaOldStack LS(L, tangibles, actor);
World *w = World::fetch_global_pointer(L); World *w = World::fetch_global_pointer(L);
LS.rawget(tangibles, LuaRegistry, "tangibles"); LS.rawget(tangibles, LuaRegistry, "tangibles");
LS.rawget(actor, tangibles, w->lthread_actor_id_); LS.rawget(actor, tangibles, w->lthread_actor_id_);
@@ -255,7 +255,7 @@ LuaDefine(tangible_place, "",
"|Return the current place.") { "|Return the current place.") {
LuaRet place; LuaRet place;
LuaVar tangibles; LuaVar tangibles;
LuaStack LS(L, tangibles, place); LuaOldStack LS(L, tangibles, place);
World *w = World::fetch_global_pointer(L); World *w = World::fetch_global_pointer(L);
LS.rawget(tangibles, LuaRegistry, "tangibles"); LS.rawget(tangibles, LuaRegistry, "tangibles");
LS.rawget(place, tangibles, w->lthread_place_id_); LS.rawget(place, tangibles, w->lthread_place_id_);
@@ -269,7 +269,7 @@ LuaDefine(tangible_near, "tan,radius,omit_nowhere,omit_self",
"|tangible passed in is omitted from the results.") { "|tangible passed in is omitted from the results.") {
LuaArg ltan, lradius, lomit_nowhere, lomit_self; LuaArg ltan, lradius, lomit_nowhere, lomit_self;
LuaRet list; LuaRet list;
LuaStack LS(L, ltan, lradius, lomit_nowhere, lomit_self, list); LuaOldStack LS(L, ltan, lradius, lomit_nowhere, lomit_self, list);
World *w = World::fetch_global_pointer(L); World *w = World::fetch_global_pointer(L);
Tangible *tan = w->tangible_get(LS, ltan, false); Tangible *tan = w->tangible_get(LS, ltan, false);
const AnimStep &aqback = tan->anim_queue_.back(); const AnimStep &aqback = tan->anim_queue_.back();
@@ -293,7 +293,7 @@ LuaDefine(tangible_scan, "plane,x,y,radius,omit_nowhere",
"|the scan returns empty.") { "|the scan returns empty.") {
LuaArg lplane, lx, ly, lradius, lomit_nowhere; LuaArg lplane, lx, ly, lradius, lomit_nowhere;
LuaRet list; LuaRet list;
LuaStack LS(L, lplane, lx, ly, lradius, lomit_nowhere, list); LuaOldStack LS(L, lplane, lx, ly, lradius, lomit_nowhere, list);
World *w = World::fetch_global_pointer(L); World *w = World::fetch_global_pointer(L);
PlaneScan scan; PlaneScan scan;
@@ -367,7 +367,7 @@ LuaDefine(tangible_find, "config",
"|") { "|") {
LuaArg config; LuaArg config;
LuaRet result; LuaRet result;
LuaStack LS(L, config, result); LuaOldStack LS(L, config, result);
LuaKeywordParser kw(LS, config); LuaKeywordParser kw(LS, config);
PlaneScan scan; PlaneScan scan;
scan.configure(kw); scan.configure(kw);
@@ -446,7 +446,7 @@ LuaDefine(tangible_start, "tangible,function,arg1,arg2...",
w->guard_blockable(L, "tangible.start"); w->guard_blockable(L, "tangible.start");
LuaVar mt, classtab, plthreads, thread, thinfo, func, tanlist; LuaVar mt, classtab, plthreads, thread, thinfo, func, tanlist;
LuaStack LS(L, mt, classtab, plthreads, thread, thinfo, func, tanlist); LuaOldStack LS(L, mt, classtab, plthreads, thread, thinfo, func, tanlist);
LuaSpecial place(1); LuaSpecial place(1);
LuaSpecial fname(2); LuaSpecial fname(2);
@@ -537,7 +537,7 @@ LuaDefine(wait, "nticks",
// Parse the argument. // Parse the argument.
LuaArg seconds; LuaArg seconds;
LuaStack LS(L, seconds); LuaOldStack LS(L, seconds);
int64_t n = LS.ckinteger(seconds); int64_t n = LS.ckinteger(seconds);
if ((n < 0) || (n > 1000000)) { if ((n < 0) || (n > 1000000)) {
luaL_error(L, "Argument to wait must be between 0 and 1000000"); luaL_error(L, "Argument to wait must be between 0 and 1000000");
@@ -603,7 +603,7 @@ LuaDefine(math_random, "(args...)",
highf = std::floor(lua_tonumber(L, arg)); highf = std::floor(lua_tonumber(L, arg));
arg += 1; arg += 1;
} }
if ((lowf < -LuaStack::MAXINT) || (highf > LuaStack::MAXINT)) { if ((lowf < -LuaOldStack::MAXINT) || (highf > LuaOldStack::MAXINT)) {
luaL_error(L, "math.random range exceeds MAXINT"); luaL_error(L, "math.random range exceeds MAXINT");
return 0; return 0;
} }
@@ -636,8 +636,8 @@ LuaDefine(math_random, "(args...)",
} }
double dseed = lua_tonumber(L, -2); double dseed = lua_tonumber(L, -2);
double dcount = lua_tonumber(L, -1); double dcount = lua_tonumber(L, -1);
seed = uint64_t(dseed) & LuaStack::MAXINT; seed = uint64_t(dseed) & LuaOldStack::MAXINT;
count = uint64_t(dcount) & LuaStack::MAXINT; count = uint64_t(dcount) & LuaOldStack::MAXINT;
if (dseed < 0) { if (dseed < 0) {
salt = 0x35c9a6082a097ade; salt = 0x35c9a6082a097ade;
} else { } else {
@@ -645,7 +645,7 @@ LuaDefine(math_random, "(args...)",
} }
lua_pop(L, 2); lua_pop(L, 2);
lua_pushstring(L, "count"); lua_pushstring(L, "count");
lua_pushnumber(L, double((count + 1) & LuaStack::MAXINT)); lua_pushnumber(L, double((count + 1) & LuaOldStack::MAXINT));
lua_rawset(L, 1); lua_rawset(L, 1);
} else { } else {
World *w = World::fetch_global_pointer(L); World *w = World::fetch_global_pointer(L);
@@ -692,7 +692,7 @@ LuaDefine(math_randomstate, "seed",
double seed; double seed;
if (lua_gettop(L) == 0) { if (lua_gettop(L) == 0) {
World *w = World::fetch_global_pointer(L); World *w = World::fetch_global_pointer(L);
int64_t iseed = (w->id_global_pool_.get_seqno() & LuaStack::MAXINT) + 1; int64_t iseed = (w->id_global_pool_.get_seqno() & LuaOldStack::MAXINT) + 1;
seed = -iseed; seed = -iseed;
} else if (lua_gettop(L) == 1) { } else if (lua_gettop(L) == 1) {
if (lua_type(L, 1) != LUA_TNUMBER) { if (lua_type(L, 1) != LUA_TNUMBER) {
@@ -700,7 +700,7 @@ LuaDefine(math_randomstate, "seed",
return 0; return 0;
} }
seed = lua_tonumber(L, 1); seed = lua_tonumber(L, 1);
if ((seed < 0.0) || (seed > LuaStack::MAXINT) || (std::floor(seed) != seed)) { if ((seed < 0.0) || (seed > LuaOldStack::MAXINT) || (std::floor(seed) != seed)) {
luaL_error(L, "math.randomstate seed must be an integer 0-MAXINT"); luaL_error(L, "math.randomstate seed must be an integer 0-MAXINT");
return 0; return 0;
} }
@@ -732,7 +732,7 @@ LuaDefine(pprint, "obj1, obj2, ...",
World *w = World::fetch_global_pointer(L); World *w = World::fetch_global_pointer(L);
std::ostream *ostream = w->lthread_print_stream(); std::ostream *ostream = w->lthread_print_stream();
int n = lua_gettop(L); int n = lua_gettop(L);
LuaStack LS(L); LuaOldStack LS(L);
for (int i = 1; i <= n; i++) { for (int i = 1; i <= n; i++) {
LuaSpecial root(i); LuaSpecial root(i);
pprint(LS, root, PrettyPrintOptions(), ostream); pprint(LS, root, PrettyPrintOptions(), ostream);
@@ -763,7 +763,7 @@ LuaDefine(pprintx, "options",
std::ostream *ostream = w->lthread_print_stream(); std::ostream *ostream = w->lthread_print_stream();
LuaArg loptions; LuaArg loptions;
LuaVar value; LuaVar value;
LuaStack LS(L, loptions, value); LuaOldStack LS(L, loptions, value);
PrettyPrintOptions options; PrettyPrintOptions options;
LuaKeywordParser kp(LS, loptions); LuaKeywordParser kp(LS, loptions);
options.parse(kp); options.parse(kp);
@@ -779,7 +779,7 @@ LuaDefine(print, "obj1, obj2, ...",
"|Print object or objects.") { "|Print object or objects.") {
World *w = World::fetch_global_pointer(L); World *w = World::fetch_global_pointer(L);
std::ostream *ostream = w->lthread_print_stream(); std::ostream *ostream = w->lthread_print_stream();
LuaStack LS(L); LuaOldStack LS(L);
int n = lua_gettop(L); int n = lua_gettop(L);
for (int i = 1; i <= n; i++) { for (int i = 1; i <= n; i++) {
LuaSpecial root(i); LuaSpecial root(i);
@@ -795,7 +795,7 @@ LuaDefine(doc, "function",
World *w = World::fetch_global_pointer(L); World *w = World::fetch_global_pointer(L);
std::ostream *ostream = w->lthread_print_stream(); std::ostream *ostream = w->lthread_print_stream();
LuaArg func; LuaArg func;
LuaStack LS(L, func); LuaOldStack LS(L, func);
eng::string doc = SourceDB::function_docs(LS, func); eng::string doc = SourceDB::function_docs(LS, func);
if (doc == "") { if (doc == "") {
(*ostream) << "no doc found" << std::endl; (*ostream) << "no doc found" << std::endl;
@@ -810,7 +810,7 @@ int lfn_http_request(lua_State *L, const char *method) {
LuaArg request; LuaArg request;
LuaRet response; LuaRet response;
LuaStack LS(L, request, response); LuaOldStack LS(L, request, response);
LuaKeywordParser kp(LS, request); LuaKeywordParser kp(LS, request);
HttpClientRequest req; HttpClientRequest req;
@@ -856,11 +856,11 @@ LuaDefine(http_post, "request",
return lfn_http_request(L, "POST"); return lfn_http_request(L, "POST");
} }
void global_set(LuaStack &LS0, const eng::string &gvar, LuaSlot value) { void global_set(LuaCoreStack &LS0, const eng::string &gvar, LuaSlot value) {
lua_State *L = LS0.state(); lua_State *L = LS0.state();
World *w = World::fetch_global_pointer(L); World *w = World::fetch_global_pointer(L);
LuaVar globaldb, copy; LuaVar globaldb, copy;
LuaStack LS(L, globaldb, copy); LuaOldStack LS(L, globaldb, copy);
// Serialize then deserialize the data, to produce a copy. // Serialize then deserialize the data, to produce a copy.
StreamBuffer sb; StreamBuffer sb;
@@ -936,7 +936,7 @@ LuaDefine(global_set, "varname, value",
"|") { "|") {
LuaArg varname; LuaArg varname;
LuaArg value; LuaArg value;
LuaStack LS(L, varname, value); LuaOldStack LS(L, varname, value);
// Check the varname argument. // Check the varname argument.
eng::string gvar = LS.ckstring(varname); eng::string gvar = LS.ckstring(varname);
@@ -961,7 +961,7 @@ LuaDefine(global_get, "varname",
LuaArg varname; LuaArg varname;
LuaRet value; LuaRet value;
LuaVar globaldb; LuaVar globaldb;
LuaStack LS(L, varname, value, globaldb); LuaOldStack LS(L, varname, value, globaldb);
LS.rawget(globaldb, LuaRegistry, "globaldb"); LS.rawget(globaldb, LuaRegistry, "globaldb");
LS.rawget(value, globaldb, varname); LS.rawget(value, globaldb, varname);
return LS.result(); return LS.result();
@@ -977,7 +977,7 @@ LuaDefine(global_once, "varname",
LuaArg varname; LuaArg varname;
LuaRet result; LuaRet result;
LuaVar globaldb, flag; LuaVar globaldb, flag;
LuaStack LS(L, varname, flag, result, globaldb); LuaOldStack LS(L, varname, flag, result, globaldb);
// Check the varname argument. // Check the varname argument.
eng::string gvar = LS.ckstring(varname); eng::string gvar = LS.ckstring(varname);
@@ -1009,7 +1009,7 @@ LuaDefine(global_clearonce, "varname",
"|") { "|") {
LuaArg varname; LuaArg varname;
LuaVar null; LuaVar null;
LuaStack LS(L, varname, null); LuaOldStack LS(L, varname, null);
// Check the varname argument. // Check the varname argument.
eng::string gvar = LS.ckstring(varname); eng::string gvar = LS.ckstring(varname);

View File

@@ -42,7 +42,7 @@ World::World(WorldType wt) {
// Prepare to manipulate the lua state. // Prepare to manipulate the lua state.
LuaVar world, globtab; LuaVar world, globtab;
LuaStack LS(state(), world, globtab); LuaOldStack LS(state(), world, globtab);
// Put the world pointer into the lua registry. // Put the world pointer into the lua registry.
World::store_global_pointer(state(), this); World::store_global_pointer(state(), this);
@@ -134,7 +134,7 @@ World::TanVector World::tangible_get_all(const IdVector &ids) const {
return result; return result;
} }
Tangible *World::tangible_get(const LuaStack &LS, LuaSlot tab, bool allowdel) { Tangible *World::tangible_get(const LuaCoreStack &LS, LuaSlot tab, bool allowdel) {
int64_t id = LS.tanid(tab); int64_t id = LS.tanid(tab);
if (id == 0) { if (id == 0) {
luaL_error(LS.state(), "parameter is not a tangible"); luaL_error(LS.state(), "parameter is not a tangible");
@@ -158,7 +158,7 @@ Tangible *World::tangible_make(lua_State *L, int64_t id, const eng::string &plan
LuaVar metatab; LuaVar metatab;
LuaRet database; LuaRet database;
LuaStack LS(L, database, metatab); LuaOldStack LS(L, database, metatab);
// Create the C++ part of the structure. // Create the C++ part of the structure.
UniqueTangible &t = tangibles_[id]; UniqueTangible &t = tangibles_[id];
@@ -185,7 +185,7 @@ Tangible *World::tangible_make(lua_State *L, int64_t id, const eng::string &plan
void World::tangible_delete(int64_t id) { void World::tangible_delete(int64_t id) {
lua_State *L = state(); lua_State *L = state();
LuaVar tangibles, database, metatab; LuaVar tangibles, database, metatab;
LuaStack LS(L, tangibles, database, metatab); LuaOldStack LS(L, tangibles, database, metatab);
// Fetch the C++ side of the tangible. // Fetch the C++ side of the tangible.
auto iter = tangibles_.find(id); auto iter = tangibles_.find(id);
@@ -243,7 +243,7 @@ int64_t World::create_login_actor() {
Tangible *tan = tangible_make(state(), id, "nowhere", true); Tangible *tan = tangible_make(state(), id, "nowhere", true);
LuaArg database; LuaArg database;
LuaVar classtab, mt; LuaVar classtab, mt;
LuaStack LS(state(), database, classtab, mt); LuaOldStack LS(state(), database, classtab, mt);
LS.makeclass(classtab, "login"); LS.makeclass(classtab, "login");
LS.getmetatable(mt, database); LS.getmetatable(mt, database);
LS.rawset(mt, "__index", classtab); LS.rawset(mt, "__index", classtab);
@@ -264,7 +264,7 @@ eng::string World::probe_lua(int64_t actor_id, const eng::string &lua) {
} }
LuaVar closure; LuaVar closure;
LuaStack LS(L, closure); LuaOldStack LS(L, closure);
// create the compiled closure. // create the compiled closure.
int status = luaL_loadbuffer(L, lua.c_str(), lua.size(), "=probe"); int status = luaL_loadbuffer(L, lua.c_str(), lua.size(), "=probe");
@@ -316,7 +316,7 @@ void World::update_gui(int64_t actor_id, int64_t place_id, Gui *gui) {
lua_State *L = state(); lua_State *L = state();
LuaVar actor, place, ugui, func, tangibles, mt, index; LuaVar actor, place, ugui, func, tangibles, mt, index;
LuaStack LS(L, actor, place, ugui, func, tangibles, mt, index); LuaOldStack LS(L, actor, place, ugui, func, tangibles, mt, index);
// Get the actor and place. // Get the actor and place.
LS.rawget(tangibles, LuaRegistry, "tangibles"); LS.rawget(tangibles, LuaRegistry, "tangibles");
@@ -394,7 +394,7 @@ void World::http_response(const HttpParser &response) {
// Get the place and thread as lua objects. // Get the place and thread as lua objects.
LuaVar tangibles, place, mt, threads, thinfo, thread; LuaVar tangibles, place, mt, threads, thinfo, thread;
LuaStack LS(state(), tangibles, place, mt, threads, thinfo, thread); LuaOldStack LS(state(), tangibles, place, mt, threads, thinfo, thread);
LS.rawget(tangibles, LuaRegistry, "tangibles"); LS.rawget(tangibles, LuaRegistry, "tangibles");
LS.rawget(place, tangibles, request.place_id()); LS.rawget(place, tangibles, request.place_id());
if (!LS.istable(place)) { if (!LS.istable(place)) {
@@ -420,7 +420,7 @@ void World::http_response(const HttpParser &response) {
// Push the response onto the awakening thread. // Push the response onto the awakening thread.
LuaRet responsetable; LuaRet responsetable;
LuaStack LSCO(CO, responsetable); LuaOldStack LSCO(CO, responsetable);
response.store(LSCO, responsetable); response.store(LSCO, responsetable);
// Clean up lua stacks. // Clean up lua stacks.
@@ -475,7 +475,7 @@ HttpServerResponse World::http_serve(const HttpParser &request) {
lua_State *L = state(); lua_State *L = state();
LuaVar www, func, reqtab; LuaVar www, func, reqtab;
LuaStack LS(L, www, func, reqtab); LuaOldStack LS(L, www, func, reqtab);
// Get the www class. If there's no such class, // Get the www class. If there's no such class,
// return a 503 Service Unavailable to the client. // return a 503 Service Unavailable to the client.
@@ -605,7 +605,7 @@ void World::invoke_lua(int64_t actor_id, int64_t place_id, const eng::string &ac
// Set up for lua manipulation. // Set up for lua manipulation.
lua_State *L = state(); lua_State *L = state();
LuaVar func, tangibles, place, mt, thread, thinfo, threads; LuaVar func, tangibles, place, mt, thread, thinfo, threads;
LuaStack LS(L, func, tangibles, place, mt, thread, thinfo, threads); LuaOldStack LS(L, func, tangibles, place, mt, thread, thinfo, threads);
// create the compiled closure. // create the compiled closure.
int status = luaL_loadbuffer(L, action.c_str(), action.size(), "=invoke"); int status = luaL_loadbuffer(L, action.c_str(), action.size(), "=invoke");
@@ -689,7 +689,7 @@ void World::invoke_plan(int64_t actor_id, int64_t place_id, const eng::string &a
// Set up for Lua manipulation. // Set up for Lua manipulation.
lua_State *L = state(); lua_State *L = state();
LuaVar actor, place, func, tangibles, mt, index, thread, threads, thinfo, message, invdata; LuaVar actor, place, func, tangibles, mt, index, thread, threads, thinfo, message, invdata;
LuaStack LS(L, actor, place, func, tangibles, mt, index, thread, threads, thinfo, message, invdata); LuaOldStack LS(L, actor, place, func, tangibles, mt, index, thread, threads, thinfo, message, invdata);
// Get the actor and place. // Get the actor and place.
LS.rawget(tangibles, LuaRegistry, "tangibles"); LS.rawget(tangibles, LuaRegistry, "tangibles");
@@ -794,7 +794,7 @@ void World::guard_blockable(lua_State *L, const char *fn) {
void World::guard_nopredict(lua_State *L, const char *fn) { void World::guard_nopredict(lua_State *L, const char *fn) {
// Caution: this code must be equivalent to the // Caution: this code must be equivalent to the
// code in LuaStack::guard_nopredict. // code in LuaOldStack::guard_nopredict.
if (lthread_thread_id_ == 0) { if (lthread_thread_id_ == 0) {
return; return;
} }
@@ -815,7 +815,7 @@ void World::run_scheduled_threads() {
assert(stack_is_clear()); assert(stack_is_clear());
lua_State *L = state(); lua_State *L = state();
LuaVar tangibles, place, mt, threads, thinfo, actorid, isnew, useppool, thread, print; LuaVar tangibles, place, mt, threads, thinfo, actorid, isnew, useppool, thread, print;
LuaStack LS(L, tangibles, place, mt, threads, thinfo, actorid, isnew, useppool, thread, print); LuaOldStack LS(L, tangibles, place, mt, threads, thinfo, actorid, isnew, useppool, thread, print);
LS.rawget(tangibles, LuaRegistry, "tangibles"); LS.rawget(tangibles, LuaRegistry, "tangibles");
while (thread_sched_.ready(clock_)) { while (thread_sched_.ready(clock_)) {
@@ -865,7 +865,7 @@ void World::run_scheduled_threads() {
// Remove from thread table. // Remove from thread table.
LS.rawget(print, thinfo, "print"); LS.rawget(print, thinfo, "print");
LS.rawset(threads, sched.thread_id(), LuaNil); LS.rawset(threads, sched.thread_id(), LuaNil);
LuaStack LSCO(CO); LuaOldStack LSCO(CO);
if (LS.ckboolean(print)) { if (LS.ckboolean(print)) {
for (int i = 1; i <= lua_gettop(CO); i++) { for (int i = 1; i <= lua_gettop(CO); i++) {
pprint(LSCO, LuaSpecial(i), PrettyPrintOptions(), ostream); pprint(LSCO, LuaSpecial(i), PrettyPrintOptions(), ostream);

View File

@@ -27,7 +27,7 @@
// Given a table and an tnmap, return the table number of the table. // Given a table and an tnmap, return the table number of the table.
// Returns zero if the table doesn't have a table number. // Returns zero if the table doesn't have a table number.
// //
static int get_table_number(LuaStack &MLS, LuaSlot mval, LuaSlot mtnmap) { static int get_table_number(LuaCoreStack &MLS, LuaSlot mval, LuaSlot mtnmap) {
lua_State *L = MLS.state(); lua_State *L = MLS.state();
lua_pushvalue(L, mval.index()); lua_pushvalue(L, mval.index());
lua_rawget(L, mtnmap.index()); lua_rawget(L, mtnmap.index());
@@ -40,8 +40,8 @@ static int get_table_number(LuaStack &MLS, LuaSlot mval, LuaSlot mtnmap) {
} }
static bool equivalent_values(LuaStack &MLS, LuaSlot mval, LuaSlot mtnmap, static bool equivalent_values(LuaCoreStack &MLS, LuaSlot mval, LuaSlot mtnmap,
LuaStack &SLS, LuaSlot sval, LuaSlot stnmap) { LuaCoreStack &SLS, LuaSlot sval, LuaSlot stnmap) {
switch (MLS.xtype(mval)) { switch (MLS.xtype(mval)) {
case LUA_TBOOLEAN: { case LUA_TBOOLEAN: {
if (SLS.type(sval) != LUA_TBOOLEAN) return false; if (SLS.type(sval) != LUA_TBOOLEAN) return false;
@@ -92,7 +92,7 @@ static bool equivalent_values(LuaStack &MLS, LuaSlot mval, LuaSlot mtnmap,
} }
} }
static void transmit_value(LuaStack &MLS, LuaSlot mval, LuaSlot mtnmap, StreamBuffer *sb) { static void transmit_value(LuaCoreStack &MLS, LuaSlot mval, LuaSlot mtnmap, StreamBuffer *sb) {
switch (MLS.xtype(mval)) { switch (MLS.xtype(mval)) {
case LUA_TBOOLEAN: { case LUA_TBOOLEAN: {
sb->write_uint8(LUA_TBOOLEAN); sb->write_uint8(LUA_TBOOLEAN);
@@ -189,12 +189,12 @@ static void transmit_value_debug_string(StreamBuffer *sb, eng::ostringstream &os
} }
} }
static bool diff_tables(LuaStack &SLS0, LuaSlot stnmap, LuaSlot stab, static bool diff_tables(LuaCoreStack &SLS0, LuaSlot stnmap, LuaSlot stab,
LuaStack &MLS0, LuaSlot mtnmap, LuaSlot mtab, LuaCoreStack &MLS0, LuaSlot mtnmap, LuaSlot mtab,
bool cmeta, StreamBuffer *sb) { bool cmeta, StreamBuffer *sb) {
LuaVar skey, mkey, sval, mval, mnil; LuaVar skey, mkey, sval, mval, mnil;
LuaStack SLS(SLS0.state(), skey, sval); LuaOldStack SLS(SLS0.state(), skey, sval);
LuaStack MLS(MLS0.state(), mkey, mval, mnil); LuaOldStack MLS(MLS0.state(), mkey, mval, mnil);
assert(MLS.istable(mtab)); assert(MLS.istable(mtab));
assert(SLS.istable(stab)); assert(SLS.istable(stab));
MLS.set(mnil, LuaNil); MLS.set(mnil, LuaNil);
@@ -262,7 +262,7 @@ static eng::string diff_tables_debug_string(StreamBuffer *sb) {
return oss.str(); return oss.str();
} }
static void set_transmitted_value(LuaStack &LS, LuaSlot tangibles, LuaSlot ntmap, LuaSlot target, StreamBuffer *sb, const char *dbinfo, DebugCollector *dbc) { static void set_transmitted_value(LuaCoreStack &LS, LuaSlot tangibles, LuaSlot ntmap, LuaSlot target, StreamBuffer *sb, const char *dbinfo, DebugCollector *dbc) {
int kind = sb->read_uint8(); int kind = sb->read_uint8();
switch (kind) { switch (kind) {
case LUA_TBOOLEAN: { case LUA_TBOOLEAN: {
@@ -322,9 +322,9 @@ static void set_transmitted_value(LuaStack &LS, LuaSlot tangibles, LuaSlot ntmap
} }
} }
static void patch_table(LuaStack &LS0, LuaSlot tangibles, LuaSlot ntmap, LuaSlot tab, StreamBuffer *sb, DebugCollector *dbc) { static void patch_table(LuaCoreStack &LS0, LuaSlot tangibles, LuaSlot ntmap, LuaSlot tab, StreamBuffer *sb, DebugCollector *dbc) {
LuaVar key, val; LuaVar key, val;
LuaStack LS(LS0.state(), key, val); LuaOldStack LS(LS0.state(), key, val);
int ndiffs = sb->read_int32(); int ndiffs = sb->read_int32();
for (int i = 0; i < ndiffs; i++) { for (int i = 0; i < ndiffs; i++) {
set_transmitted_value(LS, tangibles, ntmap, key, sb, "key=", dbc); set_transmitted_value(LS, tangibles, ntmap, key, sb, "key=", dbc);
@@ -341,7 +341,7 @@ static void patch_table(LuaStack &LS0, LuaSlot tangibles, LuaSlot ntmap, LuaSlot
void World::patch_numbered_tables(StreamBuffer *sb, DebugCollector *dbc) { void World::patch_numbered_tables(StreamBuffer *sb, DebugCollector *dbc) {
lua_State *L = state(); lua_State *L = state();
LuaVar tangibles, ntmap, tab; LuaVar tangibles, ntmap, tab;
LuaStack LS(L, tangibles, ntmap, tab); LuaOldStack LS(L, tangibles, ntmap, tab);
LS.rawget(tangibles, LuaRegistry, "tangibles"); LS.rawget(tangibles, LuaRegistry, "tangibles");
LS.rawget(ntmap, LuaRegistry, "ntmap"); LS.rawget(ntmap, LuaRegistry, "ntmap");
assert(LS.istable(tangibles)); assert(LS.istable(tangibles));
@@ -361,8 +361,8 @@ void World::patch_numbered_tables(StreamBuffer *sb, DebugCollector *dbc) {
void World::diff_numbered_tables(lua_State *master, StreamBuffer *sb) { void World::diff_numbered_tables(lua_State *master, StreamBuffer *sb) {
lua_State *synch = state(); lua_State *synch = state();
LuaVar sntmap, mntmap, stnmap, mtnmap, stab, mtab; LuaVar sntmap, mntmap, stnmap, mtnmap, stab, mtab;
LuaStack SLS(synch, sntmap, stnmap, stab); LuaOldStack SLS(synch, sntmap, stnmap, stab);
LuaStack MLS(master, mntmap, mtnmap, mtab); LuaOldStack MLS(master, mntmap, mtnmap, mtab);
SLS.rawget(sntmap, LuaRegistry, "ntmap"); SLS.rawget(sntmap, LuaRegistry, "ntmap");
MLS.rawget(mntmap, LuaRegistry, "ntmap"); MLS.rawget(mntmap, LuaRegistry, "ntmap");
SLS.rawget(stnmap, LuaRegistry, "tnmap"); SLS.rawget(stnmap, LuaRegistry, "tnmap");
@@ -400,7 +400,7 @@ void World::diff_numbered_tables(lua_State *master, StreamBuffer *sb) {
void World::patch_tangible_databases(StreamBuffer *sb, DebugCollector *dbc) { void World::patch_tangible_databases(StreamBuffer *sb, DebugCollector *dbc) {
lua_State *L = state(); lua_State *L = state();
LuaVar tangibles, ntmap, tab; LuaVar tangibles, ntmap, tab;
LuaStack LS(L, tangibles, ntmap, tab); LuaOldStack LS(L, tangibles, ntmap, tab);
LS.rawget(tangibles, LuaRegistry, "tangibles"); LS.rawget(tangibles, LuaRegistry, "tangibles");
LS.rawget(ntmap, LuaRegistry, "ntmap"); LS.rawget(ntmap, LuaRegistry, "ntmap");
assert(LS.istable(tangibles)); assert(LS.istable(tangibles));
@@ -420,8 +420,8 @@ void World::patch_tangible_databases(StreamBuffer *sb, DebugCollector *dbc) {
void World::diff_tangible_databases(const IdVector &basis, lua_State *master, StreamBuffer *sb) { void World::diff_tangible_databases(const IdVector &basis, lua_State *master, StreamBuffer *sb) {
lua_State *synch = state(); lua_State *synch = state();
LuaVar stnmap, mtnmap, stangibles, mtangibles, stab, mtab; LuaVar stnmap, mtnmap, stangibles, mtangibles, stab, mtab;
LuaStack SLS(synch, stnmap, stangibles, stab); LuaOldStack SLS(synch, stnmap, stangibles, stab);
LuaStack MLS(master, mtnmap, mtangibles, mtab); LuaOldStack MLS(master, mtnmap, mtangibles, mtab);
SLS.rawget(stnmap, LuaRegistry, "tnmap"); SLS.rawget(stnmap, LuaRegistry, "tnmap");
MLS.rawget(mtnmap, LuaRegistry, "tnmap"); MLS.rawget(mtnmap, LuaRegistry, "tnmap");
SLS.rawget(stangibles, LuaRegistry, "tangibles"); SLS.rawget(stangibles, LuaRegistry, "tangibles");
@@ -456,7 +456,7 @@ LuaDefine(table_diffcompare, "mtnmap,mtab,stnmap,stab", "for unit testing only")
LuaArg mtnmap, mtab, mstnmap, mstab; LuaArg mtnmap, mtab, mstnmap, mstab;
LuaRet dbgstring; LuaRet dbgstring;
LuaVar tthread; LuaVar tthread;
LuaStack MLS(L, mtnmap, mtab, mstnmap, mstab, dbgstring, tthread); LuaOldStack MLS(L, mtnmap, mtab, mstnmap, mstab, dbgstring, tthread);
// Check the arguments. // Check the arguments.
MLS.checktable(mtnmap, "mtnmap"); MLS.checktable(mtnmap, "mtnmap");
MLS.checktable(mstnmap, "mstnmap"); MLS.checktable(mstnmap, "mstnmap");
@@ -471,7 +471,7 @@ LuaDefine(table_diffcompare, "mtnmap,mtab,stnmap,stab", "for unit testing only")
lua_pushvalue(L, mstab.index()); lua_pushvalue(L, mstab.index());
lua_xmove(L, synch, 2); lua_xmove(L, synch, 2);
LuaArg stnmap,stab; LuaArg stnmap,stab;
LuaStack SLS(synch, stnmap, stab); LuaOldStack SLS(synch, stnmap, stab);
// Call tablecmp_diff. // Call tablecmp_diff.
StreamBuffer sb; StreamBuffer sb;
@@ -486,7 +486,7 @@ LuaDefine(table_diffapply, "mtnmap,mtab,mstab", "for unit testing only") {
LuaArg mtnmap, mtab, mstab; LuaArg mtnmap, mtab, mstab;
LuaRet eql, eqlstr, rtab; LuaRet eql, eqlstr, rtab;
LuaVar tthread, tangibles, mntmap, key, val; LuaVar tthread, tangibles, mntmap, key, val;
LuaStack MLS(L, mtnmap, mtab, mstab, eql, eqlstr, rtab, tthread, tangibles, mntmap, key, val); LuaOldStack MLS(L, mtnmap, mtab, mstab, eql, eqlstr, rtab, tthread, tangibles, mntmap, key, val);
// Check the arguments. // Check the arguments.
MLS.checktable(mtnmap, "mtnmap"); MLS.checktable(mtnmap, "mtnmap");
MLS.checktable(mtab, "mtab"); MLS.checktable(mtab, "mtab");
@@ -510,7 +510,7 @@ LuaDefine(table_diffapply, "mtnmap,mtab,mstab", "for unit testing only") {
lua_pushvalue(L, mstab.index()); lua_pushvalue(L, mstab.index());
lua_xmove(L, synch, 2); lua_xmove(L, synch, 2);
LuaArg stnmap, stab; LuaArg stnmap, stab;
LuaStack SLS(synch, stnmap, stab); LuaOldStack SLS(synch, stnmap, stab);
// Call diff_tables and patch_tables // Call diff_tables and patch_tables
StreamBuffer sb; StreamBuffer sb;

View File

@@ -224,7 +224,7 @@ void World::patch_tanclass(StreamBuffer *sb, DebugCollector *dbc) {
DebugBlock dbb(dbc, "patch_tanclass"); DebugBlock dbb(dbc, "patch_tanclass");
lua_State *L = state(); lua_State *L = state();
LuaVar tangibles, tab, meta, sclass; LuaVar tangibles, tab, meta, sclass;
LuaStack LS(L, tangibles, tab, meta, sclass); LuaOldStack LS(L, tangibles, tab, meta, sclass);
LS.rawget(tangibles, LuaRegistry, "tangibles"); LS.rawget(tangibles, LuaRegistry, "tangibles");
int nmodified = sb->read_int32(); int nmodified = sb->read_int32();
@@ -249,8 +249,8 @@ void World::diff_tanclass(int64_t actor_id, World *master, StreamBuffer *xsb) {
StreamBuffer tsb; StreamBuffer tsb;
LuaVar stangibles, mtangibles, stab, mtab, smeta, mmeta, sclass, mclass; LuaVar stangibles, mtangibles, stab, mtab, smeta, mmeta, sclass, mclass;
LuaStack SLS(state(), stangibles, stab, smeta, sclass); LuaOldStack SLS(state(), stangibles, stab, smeta, sclass);
LuaStack MLS(master->state(), mtangibles, mtab, mmeta, mclass); LuaOldStack MLS(master->state(), mtangibles, mtab, mmeta, mclass);
SLS.rawget(stangibles, LuaRegistry, "tangibles"); SLS.rawget(stangibles, LuaRegistry, "tangibles");
MLS.rawget(mtangibles, LuaRegistry, "tangibles"); MLS.rawget(mtangibles, LuaRegistry, "tangibles");

View File

@@ -21,7 +21,7 @@ int World::number_lua_tables(const IdVector &basis) {
// explicit stack (the lua stack). // explicit stack (the lua stack).
lua_State *L = state(); lua_State *L = state();
LuaVar tnmap, ntmap, tangibles, tab, key, val, xid; LuaVar tnmap, ntmap, tangibles, tab, key, val, xid;
LuaStack LS(L, tnmap, ntmap, tangibles, tab, key, val, xid); LuaOldStack LS(L, tnmap, ntmap, tangibles, tab, key, val, xid);
LS.set(tnmap, LuaNewTable); LS.set(tnmap, LuaNewTable);
LS.set(ntmap, LuaNewTable); LS.set(ntmap, LuaNewTable);
LS.rawset(LuaRegistry, "tnmap", tnmap); LS.rawset(LuaRegistry, "tnmap", tnmap);
@@ -79,8 +79,8 @@ int World::number_lua_tables(const IdVector &basis) {
void World::pair_lua_tables(const IdVector &basis, lua_State *master) { void World::pair_lua_tables(const IdVector &basis, lua_State *master) {
lua_State *synch = state(); lua_State *synch = state();
LuaVar stangibles, mtangibles, sntmap, mntmap, stnmap, mtnmap, stab, mtab, skey, mkey, sval, mval, sidx, midx; LuaVar stangibles, mtangibles, sntmap, mntmap, stnmap, mtnmap, stab, mtab, skey, mkey, sval, mval, sidx, midx;
LuaStack SLS(synch, stangibles, stab, skey, sval, sntmap, stnmap, sidx); LuaOldStack SLS(synch, stangibles, stab, skey, sval, sntmap, stnmap, sidx);
LuaStack MLS(master, mtangibles, mtab, mkey, mval, mntmap, mtnmap, midx); LuaOldStack MLS(master, mtangibles, mtab, mkey, mval, mntmap, mtnmap, midx);
// Fetch the tangible databases // Fetch the tangible databases
SLS.rawget(stangibles, LuaRegistry, "tangibles"); SLS.rawget(stangibles, LuaRegistry, "tangibles");
@@ -178,7 +178,7 @@ int World::number_remaining_tables(const IdVector &basis, lua_State *master) {
// explicit stack (the lua stack). // explicit stack (the lua stack).
lua_State *L = master; lua_State *L = master;
LuaVar tnmap, ntmap, tangibles, tab, key, val, xid; LuaVar tnmap, ntmap, tangibles, tab, key, val, xid;
LuaStack LS(L, tnmap, ntmap, tangibles, tab, key, val, xid); LuaOldStack LS(L, tnmap, ntmap, tangibles, tab, key, val, xid);
LS.rawget(tnmap, LuaRegistry, "tnmap"); LS.rawget(tnmap, LuaRegistry, "tnmap");
LS.rawget(ntmap, LuaRegistry, "ntmap"); LS.rawget(ntmap, LuaRegistry, "ntmap");
LS.rawget(tangibles, LuaRegistry, "tangibles"); LS.rawget(tangibles, LuaRegistry, "tangibles");
@@ -242,7 +242,7 @@ int World::number_remaining_tables(const IdVector &basis, lua_State *master) {
void World::create_new_tables(int n) { void World::create_new_tables(int n) {
LuaVar tnmap, ntmap, tab; LuaVar tnmap, ntmap, tab;
LuaStack LS(state(), tnmap, ntmap, tab); LuaOldStack LS(state(), tnmap, ntmap, tab);
LS.rawget(tnmap, LuaRegistry, "tnmap"); LS.rawget(tnmap, LuaRegistry, "tnmap");
LS.rawget(ntmap, LuaRegistry, "ntmap"); LS.rawget(ntmap, LuaRegistry, "ntmap");
assert(LS.istable(tnmap)); assert(LS.istable(tnmap));
@@ -261,7 +261,7 @@ void World::create_new_tables(int n) {
void World::unnumber_lua_tables() { void World::unnumber_lua_tables() {
// All we have to do is remove these tables from the registry. // All we have to do is remove these tables from the registry.
LuaStack LS(state()); LuaOldStack LS(state());
LS.rawset(LuaRegistry, "tnmap", LuaNil); LS.rawset(LuaRegistry, "tnmap", LuaNil);
LS.rawset(LuaRegistry, "ntmap", LuaNil); LS.rawset(LuaRegistry, "ntmap", LuaNil);
} }

View File

@@ -50,7 +50,7 @@ eng::string World::tangibles_near_debug_string(int64_t actor, int64_t distance)
eng::string World::tangible_pprint(int64_t id) const { eng::string World::tangible_pprint(int64_t id) const {
lua_State *L = state(); lua_State *L = state();
LuaVar tangibles, tan, meta; LuaVar tangibles, tan, meta;
LuaStack LS(L, tangibles, tan, meta); LuaOldStack LS(L, tangibles, tan, meta);
LS.rawget(tangibles, LuaRegistry, "tangibles"); LS.rawget(tangibles, LuaRegistry, "tangibles");
LS.rawget(tan, tangibles, id); LS.rawget(tan, tangibles, id);
eng::ostringstream oss; eng::ostringstream oss;
@@ -68,7 +68,7 @@ eng::string World::tangible_pprint(int64_t id) const {
eng::string World::numbered_tables_debug_string() const { eng::string World::numbered_tables_debug_string() const {
lua_State *L = state(); lua_State *L = state();
LuaVar ntmap, tab, tid; LuaVar ntmap, tab, tid;
LuaStack LS(L, ntmap, tab, tid); LuaOldStack LS(L, ntmap, tab, tid);
eng::vector<eng::string> result; eng::vector<eng::string> result;
eng::ostringstream oss; eng::ostringstream oss;
@@ -98,8 +98,8 @@ eng::string World::numbered_tables_debug_string() const {
eng::string World::paired_tables_debug_string(lua_State *master) const { eng::string World::paired_tables_debug_string(lua_State *master) const {
lua_State *synch = state(); lua_State *synch = state();
LuaVar mntmap, sntmap, mtab, stab, mtid, stid; LuaVar mntmap, sntmap, mtab, stab, mtid, stid;
LuaStack MLS(master, mntmap, mtab, mtid); LuaOldStack MLS(master, mntmap, mtab, mtid);
LuaStack SLS(synch, sntmap, stab, stid); LuaOldStack SLS(synch, sntmap, stab, stid);
eng::vector<std::pair<eng::string, eng::string>> result; eng::vector<std::pair<eng::string, eng::string>> result;
eng::ostringstream oss; eng::ostringstream oss;
@@ -139,7 +139,7 @@ eng::string World::paired_tables_debug_string(lua_State *master) const {
void World::tangible_set_string(int64_t id, const eng::string &path, const eng::string &value) { void World::tangible_set_string(int64_t id, const eng::string &path, const eng::string &value) {
lua_State *L = state(); lua_State *L = state();
LuaVar tangibles, tab, subtab; LuaVar tangibles, tab, subtab;
LuaStack LS(L, tangibles, tab, subtab); LuaOldStack LS(L, tangibles, tab, subtab);
// Fetch the lua side of the tangible. // Fetch the lua side of the tangible.
LS.rawget(tangibles, LuaRegistry, "tangibles"); LS.rawget(tangibles, LuaRegistry, "tangibles");
@@ -172,7 +172,7 @@ void World::tangible_set_string(int64_t id, const eng::string &path, const eng::
void World::tangible_copy_global(int64_t id, const eng::string &path, const eng::string &global) { void World::tangible_copy_global(int64_t id, const eng::string &path, const eng::string &global) {
lua_State *L = state(); lua_State *L = state();
LuaVar tangibles, tab, subtab, globtab, value; LuaVar tangibles, tab, subtab, globtab, value;
LuaStack LS(L, tangibles, tab, subtab, globtab, value); LuaOldStack LS(L, tangibles, tab, subtab, globtab, value);
// Fetch the lua side of the tangible. // Fetch the lua side of the tangible.
LS.rawget(tangibles, LuaRegistry, "tangibles"); LS.rawget(tangibles, LuaRegistry, "tangibles");
@@ -205,7 +205,7 @@ void World::tangible_copy_global(int64_t id, const eng::string &path, const eng:
void World::tangible_set_class(int64_t id, const eng::string &c) const { void World::tangible_set_class(int64_t id, const eng::string &c) const {
LuaVar tangibles, tan, meta, sclass; LuaVar tangibles, tan, meta, sclass;
LuaStack LS(state(), tangibles, tan, meta, sclass); LuaOldStack LS(state(), tangibles, tan, meta, sclass);
LS.rawget(tangibles, LuaRegistry, "tangibles"); LS.rawget(tangibles, LuaRegistry, "tangibles");
LS.rawget(tan, tangibles, id); LS.rawget(tan, tangibles, id);
assert(LS.istable(tan)); assert(LS.istable(tan));
@@ -221,7 +221,7 @@ void World::tangible_set_class(int64_t id, const eng::string &c) const {
eng::string World::tangible_get_class(int64_t id) const { eng::string World::tangible_get_class(int64_t id) const {
LuaVar tangibles, tan, meta, sclass; LuaVar tangibles, tan, meta, sclass;
LuaStack LS(state(), tangibles, tan, meta, sclass); LuaOldStack LS(state(), tangibles, tan, meta, sclass);
LS.rawget(tangibles, LuaRegistry, "tangibles"); LS.rawget(tangibles, LuaRegistry, "tangibles");
LS.rawget(tan, tangibles, id); LS.rawget(tan, tangibles, id);
assert(LS.istable(tan)); assert(LS.istable(tan));

View File

@@ -151,7 +151,7 @@ public:
// a deleted tangible. In that case, this function returns nullptr, // a deleted tangible. In that case, this function returns nullptr,
// but this is not a Lua error. // but this is not a Lua error.
// //
Tangible *tangible_get(const LuaStack &LS, LuaSlot slot, bool allowdel); Tangible *tangible_get(const LuaCoreStack &LS, LuaSlot slot, bool allowdel);
// Get pointers to many tangibles. // Get pointers to many tangibles.
// //
@@ -240,7 +240,7 @@ public:
// Check if the world is authoritative. // Check if the world is authoritative.
// //
bool is_authoritative() const { return LuaStack::is_authoritative(world_type_); } bool is_authoritative() const { return LuaOldStack::is_authoritative(world_type_); }
// Get a table showing all outstanding HTTP requests. // Get a table showing all outstanding HTTP requests.
// //
@@ -560,7 +560,7 @@ private:
std::unique_ptr<eng::ostringstream> lthread_prints_; std::unique_ptr<eng::ostringstream> lthread_prints_;
friend class Tangible; friend class Tangible;
friend void global_set(LuaStack &LS0, const eng::string &gvar, LuaSlot value); friend void global_set(LuaCoreStack &LS0, const eng::string &gvar, LuaSlot value);
friend int lfn_tangible_animate(lua_State *L); friend int lfn_tangible_animate(lua_State *L);
friend int lfn_tangible_build(lua_State *L); friend int lfn_tangible_build(lua_State *L);
friend int lfn_tangible_redirect(lua_State *L); friend int lfn_tangible_redirect(lua_State *L);