summaryrefslogtreecommitdiff
path: root/indra/llcommon/lualistener.h
diff options
context:
space:
mode:
authorNat Goodspeed <nat@lindenlab.com>2024-06-17 11:18:09 -0400
committerNat Goodspeed <nat@lindenlab.com>2024-06-17 11:18:09 -0400
commit5b6a5c757deaba3c2b361eb49f2e61630fe3eb47 (patch)
tree14e69fcce05d56625bd16082d54f55909c33d72a /indra/llcommon/lualistener.h
parentab9cb6fcd96c1c29650d844b5fd76e2ebbf5f2df (diff)
Store script's LuaListener in userdata in lua_State's Registry.
Instead of deriving LuaListener from LLInstanceTracker with an int key, generating a unique int key and storing that key in the Registry, use new lua_emplace<LuaState>() to store the LuaListener directly in a Lua userdata object in the Lua Registry. Because lua_emplace<T>() uses LL.atexit() to guarantee that ~LuaState will destroy the T object, we no longer need ~LuaState() to make a special call specifically to destroy the LuaListener, if any. So we no longer need LuaState::getListener() separate from obtainListener(). Since LuaListener is no longer an LLInstanceTracker subclass, make LuaState::obtainListener() return LuaListener& rather than LuaListener::ptr_t.
Diffstat (limited to 'indra/llcommon/lualistener.h')
-rw-r--r--indra/llcommon/lualistener.h20
1 files changed, 2 insertions, 18 deletions
diff --git a/indra/llcommon/lualistener.h b/indra/llcommon/lualistener.h
index 85fb093cd6..68131dfa27 100644
--- a/indra/llcommon/lualistener.h
+++ b/indra/llcommon/lualistener.h
@@ -12,8 +12,7 @@
#if ! defined(LL_LUALISTENER_H)
#define LL_LUALISTENER_H
-#include "llevents.h"
-#include "llinstancetracker.h"
+#include "llevents.h" // LLTempBoundListener
#include "llsd.h"
#include "llthreadsafequeue.h"
#include <iosfwd> // std::ostream
@@ -27,25 +26,11 @@ class LLLeapListener;
/**
* LuaListener is based on LLLeap. It serves an analogous function.
*
- * Each LuaListener instance has an int key, generated randomly to
- * inconvenience malicious Lua scripts wanting to mess with others. The idea
- * is that a given lua_State stores in its Registry:
- * - "event.listener": the int key of the corresponding LuaListener, if any
- * The original thought was that LuaListener would itself store the Lua
- * function -- but surprisingly, there is no C/C++ type in the API that stores
- * a Lua function.
- *
- * (We considered storing in "event.listener" the LuaListener pointer itself
- * as a light userdata, but the problem would be if Lua code overwrote that.
- * We want to prevent any Lua script from crashing the viewer, intentionally
- * or otherwise. Safer to use a key lookup.)
- *
* Like LLLeap, each LuaListener instance also has an associated
* LLLeapListener to respond to LLEventPump management commands.
*/
-class LuaListener: public LLInstanceTracker<LuaListener, int>
+class LuaListener
{
- using super = LLInstanceTracker<LuaListener, int>;
public:
LuaListener(lua_State* L);
@@ -68,7 +53,6 @@ public:
friend std::ostream& operator<<(std::ostream& out, const LuaListener& self);
private:
- static int getUniqueKey();
bool queueEvent(const std::string& pump, const LLSD& data);
LLThreadSafeQueue<PumpData> mQueue;