aboutsummaryrefslogtreecommitdiff
path: root/deep_test/deep_test.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'deep_test/deep_test.cpp')
-rw-r--r--deep_test/deep_test.cpp14
1 files changed, 14 insertions, 0 deletions
diff --git a/deep_test/deep_test.cpp b/deep_test/deep_test.cpp
index da467f3..c330cbe 100644
--- a/deep_test/deep_test.cpp
+++ b/deep_test/deep_test.cpp
@@ -47,6 +47,7 @@ void MyDeepFactory::deleteDeepObjectInternal(lua_State* const L_, DeepPrelude* c
47[[nodiscard]] static int deep_gc(lua_State* L) 47[[nodiscard]] static int deep_gc(lua_State* L)
48{ 48{
49 MyDeepUserdata* const _self{ static_cast<MyDeepUserdata*>(MyDeepFactory::Instance.toDeep(L, 1)) }; 49 MyDeepUserdata* const _self{ static_cast<MyDeepUserdata*>(MyDeepFactory::Instance.toDeep(L, 1)) };
50 luaL_argcheck(L, 1, !_self->inUse.load(), "being collected while in use!");
50 return 0; 51 return 0;
51} 52}
52 53
@@ -76,6 +77,18 @@ void MyDeepFactory::deleteDeepObjectInternal(lua_State* const L_, DeepPrelude* c
76 77
77// ################################################################################################# 78// #################################################################################################
78 79
80[[nodiscard]] static int deep_invoke(lua_State* L)
81{
82 MyDeepUserdata* const _self{ static_cast<MyDeepUserdata*>(MyDeepFactory::Instance.toDeep(L, 1)) };
83 luaL_argcheck(L, 2, lua_gettop(L) >= 2, "need something to call");
84 _self->inUse.fetch_add(1, std::memory_order_seq_cst);
85 lua_call(L, lua_gettop(L) - 2, LUA_MULTRET);
86 _self->inUse.fetch_sub(1, std::memory_order_seq_cst);
87 return 1;
88}
89
90// #################################################################################################
91
79[[nodiscard]] static int deep_set(lua_State* const L_) 92[[nodiscard]] static int deep_set(lua_State* const L_)
80{ 93{
81 MyDeepUserdata* const _self{ static_cast<MyDeepUserdata*>(MyDeepFactory::Instance.toDeep(L_, 1)) }; 94 MyDeepUserdata* const _self{ static_cast<MyDeepUserdata*>(MyDeepFactory::Instance.toDeep(L_, 1)) };
@@ -105,6 +118,7 @@ static luaL_Reg const deep_mt[] = {
105 { "__gc", deep_gc }, 118 { "__gc", deep_gc },
106 { "__tostring", deep_tostring }, 119 { "__tostring", deep_tostring },
107 { "getuv", deep_getuv }, 120 { "getuv", deep_getuv },
121 { "invoke", deep_invoke },
108 { "set", deep_set }, 122 { "set", deep_set },
109 { "setuv", deep_setuv }, 123 { "setuv", deep_setuv },
110 { nullptr, nullptr } 124 { nullptr, nullptr }