Lots of work on documenting class LuaStack
This commit is contained in:
@@ -85,7 +85,7 @@ static bool encode_nil(lua_State *L, eng::ostringstream &oss) {
|
|||||||
|
|
||||||
static bool encode_token(lua_State *L, eng::ostringstream &oss) {
|
static bool encode_token(lua_State *L, eng::ostringstream &oss) {
|
||||||
LuaToken token(lua_touserdata(L, -1));
|
LuaToken token(lua_touserdata(L, -1));
|
||||||
if (token == LuaToken("jsonnull")) {
|
if (token == ltoken_json_null) {
|
||||||
oss << "null";
|
oss << "null";
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
@@ -312,7 +312,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 (!LuaCoreStack::int64_storable(i)) return false;
|
if (!LuaCoreStack::validinteger(i)) return false;
|
||||||
lua_pushnumber(L, double(i));
|
lua_pushnumber(L, double(i));
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
@@ -362,7 +362,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 (!LuaCoreStack::int64_storable(i)) {
|
if (!LuaCoreStack::validinteger(i)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
lua_pushnumber(L, double(i));
|
lua_pushnumber(L, double(i));
|
||||||
|
|||||||
@@ -88,6 +88,9 @@ lua_State *LuaCoreStack::newstate (lua_Alloc allocf) {
|
|||||||
lua_pushstring(L, "tangibles");
|
lua_pushstring(L, "tangibles");
|
||||||
lua_newtable(L);
|
lua_newtable(L);
|
||||||
lua_rawset(L, LUA_REGISTRYINDEX);
|
lua_rawset(L, LUA_REGISTRYINDEX);
|
||||||
|
lua_pushstring(L, "worldtype");
|
||||||
|
lua_pushnumber(L, WORLD_TYPE_MASTER);
|
||||||
|
lua_rawset(L, LUA_REGISTRYINDEX);
|
||||||
|
|
||||||
return L;
|
return L;
|
||||||
}
|
}
|
||||||
@@ -299,14 +302,14 @@ bool LuaCoreStack::getmetatable(LuaSlot mt, LuaSlot tab) const {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int LuaCoreStack::next(LuaSlot tab, LuaSlot key, LuaSlot value) const {
|
bool LuaCoreStack::next(LuaSlot tab, LuaSlot key, LuaSlot value) const {
|
||||||
lua_pushvalue(L_, key);
|
lua_pushvalue(L_, key);
|
||||||
int ret = lua_next(L_, tab);
|
int ret = lua_next(L_, tab);
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
lua_replace(L_, value);
|
lua_replace(L_, value);
|
||||||
lua_replace(L_, key);
|
lua_replace(L_, key);
|
||||||
}
|
}
|
||||||
return ret;
|
return (ret != 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LuaCoreStack::getglobaltable(LuaSlot target) const {
|
void LuaCoreStack::getglobaltable(LuaSlot target) const {
|
||||||
@@ -334,14 +337,6 @@ bool LuaCoreStack::valididentifier(std::string_view str) {
|
|||||||
return sv::is_lua_id(str);
|
return sv::is_lua_id(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool LuaCoreStack::validint64(int64_t value) {
|
|
||||||
return (value <= MAXINT) && (value >= -MAXINT);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool LuaCoreStack::validpositiveint64(int64_t value) {
|
|
||||||
return (value <= MAXINT) && (value >= 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool LuaCoreStack::validclassname(std::string_view cname) {
|
bool LuaCoreStack::validclassname(std::string_view cname) {
|
||||||
if (cname == "_G") return false;
|
if (cname == "_G") return false;
|
||||||
return valididentifier(cname);
|
return valididentifier(cname);
|
||||||
@@ -473,7 +468,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 {
|
||||||
assert(validpositiveint64(id));
|
assert(validpositiveinteger(id));
|
||||||
|
|
||||||
LuaVar tangibles, metatab;
|
LuaVar tangibles, metatab;
|
||||||
LuaExtStack LS(L_, tangibles, metatab);
|
LuaExtStack LS(L_, tangibles, metatab);
|
||||||
@@ -627,7 +622,7 @@ void LuaCoreStack::setvisited(LuaSlot tab, bool visited) const {
|
|||||||
lua_modflagbits(L_, tab.index(), 0x0010, visited ? 0x0010 : 0);
|
lua_modflagbits(L_, tab.index(), 0x0010, visited ? 0x0010 : 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
WorldType LuaCoreStack::world_type() const {
|
WorldType LuaCoreStack::get_world_type() const {
|
||||||
lua_pushstring(L_, "worldtype");
|
lua_pushstring(L_, "worldtype");
|
||||||
lua_rawget(L_, LUA_REGISTRYINDEX);
|
lua_rawget(L_, LUA_REGISTRYINDEX);
|
||||||
lua_Integer n = lua_tointeger(L_, -1);
|
lua_Integer n = lua_tointeger(L_, -1);
|
||||||
@@ -636,6 +631,12 @@ WorldType LuaCoreStack::world_type() const {
|
|||||||
return (WorldType)n;
|
return (WorldType)n;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void LuaCoreStack::set_world_type(WorldType t) const {
|
||||||
|
lua_pushstring(L_, "worldtype");
|
||||||
|
lua_pushnumber(L_, (int)t);
|
||||||
|
lua_rawset(L_, LUA_REGISTRYINDEX);
|
||||||
|
}
|
||||||
|
|
||||||
void LuaCoreStack::guard_nopredict(const char *fn) {
|
void LuaCoreStack::guard_nopredict(const char *fn) {
|
||||||
if (lua_isyieldable(L_)) {
|
if (lua_isyieldable(L_)) {
|
||||||
if (!is_authoritative()) {
|
if (!is_authoritative()) {
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -81,7 +81,7 @@ class Deserializer {
|
|||||||
}
|
}
|
||||||
case LUA_TT_TANGIBLE: {
|
case LUA_TT_TANGIBLE: {
|
||||||
int64_t tanid = sb_->read_int64();
|
int64_t tanid = sb_->read_int64();
|
||||||
if (!LS_.validpositiveint64(tanid)) {
|
if (!LS_.validpositiveinteger(tanid)) {
|
||||||
throw DeserializeError();
|
throw DeserializeError();
|
||||||
}
|
}
|
||||||
LS_.maketan(target, tanid);
|
LS_.maketan(target, tanid);
|
||||||
|
|||||||
@@ -32,6 +32,13 @@
|
|||||||
#include <cstdarg>
|
#include <cstdarg>
|
||||||
#include "spookyv2.hpp"
|
#include "spookyv2.hpp"
|
||||||
|
|
||||||
|
|
||||||
|
enum WorldType {
|
||||||
|
WORLD_TYPE_MASTER = 1,
|
||||||
|
WORLD_TYPE_PREDICTIVE = 2,
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
namespace sv {
|
namespace sv {
|
||||||
|
|
||||||
// Bring this into our namespace.
|
// Bring this into our namespace.
|
||||||
@@ -320,6 +327,9 @@ double distance_squared(double x1, double y1, double x2, double y2);
|
|||||||
// Make a LuaSourceVec with one element, for unit testing.
|
// Make a LuaSourceVec with one element, for unit testing.
|
||||||
LuaSourcePtr make_lua_source(const eng::string &code);
|
LuaSourcePtr make_lua_source(const eng::string &code);
|
||||||
|
|
||||||
|
// Return true if the worldtype is authoritative.
|
||||||
|
inline bool is_authoritative(WorldType t) { return (t == WORLD_TYPE_MASTER); }
|
||||||
|
|
||||||
// Remove items from a vector that are nullptr.
|
// Remove items from a vector that are nullptr.
|
||||||
template<class T>
|
template<class T>
|
||||||
void remove_nullptrs(T &vec) {
|
void remove_nullptrs(T &vec) {
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ World::World(WorldType wt) {
|
|||||||
LS.settabletype(globtab, LUA_TT_GLOBALENV);
|
LS.settabletype(globtab, LUA_TT_GLOBALENV);
|
||||||
|
|
||||||
// Store the world type in the registry.
|
// Store the world type in the registry.
|
||||||
LS.rawset(LuaRegistry, "worldtype", wt);
|
LS.set_world_type(wt);
|
||||||
|
|
||||||
// Create the globaldb in the registry.
|
// Create the globaldb in the registry.
|
||||||
LS.rawset(LuaRegistry, "globaldb", LuaNewTable);
|
LS.rawset(LuaRegistry, "globaldb", LuaNewTable);
|
||||||
@@ -141,7 +141,7 @@ Tangible *World::tangible_get(const LuaCoreStack &LS, LuaSlot tab, bool allowdel
|
|||||||
}
|
}
|
||||||
|
|
||||||
Tangible *World::tangible_make(const LuaCoreStack &LS0, LuaSlot database, int64_t id) {
|
Tangible *World::tangible_make(const LuaCoreStack &LS0, LuaSlot database, int64_t id) {
|
||||||
assert(LS0.validpositiveint64(id));
|
assert(LS0.validpositiveinteger(id));
|
||||||
LuaVar metatab;
|
LuaVar metatab;
|
||||||
LuaExtStack LS(LS0.state(), metatab);
|
LuaExtStack LS(LS0.state(), metatab);
|
||||||
|
|
||||||
|
|||||||
@@ -308,7 +308,7 @@ public:
|
|||||||
|
|
||||||
// Check if the world is authoritative.
|
// Check if the world is authoritative.
|
||||||
//
|
//
|
||||||
bool is_authoritative() const { return LuaCoreStack::is_authoritative(world_type_); }
|
bool is_authoritative() const { return util::is_authoritative(world_type_); }
|
||||||
|
|
||||||
// Get a table showing all outstanding HTTP requests.
|
// Get a table showing all outstanding HTTP requests.
|
||||||
//
|
//
|
||||||
|
|||||||
Reference in New Issue
Block a user