More LuaStack work.
This commit is contained in:
@@ -78,15 +78,48 @@ void LuaStack::setnumber(LuaSlot target, double value) const {
|
|||||||
lua_replace(L_, target);
|
lua_replace(L_, target);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string LuaStack::tostring(LuaSlot s) {
|
std::string LuaStack::tostring(LuaSlot s) const {
|
||||||
size_t len;
|
size_t len;
|
||||||
const char *str = lua_tolstring(L_, s, &len);
|
const char *str = lua_tolstring(L_, s, &len);
|
||||||
return std::string(str, len);
|
return std::string(str, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string LuaStack::checkstring(LuaSlot s) {
|
std::string LuaStack::checkstring(LuaSlot s) const {
|
||||||
size_t len;
|
size_t len;
|
||||||
const char *str = luaL_checklstring(L_, s, &len);
|
const char *str = luaL_checklstring(L_, s, &len);
|
||||||
return std::string(str, len);
|
return std::string(str, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void LuaStack::clearmetatable(LuaSlot tab) const {
|
||||||
|
lua_pushnil(L_);
|
||||||
|
lua_setmetatable(L_, tab);
|
||||||
|
}
|
||||||
|
|
||||||
|
void LuaStack::setmetatable(LuaSlot tab, LuaSlot mt) const {
|
||||||
|
lua_pushvalue(L_, mt);
|
||||||
|
lua_setmetatable(L_, tab);
|
||||||
|
}
|
||||||
|
|
||||||
|
void LuaStack::checknometa(LuaSlot index) const {
|
||||||
|
if (lua_istable(L_, index)) {
|
||||||
|
if (!lua_getmetatable(L_, index)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
luaL_error(L_, "expected simple table with no metatable");
|
||||||
|
}
|
||||||
|
|
||||||
|
int LuaStack::next(LuaSlot tab, LuaSlot key, LuaSlot value) const {
|
||||||
|
lua_pushvalue(L_, key);
|
||||||
|
int ret = lua_next(L_, tab);
|
||||||
|
if (ret != 0) {
|
||||||
|
lua_replace(L_, value);
|
||||||
|
lua_replace(L_, key);
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
void LuaStack::newtable(LuaSlot target) const {
|
||||||
|
lua_newtable(L_);
|
||||||
|
lua_replace(L_, target);
|
||||||
|
}
|
||||||
|
|||||||
@@ -168,38 +168,36 @@ public:
|
|||||||
void setstring(LuaSlot target, const std::string &str) const;
|
void setstring(LuaSlot target, const std::string &str) const;
|
||||||
void setnumber(LuaSlot target, double value) const;
|
void setnumber(LuaSlot target, double value) const;
|
||||||
|
|
||||||
bool isboolean(LuaSlot s) { return lua_isboolean(L_, s); }
|
bool isboolean(LuaSlot s) const { return lua_isboolean(L_, s); }
|
||||||
bool iscfunction(LuaSlot s) { return lua_iscfunction(L_, s); }
|
bool iscfunction(LuaSlot s) const { return lua_iscfunction(L_, s); }
|
||||||
bool isfunction(LuaSlot s) { return lua_isfunction(L_, s); }
|
bool isfunction(LuaSlot s) const { return lua_isfunction(L_, s); }
|
||||||
bool islightuserdata(LuaSlot s) { return lua_islightuserdata(L_, s); }
|
bool islightuserdata(LuaSlot s) const { return lua_islightuserdata(L_, s); }
|
||||||
bool isnil(LuaSlot s) { return lua_isnil(L_, s); }
|
bool isnil(LuaSlot s) const { return lua_isnil(L_, s); }
|
||||||
bool isnumber(LuaSlot s) { return lua_isnumber(L_, s); }
|
bool isnumber(LuaSlot s) const { return lua_type(L_, s) == LUA_TNUMBER; }
|
||||||
bool isstring(LuaSlot s) { return lua_isstring(L_, s); }
|
bool isstring(LuaSlot s) const { return lua_type(L_, s) == LUA_TSTRING; }
|
||||||
bool istable(LuaSlot s) { return lua_istable(L_, s); }
|
bool istable(LuaSlot s) const { return lua_istable(L_, s); }
|
||||||
bool isthread(LuaSlot s) { return lua_isthread(L_, s); }
|
bool isthread(LuaSlot s) const { return lua_isthread(L_, s); }
|
||||||
bool isuserdata(LuaSlot s) { return lua_isuserdata(L_, s); }
|
bool isuserdata(LuaSlot s) const { return lua_isuserdata(L_, s); }
|
||||||
|
|
||||||
bool toboolean(LuaSlot s) { return lua_toboolean(L_, s); }
|
bool toboolean(LuaSlot s) const { return lua_toboolean(L_, s); }
|
||||||
int tointeger(LuaSlot s) { return lua_tointeger(L_, s); }
|
int tointeger(LuaSlot s) const { return lua_tointeger(L_, s); }
|
||||||
double tonumber(LuaSlot s) { return lua_tonumber(L_, s); }
|
double tonumber(LuaSlot s) const { return lua_tonumber(L_, s); }
|
||||||
std::string tostring(LuaSlot s);
|
std::string tostring(LuaSlot s) const;
|
||||||
lua_State *tothread(LuaSlot s) { return lua_tothread(L_, s); }
|
lua_State *tothread(LuaSlot s) const { return lua_tothread(L_, s); }
|
||||||
|
|
||||||
int checkint(LuaSlot s) { return luaL_checkint(L_, s); }
|
int checkint(LuaSlot s) const { return luaL_checkint(L_, s); }
|
||||||
long checklong(LuaSlot s) { return luaL_checklong(L_, s); }
|
long checklong(LuaSlot s) const { return luaL_checklong(L_, s); }
|
||||||
double checknumber(LuaSlot s) { return luaL_checknumber(L_, s); }
|
double checknumber(LuaSlot s) const { return luaL_checknumber(L_, s); }
|
||||||
std::string checkstring(LuaSlot s);
|
std::string checkstring(LuaSlot s) const;
|
||||||
void checktype(LuaSlot s, int t) { return luaL_checktype(L_, s, t); }
|
void checktype(LuaSlot s, int t) const { return luaL_checktype(L_, s, t); }
|
||||||
|
|
||||||
void clearmetatable(LuaSlot tab) {
|
void clearmetatable(LuaSlot tab) const;
|
||||||
lua_pushnil(L_);
|
void setmetatable(LuaSlot tab, LuaSlot mt) const;
|
||||||
lua_setmetatable(L_, tab);
|
void checknometa(LuaSlot index) const;
|
||||||
}
|
|
||||||
|
|
||||||
void setmetatable(LuaSlot tab, LuaSlot mt) {
|
void newtable(LuaSlot target) const;
|
||||||
lua_pushvalue(L_, mt);
|
|
||||||
lua_setmetatable(L_, tab);
|
int next(LuaSlot tab, LuaSlot key, LuaSlot value) const;
|
||||||
}
|
|
||||||
|
|
||||||
void rawget(LuaSlot target, LuaSlot tab, LuaSlot key) const {
|
void rawget(LuaSlot target, LuaSlot tab, LuaSlot key) const {
|
||||||
lua_pushvalue(L_, key);
|
lua_pushvalue(L_, key);
|
||||||
@@ -213,18 +211,6 @@ public:
|
|||||||
lua_rawset(L_, tab);
|
lua_rawset(L_, tab);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int next(LuaSlot tab, LuaSlot key, LuaSlot value) const {
|
|
||||||
lua_pushvalue(L_, key);
|
|
||||||
int ret = lua_next(L_, tab);
|
|
||||||
if (ret != 0) {
|
|
||||||
lua_replace(L_, value);
|
|
||||||
lua_replace(L_, key);
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void setfield(LuaSlot tab, const char *field, LuaSlot value) const {
|
void setfield(LuaSlot tab, const char *field, LuaSlot value) const {
|
||||||
lua_pushvalue(L_, value);
|
lua_pushvalue(L_, value);
|
||||||
lua_setfield(L_, tab, field);
|
lua_setfield(L_, tab, field);
|
||||||
@@ -245,19 +231,7 @@ public:
|
|||||||
lua_replace(L_, target);
|
lua_replace(L_, target);
|
||||||
}
|
}
|
||||||
|
|
||||||
void newtable(LuaSlot target) const {
|
|
||||||
lua_newtable(L_);
|
|
||||||
lua_replace(L_, target);
|
|
||||||
}
|
|
||||||
|
|
||||||
void checknometa(LuaSlot index) const {
|
|
||||||
if (lua_istable(L_, index)) {
|
|
||||||
if (!lua_getmetatable(L_, index)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
luaL_error(L_, "expected simple table with no metatable");
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user