still working on porting to lua 5.2
This commit is contained in:
@@ -3,7 +3,6 @@
|
||||
#include <iostream>
|
||||
|
||||
LuaSpecial LuaRegistry(LUA_REGISTRYINDEX);
|
||||
LuaSpecial LuaGlobals(LUA_GLOBALSINDEX);
|
||||
LuaNilMarker LuaNil;
|
||||
LuaNewTableMarker LuaNewTable;
|
||||
|
||||
@@ -39,8 +38,8 @@ lua_Number LuaStack::cknumber(LuaSlot s) const {
|
||||
std::string LuaStack::ckstring(LuaSlot s) const {
|
||||
luaL_checktype(L_, s, LUA_TSTRING);
|
||||
size_t len;
|
||||
const char *s = lua_tolstring(L_, s, &len);
|
||||
return std::string(s, len);
|
||||
const char *str = lua_tolstring(L_, s, &len);
|
||||
return std::string(str, len);
|
||||
}
|
||||
|
||||
lua_State *LuaStack::ckthread(LuaSlot s) const {
|
||||
@@ -104,12 +103,6 @@ void LuaStack::pop_any_value(std::string &s) const {
|
||||
lua_pop(L_, 1);
|
||||
}
|
||||
|
||||
std::string LuaStack::ckstring(LuaSlot s) const {
|
||||
size_t len;
|
||||
const char *str = luaL_cklstring(L_, s, &len);
|
||||
return std::string(str, len);
|
||||
}
|
||||
|
||||
void LuaStack::clearmetatable(LuaSlot tab) const {
|
||||
lua_pushnil(L_);
|
||||
lua_setmetatable(L_, tab);
|
||||
@@ -156,29 +149,37 @@ lua_State *LuaStack::newthread(LuaSlot target) const {
|
||||
}
|
||||
|
||||
void LuaStack::makeclass(LuaSlot classtab, LuaSlot classname) const {
|
||||
checkstring(classname);
|
||||
LuaVar globtab;
|
||||
LuaStack LS(L_, globtab);
|
||||
|
||||
// Special case: if the classname is _G, detect and error.
|
||||
if (equal(classname, "_G")) {
|
||||
// Validate the class name.
|
||||
LS.checkstring(classname);
|
||||
if (LS.equal(classname, "_G")) {
|
||||
luaL_error(L_, "_G is explicitly not allowed as a class name");
|
||||
}
|
||||
|
||||
// Fetch the global environment from the registry.
|
||||
LS.rawget(globtab, LuaRegistry, LUA_RIDX_GLOBALS);
|
||||
|
||||
// Get the classtab from the global environment.
|
||||
// Create it if it doesn't exist.
|
||||
rawget(classtab, LuaGlobals, classname);
|
||||
if (isnil(classtab)) {
|
||||
newtable(classtab);
|
||||
rawset(LuaGlobals, classname, classtab);
|
||||
LS.rawget(classtab, globtab, classname);
|
||||
if (LS.isnil(classtab)) {
|
||||
LS.newtable(classtab);
|
||||
LS.rawset(globtab, classname, classtab);
|
||||
}
|
||||
|
||||
// If the name isn't bound to a table, abort.
|
||||
if (!istable(classtab)) {
|
||||
if (!LS.istable(classtab)) {
|
||||
luaL_error(L_, "%s is not a class", ckstring(classname).c_str());
|
||||
}
|
||||
|
||||
// Repair the special fields.
|
||||
rawset(classtab, "__index", classtab);
|
||||
rawset(classtab, "__class", classname);
|
||||
LS.rawset(classtab, "__index", classtab);
|
||||
LS.rawset(classtab, "__class", classname);
|
||||
|
||||
// Put the stack back.
|
||||
LS.result();
|
||||
}
|
||||
|
||||
void LuaStack::makesubtable(LuaSlot sub, LuaSlot tab, const char *name) const {
|
||||
|
||||
Reference in New Issue
Block a user