From 4e9794bd06660baea6d16779f6e354ca99e11b8a Mon Sep 17 00:00:00 2001 From: Nat Goodspeed Date: Thu, 8 Feb 2024 13:59:19 -0500 Subject: 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. --- indra/llcommon/lua_function.cpp | 12 +++++++----- indra/llcommon/lua_function.h | 21 +++++++++++---------- 2 files changed, 18 insertions(+), 15 deletions(-) (limited to 'indra/llcommon') 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; + using Registry = std::map>; 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' ... // } -- cgit v1.2.3