A little more work on getclass and classname
This commit is contained in:
@@ -833,6 +833,20 @@ public:
|
|||||||
//
|
//
|
||||||
static bool validpositiveinteger(int64_t value) { return (value <= MAXINT) && (value >= 1); }
|
static bool validpositiveinteger(int64_t value) { return (value <= MAXINT) && (value >= 1); }
|
||||||
|
|
||||||
|
// Get the class table and class name of X.
|
||||||
|
//
|
||||||
|
// The object passed in can be:
|
||||||
|
//
|
||||||
|
// * A valid class table.
|
||||||
|
// * A valid, existing class name.
|
||||||
|
// * A tangible that has a class.
|
||||||
|
// * A normal table with a class metatable.
|
||||||
|
//
|
||||||
|
// On success, sets classtab, classname, and clears error.
|
||||||
|
// On failure, sets classtab to nil, clears classname, and sets error.
|
||||||
|
//
|
||||||
|
void getclassinfo(LuaSlot classtab, eng::string &classname, eng::string &error, LuaSlot input) const;
|
||||||
|
|
||||||
// Get the class name of X.
|
// Get the class name of X.
|
||||||
//
|
//
|
||||||
// The object passed in can be:
|
// The object passed in can be:
|
||||||
@@ -853,12 +867,10 @@ public:
|
|||||||
// * A valid class table.
|
// * A valid class table.
|
||||||
// * A valid, existing class name.
|
// * A valid, existing class name.
|
||||||
// * A tangible that has a class.
|
// * A tangible that has a class.
|
||||||
// *
|
// * A normal table with a class metatable.
|
||||||
//
|
//
|
||||||
// If there is a problem, returns an error message.
|
// If there is a problem, returns an error message
|
||||||
// There are lots of error conditions, including such
|
// and sets tab to nil.
|
||||||
// things as no such class, corrupted class, classname
|
|
||||||
// invalid, etc.
|
|
||||||
//
|
//
|
||||||
eng::string getclass(LuaSlot tab, LuaSlot obj) const;
|
eng::string getclass(LuaSlot tab, LuaSlot obj) const;
|
||||||
eng::string getclass(LuaSlot tab, std::string_view name) const;
|
eng::string getclass(LuaSlot tab, std::string_view name) const;
|
||||||
@@ -1032,9 +1044,6 @@ public:
|
|||||||
lua_rawseti(L_, tab, key);
|
lua_rawseti(L_, tab, key);
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
|
||||||
void getclassinfo(LuaSlot classtab, eng::string &classname, eng::string &error, LuaSlot input) const;
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
// Assign slots: this is used by the LuaDefStack and LuaExtStack
|
// Assign slots: this is used by the LuaDefStack and LuaExtStack
|
||||||
|
|||||||
@@ -29,18 +29,42 @@ LuaDefine(makeclass, "classname", "create a class if it doesn't already exist")
|
|||||||
return LS.result();
|
return LS.result();
|
||||||
}
|
}
|
||||||
|
|
||||||
LuaDefine(getclass, "x", "get a class table") {
|
LuaDefine(getclass, "x",
|
||||||
LuaArg classname;
|
"|Get the class table of X."
|
||||||
|
"|"
|
||||||
|
"|The object passed in can be:"
|
||||||
|
"|"
|
||||||
|
"| * A valid class table."
|
||||||
|
"| * A valid, existing class name."
|
||||||
|
"| * A tangible that has a class."
|
||||||
|
"| * A normal table with a class metatable."
|
||||||
|
"|"
|
||||||
|
"|On success, returns the class table."
|
||||||
|
"|On failure, throws an error."
|
||||||
|
) {
|
||||||
|
LuaArg input;
|
||||||
LuaRet classtab;
|
LuaRet classtab;
|
||||||
LuaDefStack LS(L, classname, classtab);
|
LuaDefStack LS(L, input, classtab);
|
||||||
eng::string err = LS.getclass(classtab, classname);
|
eng::string err = LS.getclass(classtab, input);
|
||||||
if (err != "") {
|
if (!err.empty()) {
|
||||||
luaL_error(L, "%s", err.c_str());
|
luaL_error(L, "%s", err.c_str());
|
||||||
}
|
}
|
||||||
return LS.result();
|
return LS.result();
|
||||||
}
|
}
|
||||||
|
|
||||||
LuaDefine(classname, "x", "get a class name") {
|
LuaDefine(classname, "x",
|
||||||
|
"|Get the class name of X."
|
||||||
|
"|"
|
||||||
|
"|The object passed in can be:"
|
||||||
|
"|"
|
||||||
|
"| * A valid class table."
|
||||||
|
"| * A valid, existing class name."
|
||||||
|
"| * A tangible that has a class."
|
||||||
|
"| * A normal table with a class metatable."
|
||||||
|
"|"
|
||||||
|
"|If the object is none of these, returns empty string."
|
||||||
|
"|This function does not throw errors."
|
||||||
|
) {
|
||||||
LuaArg table;
|
LuaArg table;
|
||||||
LuaRet result;
|
LuaRet result;
|
||||||
LuaDefStack LS(L, table, result);
|
LuaDefStack LS(L, table, result);
|
||||||
|
|||||||
Reference in New Issue
Block a user