More LuaStack work.
This commit is contained in:
@@ -78,15 +78,48 @@ void LuaStack::setnumber(LuaSlot target, double value) const {
|
||||
lua_replace(L_, target);
|
||||
}
|
||||
|
||||
std::string LuaStack::tostring(LuaSlot s) {
|
||||
std::string LuaStack::tostring(LuaSlot s) const {
|
||||
size_t len;
|
||||
const char *str = lua_tolstring(L_, s, &len);
|
||||
return std::string(str, len);
|
||||
}
|
||||
|
||||
std::string LuaStack::checkstring(LuaSlot s) {
|
||||
std::string LuaStack::checkstring(LuaSlot s) const {
|
||||
size_t len;
|
||||
const char *str = luaL_checklstring(L_, s, &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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user