diff options
author | Nat Goodspeed <nat@lindenlab.com> | 2024-02-08 13:59:19 -0500 |
---|---|---|
committer | Nat Goodspeed <nat@lindenlab.com> | 2024-02-08 13:59:19 -0500 |
commit | 4e9794bd06660baea6d16779f6e354ca99e11b8a (patch) | |
tree | 5437fa6948a8a111b77b8bcf726629d419cdcf1d /indra/llcommon | |
parent | 72e680cfae03aa86659b6c2165e16ce46487097b (diff) |
Add required helptext parameter to lua_function() macro.
Extend the LuaFunction::Registry map to store helptext as well as the function
pointer.
Add help text to every existing lua_function() invocation.
Diffstat (limited to 'indra/llcommon')
-rw-r--r-- | indra/llcommon/lua_function.cpp | 12 | ||||
-rw-r--r-- | indra/llcommon/lua_function.h | 21 |
2 files changed, 18 insertions, 15 deletions
diff --git a/indra/llcommon/lua_function.cpp b/indra/llcommon/lua_function.cpp index 956630ed3c..07e0c1fac2 100644 --- a/indra/llcommon/lua_function.cpp +++ b/indra/llcommon/lua_function.cpp @@ -508,16 +508,18 @@ LuaPopper::~LuaPopper() } } -LuaFunction::LuaFunction(const std::string_view& name, lua_CFunction function) +LuaFunction::LuaFunction(const std::string_view& name, lua_CFunction function, + const std::string_view& helptext) { - getRegistry().emplace(name, function); + getRegistry().emplace(name, Registry::mapped_type{ function, helptext }); } void LuaFunction::init(lua_State* L) { - for (const auto& pair: getRegistry()) + for (const auto& [name, pair]: getRegistry()) { - lua_register(L, pair.first.c_str(), pair.second); + const auto& [funcptr, helptext] = pair; + lua_register(L, name.c_str(), funcptr); } } @@ -527,7 +529,7 @@ lua_CFunction LuaFunction::get(const std::string& key) // unknown key const auto& registry{ getRegistry() }; auto found{ registry.find(key) }; - return (found == registry.end())? nullptr : found->second; + return (found == registry.end())? nullptr : found->second.first; } LuaFunction::Registry& LuaFunction::getRegistry() diff --git a/indra/llcommon/lua_function.h b/indra/llcommon/lua_function.h index 82cd91984a..26c399cdd1 100644 --- a/indra/llcommon/lua_function.h +++ b/indra/llcommon/lua_function.h @@ -124,19 +124,20 @@ struct LuaPopper class LuaFunction { public: - LuaFunction(const std::string_view& name, lua_CFunction function); + LuaFunction(const std::string_view& name, lua_CFunction function, + const std::string_view& helptext); static void init(lua_State* L); static lua_CFunction get(const std::string& key); private: - using Registry = std::map<std::string, lua_CFunction>; + using Registry = std::map<std::string, std::pair<lua_CFunction, std::string>>; static Registry& getRegistry(); }; /** - * lua_function(name) is a macro to facilitate defining C++ functions + * lua_function(name, helptext) is a macro to facilitate defining C++ functions * available to Lua. It defines a subclass of LuaFunction and declares a * static instance of that subclass, thereby forcing the compiler to call its * constructor at module initialization time. The constructor passes the @@ -145,13 +146,13 @@ private: * call() method definition header, to be followed by a method body enclosed * in curly braces as usual. */ -#define lua_function(name) \ -static struct name##_luadecl : public LuaFunction \ -{ \ - name##_luadecl(): LuaFunction(#name, &call) {} \ - static int call(lua_State* L); \ -} name##_luadef; \ -int name##_luadecl::call(lua_State* L) +#define lua_function(name, helptext) \ +static struct name##_luasub : public LuaFunction \ +{ \ + name##_luasub(): LuaFunction(#name, &call, helptext) {} \ + static int call(lua_State* L); \ +} name##_luadecl; \ +int name##_luasub::call(lua_State* L) // { // ... supply method body here, referencing 'L' ... // } |