From f544888938e7c9c8eba1c99ba72d48770480ec69 Mon Sep 17 00:00:00 2001 From: jyelon Date: Sat, 21 Feb 2026 23:58:33 -0500 Subject: [PATCH] A little more work on getclass and classname --- luprex/cpp/core/luastack.hpp | 25 +++++++++++++++++-------- luprex/cpp/core/source.cpp | 36 ++++++++++++++++++++++++++++++------ 2 files changed, 47 insertions(+), 14 deletions(-) diff --git a/luprex/cpp/core/luastack.hpp b/luprex/cpp/core/luastack.hpp index d8512d17..983f02b7 100644 --- a/luprex/cpp/core/luastack.hpp +++ b/luprex/cpp/core/luastack.hpp @@ -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 diff --git a/luprex/cpp/core/source.cpp b/luprex/cpp/core/source.cpp index d46389fc..69fab08e 100644 --- a/luprex/cpp/core/source.cpp +++ b/luprex/cpp/core/source.cpp @@ -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);