summaryrefslogtreecommitdiff
path: root/indra
diff options
context:
space:
mode:
Diffstat (limited to 'indra')
-rw-r--r--indra/llcommon/lua_function.cpp12
-rw-r--r--indra/llcommon/lua_function.h21
-rw-r--r--indra/newview/llluamanager.cpp24
3 files changed, 33 insertions, 24 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' ...
// }
diff --git a/indra/newview/llluamanager.cpp b/indra/newview/llluamanager.cpp
index fac66003a1..c55c44e671 100644
--- a/indra/newview/llluamanager.cpp
+++ b/indra/newview/llluamanager.cpp
@@ -56,7 +56,7 @@ extern LLUIListener sUIListener;
#include <string_view>
#include <vector>
-lua_function(sleep)
+lua_function(sleep, "sleep(seconds): pause the running coroutine")
{
F32 seconds = lua_tonumber(L, -1);
lua_pop(L, 1);
@@ -106,20 +106,20 @@ std::string lua_print_msg(lua_State* L, const std::string_view& level)
return msg;
}
-lua_function(print_debug)
+lua_function(print_debug, "print_debug(args...): DEBUG level logging")
{
LL_DEBUGS("Lua") << lua_print_msg(L, "DEBUG") << LL_ENDL;
return 0;
}
// also used for print(); see LuaState constructor
-lua_function(print_info)
+lua_function(print_info, "print_info(args...): INFO level logging")
{
LL_INFOS("Lua") << lua_print_msg(L, "INFO") << LL_ENDL;
return 0;
}
-lua_function(print_warning)
+lua_function(print_warning, "print_warning(args...): WARNING level logging")
{
LL_WARNS("Lua") << lua_print_msg(L, "WARN") << LL_ENDL;
return 0;
@@ -127,7 +127,9 @@ lua_function(print_warning)
#ifndef LL_TEST
-lua_function(run_ui_command)
+lua_function(run_ui_command,
+ "run_ui_command(name [, parameter]): "
+ "call specified UI command with specified parameter")
{
int top = lua_gettop(L);
std::string func_name;
@@ -154,7 +156,7 @@ lua_function(run_ui_command)
}
#endif // ! LL_TEST
-lua_function(post_on)
+lua_function(post_on, "post_on(pumpname, data): post specified data to specified LLEventPump")
{
std::string pumpname{ lua_tostdstring(L, 1) };
LLSD data{ lua_tollsd(L, 2) };
@@ -164,7 +166,10 @@ lua_function(post_on)
return 0;
}
-lua_function(listen_events)
+lua_function(listen_events,
+ "listen_events(callback): call callback(pumpname, data) with events received\n"
+ "on this Lua chunk's replypump.\n"
+ "Returns replypump, commandpump: names of LLEventPumps specific to this chunk.")
{
if (! lua_isfunction(L, 1))
{
@@ -237,9 +242,10 @@ lua_function(listen_events)
return 2;
}
-lua_function(await_event)
+lua_function(await_event,
+ "await_event(pumpname [, timeout [, value to return if timeout (default nil)]]):\n"
+ "pause the running Lua chunk until the next event on the named LLEventPump")
{
- // await_event(pumpname [, timeout [, value to return if timeout (default nil)]])
auto pumpname{ lua_tostdstring(L, 1) };
LLSD result;
if (lua_gettop(L) > 1)