God knows what's modified

This commit is contained in:
2021-01-02 13:31:18 -05:00
parent c751678179
commit b03aada315
22 changed files with 1577 additions and 294 deletions

View File

@@ -3,6 +3,26 @@
LuaSpecial LuaRegistry(LUA_REGISTRYINDEX);
LuaSpecial LuaGlobals(LUA_GLOBALSINDEX);
LuaNilMarker LuaNil;
LuaNewTableMarker LuaNewTable;
LuaDiscardMarker LuaDiscard;
LuaFunctionReg *LuaFunctionReg::LuaFunctionRegistry;
LuaFunctionReg::LuaFunctionReg(const char *m, const char *n, lua_CFunction f) {
mode_ = m;
name_ = n;
func_ = f;
next_ = LuaFunctionRegistry;
LuaFunctionRegistry = this;
}
LuaFunctionReg::List LuaFunctionReg::all() {
LuaFunctionReg::List result;
for (const LuaFunctionReg *r = LuaFunctionRegistry; r != 0; r = r->next_) {
result.push_back(r);
}
return result;
}
void LuaStack::count_slots_finalize(int narg, int nvar, int nret) {
narg_ = narg;
@@ -39,33 +59,45 @@ int LuaStack::result() {
return nret_;
}
LuaFunctionReg *LuaFunctionReg::LuaFunctionRegistry;
LuaFunctionReg::LuaFunctionReg(int m, const char *n, lua_CFunction f) {
mode_ = m;
name_ = n;
func_ = f;
next_ = LuaFunctionRegistry;
LuaFunctionRegistry = this;
void LuaStack::pop_any_value(std::string &s) const {
size_t len;
const char *str = luaL_cklstring(L_, -1, &len);
s = std::string(str, len);
lua_pop(L_, 1);
}
LuaFunctionReg::List LuaFunctionReg::all() {
LuaFunctionReg::List result;
for (const LuaFunctionReg *r = LuaFunctionRegistry; r != 0; r = r->next_) {
result.push_back(r);
void LuaStack::pop_any_value(LuaAcceptNilNumber &s) const {
if (lua_isnil(L_, -1)) {
s.v = 0.0;
} else {
s.v = luaL_cknumber(L_, -1);
}
return result;
lua_pop(L_, 1);
}
std::string LuaStack::tostring(LuaSlot s) const {
size_t len;
const char *str = lua_tolstring(L_, s, &len);
return std::string(str, len);
void LuaStack::pop_any_value(LuaAcceptNilInteger &s) const {
if (lua_isnil(L_, -1)) {
s.v = 0;
} else {
s.v = luaL_ckinteger(L_, -1);
}
lua_pop(L_, 1);
}
std::string LuaStack::checkstring(LuaSlot s) const {
void LuaStack::pop_any_value(LuaAcceptNilString &s) const {
if (lua_isnil(L_, -1)) {
s.v = "";
} else {
size_t len;
const char *str = luaL_cklstring(L_, -1, &len);
s.v = std::string(str, len);
}
lua_pop(L_, 1);
}
std::string LuaStack::ckstring(LuaSlot s) const {
size_t len;
const char *str = luaL_checklstring(L_, s, &len);
const char *str = luaL_cklstring(L_, s, &len);
return std::string(str, len);
}
@@ -79,6 +111,11 @@ void LuaStack::setmetatable(LuaSlot tab, LuaSlot mt) const {
lua_setmetatable(L_, tab);
}
void LuaStack::getmetatable(LuaSlot mt, LuaSlot tab) const {
lua_getmetatable(L_, tab);
lua_replace(L_, mt);
}
void LuaStack::checknometa(LuaSlot index) const {
if (lua_istable(L_, index)) {
if (!lua_getmetatable(L_, index)) {
@@ -98,6 +135,17 @@ int LuaStack::next(LuaSlot tab, LuaSlot key, LuaSlot value) const {
return ret;
}
bool LuaStack::isemptytable(LuaSlot tab) const {
if (lua_istable(L_, tab)) {
lua_pushnil(L_);
if (lua_next(L_, tab) == 0) {
return true;
}
lua_pop(L_, 2);
}
return false;
}
void LuaStack::newtable(LuaSlot target) const {
lua_newtable(L_);
lua_replace(L_, target);