summaryrefslogtreecommitdiff
path: root/indra/llcommon
diff options
context:
space:
mode:
authorNat Goodspeed <nat@lindenlab.com>2024-07-02 16:49:20 -0400
committerNat Goodspeed <nat@lindenlab.com>2024-07-02 16:49:20 -0400
commitd4aeeaf31511b3abe58d0c386fecf34e54632422 (patch)
treefdfcb9a7a44831cc3f897db4ef8786074436e0dd /indra/llcommon
parentb6a72ac2c4498ea52691d79b32d1bf763952d3ee (diff)
parent24e6c4ae23b24c7da36b2579069a062ffd882059 (diff)
Merge branch 'release/luau-scripting' into lua-appearance-listener
Diffstat (limited to 'indra/llcommon')
-rw-r--r--indra/llcommon/lua_function.h34
1 files changed, 32 insertions, 2 deletions
diff --git a/indra/llcommon/lua_function.h b/indra/llcommon/lua_function.h
index c32a586d79..b3b1f40ae5 100644
--- a/indra/llcommon/lua_function.h
+++ b/indra/llcommon/lua_function.h
@@ -118,11 +118,12 @@ private:
* LuaPopper
*****************************************************************************/
/**
- * LuaPopper is an RAII struct whose role is to pop some number of entries
+ * LuaPopper is an RAII class whose role is to pop some number of entries
* from the Lua stack if the calling function exits early.
*/
-struct LuaPopper
+class LuaPopper
{
+public:
LuaPopper(lua_State* L, int count):
mState(L),
mCount(count)
@@ -136,11 +137,40 @@ struct LuaPopper
void disarm() { set(0); }
void set(int count) { mCount = count; }
+private:
lua_State* mState;
int mCount;
};
/*****************************************************************************
+* LuaRemover
+*****************************************************************************/
+/**
+ * Remove a particular stack index on exit from enclosing scope.
+ * If you pass a negative index (meaning relative to the current stack top),
+ * converts to an absolute index. The point of LuaRemover is to remove the
+ * entry at the specified index regardless of subsequent pushes to the stack.
+ */
+class LuaRemover
+{
+public:
+ LuaRemover(lua_State* L, int index):
+ mState(L),
+ mIndex(lua_absindex(L, index))
+ {}
+ LuaRemover(const LuaRemover&) = delete;
+ LuaRemover& operator=(const LuaRemover&) = delete;
+ ~LuaRemover()
+ {
+ lua_remove(mState, mIndex);
+ }
+
+private:
+ lua_State* mState;
+ int mIndex;
+};
+
+/*****************************************************************************
* lua_function (and helper class LuaFunction)
*****************************************************************************/
/**