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); }
|
||||
|
||||
// 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.
|
||||
//
|
||||
// The object passed in can be:
|
||||
@@ -853,12 +867,10 @@ public:
|
||||
// * A valid class table.
|
||||
// * A valid, existing class name.
|
||||
// * A tangible that has a class.
|
||||
// *
|
||||
// * A normal table with a class metatable.
|
||||
//
|
||||
// If there is a problem, returns an error message.
|
||||
// There are lots of error conditions, including such
|
||||
// things as no such class, corrupted class, classname
|
||||
// invalid, etc.
|
||||
// If there is a problem, returns an error message
|
||||
// and sets tab to nil.
|
||||
//
|
||||
eng::string getclass(LuaSlot tab, LuaSlot obj) const;
|
||||
eng::string getclass(LuaSlot tab, std::string_view name) const;
|
||||
@@ -1032,9 +1044,6 @@ public:
|
||||
lua_rawseti(L_, tab, key);
|
||||
}
|
||||
|
||||
private:
|
||||
void getclassinfo(LuaSlot classtab, eng::string &classname, eng::string &error, LuaSlot input) const;
|
||||
|
||||
protected:
|
||||
|
||||
// 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();
|
||||
}
|
||||
|
||||
LuaDefine(getclass, "x", "get a class table") {
|
||||
LuaArg classname;
|
||||
LuaDefine(getclass, "x",
|
||||
"|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;
|
||||
LuaDefStack LS(L, classname, classtab);
|
||||
eng::string err = LS.getclass(classtab, classname);
|
||||
if (err != "") {
|
||||
LuaDefStack LS(L, input, classtab);
|
||||
eng::string err = LS.getclass(classtab, input);
|
||||
if (!err.empty()) {
|
||||
luaL_error(L, "%s", err.c_str());
|
||||
}
|
||||
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;
|
||||
LuaRet result;
|
||||
LuaDefStack LS(L, table, result);
|
||||
|
||||
Reference in New Issue
Block a user