summaryrefslogtreecommitdiff
path: root/indra/llcommon/lua_function.h
diff options
context:
space:
mode:
authorNat Goodspeed <nat@lindenlab.com>2024-02-27 11:22:31 -0500
committerNat Goodspeed <nat@lindenlab.com>2024-02-27 11:22:31 -0500
commitedf1a712a7ca8fd741514348e3304af6a766f4aa (patch)
tree0cecaa9b4be0958dc7ff126c30382da3781f1f60 /indra/llcommon/lua_function.h
parent01a94f9d8378bb1094f4272b37ed9b966703f0b6 (diff)
parentad32c066691152e6a23f025d6aa5ead0e91b7be9 (diff)
Merge branch 'release/luau-scripting' into luau-require-impl.
Diffstat (limited to 'indra/llcommon/lua_function.h')
-rw-r--r--indra/llcommon/lua_function.h34
1 files changed, 20 insertions, 14 deletions
diff --git a/indra/llcommon/lua_function.h b/indra/llcommon/lua_function.h
index 0605eb12a6..08a2353d29 100644
--- a/indra/llcommon/lua_function.h
+++ b/indra/llcommon/lua_function.h
@@ -17,8 +17,11 @@
#include "luau/luaconf.h"
#include "luau/lualib.h"
#include "stringize.h"
+#include <memory> // std::shared_ptr
#include <utility> // std::pair
+class LuaListener;
+
#define lua_register(L, n, f) (lua_pushcfunction(L, (f), n), lua_setglobal(L, (n)))
#define lua_rawlen lua_objlen
@@ -86,6 +89,17 @@ public:
operator lua_State*() const { return mState; }
+ // Return LuaListener for this LuaState if we already have one, else empty
+ // shared_ptr.
+ std::shared_ptr<LuaListener> getListener() { return getListener(mState); }
+ // Find or create LuaListener for this LuaState, returning its ptr_t.
+ std::shared_ptr<LuaListener> obtainListener() { return obtainListener(mState); }
+ // Return LuaListener for passed lua_State if we already have one, else
+ // empty shared_ptr.
+ static std::shared_ptr<LuaListener> getListener(lua_State* L);
+ // Find or create LuaListener for passed lua_State, returning its ptr_t.
+ static std::shared_ptr<LuaListener> obtainListener(lua_State* L);
+
private:
script_finished_fn mCallback;
lua_State* mState;
@@ -134,9 +148,13 @@ public:
static lua_CFunction get(const std::string& key);
-private:
+protected:
using Registry = std::map<std::string, std::pair<lua_CFunction, std::string>>;
- static Registry& getRegistry();
+ using Lookup = std::map<lua_CFunction, std::string>;
+ static std::pair<const Registry&, const Lookup&> getRState() { return getState(); }
+
+private:
+ static std::pair<Registry&, Lookup&> getState();
};
/**
@@ -198,16 +216,4 @@ private:
lua_State* L;
};
-// log exit from any block declaring an instance of DebugExit, regardless of
-// how control leaves that block
-struct DebugExit
-{
- DebugExit(const std::string& name): mName(name) {}
- DebugExit(const DebugExit&) = delete;
- DebugExit& operator=(const DebugExit&) = delete;
- ~DebugExit();
-
- std::string mName;
-};
-
#endif /* ! defined(LL_LUA_FUNCTION_H) */