Add isclass operator, make inspector print classes nicely
This commit is contained in:
@@ -40,6 +40,30 @@ LuaDefine(source_makeclass, "f") {
|
|||||||
return LS.result();
|
return LS.result();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LuaDefine(source_isclass, "f") {
|
||||||
|
LuaArg table;
|
||||||
|
LuaVar classname, globtab, classtab;
|
||||||
|
LuaRet result;
|
||||||
|
LuaStack LS(L, table, classname, globtab, classtab, result);
|
||||||
|
if (!LS.istable(table)) {
|
||||||
|
LS.set(result, false);
|
||||||
|
return LS.result();
|
||||||
|
}
|
||||||
|
LS.rawget(classname, table, "__class");
|
||||||
|
if (!LS.isstring(classname)) {
|
||||||
|
LS.set(result, false);
|
||||||
|
return LS.result();
|
||||||
|
}
|
||||||
|
LS.getglobaltable(globtab);
|
||||||
|
LS.rawget(classtab, globtab, classname);
|
||||||
|
if (!LS.rawequal(classtab, table)) {
|
||||||
|
LS.set(result, false);
|
||||||
|
return LS.result();
|
||||||
|
}
|
||||||
|
LS.set(result, true);
|
||||||
|
return LS.result();
|
||||||
|
}
|
||||||
|
|
||||||
LuaDefine(source_maketangible, "f") {
|
LuaDefine(source_maketangible, "f") {
|
||||||
LuaArg classname;
|
LuaArg classname;
|
||||||
LuaRet classtab;
|
LuaRet classtab;
|
||||||
|
|||||||
@@ -165,6 +165,9 @@ public:
|
|||||||
//
|
//
|
||||||
int source_makeclass(lua_State *L);
|
int source_makeclass(lua_State *L);
|
||||||
|
|
||||||
|
// Return true if the specified table is a class created by 'makeclass'
|
||||||
|
//
|
||||||
|
int source_isclass(lua_State *L);
|
||||||
|
|
||||||
#endif // SOURCE_HPP
|
#endif // SOURCE_HPP
|
||||||
|
|
||||||
|
|||||||
@@ -271,8 +271,14 @@ function Inspector:putTable(t)
|
|||||||
if count > 0 then self:puts(',') end
|
if count > 0 then self:puts(',') end
|
||||||
self:tabify()
|
self:tabify()
|
||||||
self:puts('<metatable> = ')
|
self:puts('<metatable> = ')
|
||||||
|
if isclass(mt) then
|
||||||
|
self:puts('<class ')
|
||||||
|
self:puts(rawget(mt, "__class"))
|
||||||
|
self:puts('>')
|
||||||
|
else
|
||||||
self:putValue(mt)
|
self:putValue(mt)
|
||||||
end
|
end
|
||||||
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
if nonSequentialKeysLength > 0 or type(mt) == 'table' then -- result is multi-lined. Justify closing }
|
if nonSequentialKeysLength > 0 or type(mt) == 'table' then -- result is multi-lined. Justify closing }
|
||||||
|
|||||||
Reference in New Issue
Block a user