diff options
Diffstat (limited to 'src/linda.cpp')
-rw-r--r-- | src/linda.cpp | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/linda.cpp b/src/linda.cpp index 6ebbc1f..7af387f 100644 --- a/src/linda.cpp +++ b/src/linda.cpp | |||
@@ -130,6 +130,8 @@ namespace { | |||
130 | // ################################################################################################# | 130 | // ################################################################################################# |
131 | // ################################################################################################# | 131 | // ################################################################################################# |
132 | 132 | ||
133 | LUAG_FUNC(linda); | ||
134 | |||
133 | // ################################################################################################# | 135 | // ################################################################################################# |
134 | // ################################################################################################# | 136 | // ################################################################################################# |
135 | // #################################### Linda implementation ####################################### | 137 | // #################################### Linda implementation ####################################### |
@@ -165,6 +167,38 @@ Keeper* Linda::acquireKeeper() const | |||
165 | 167 | ||
166 | // ################################################################################################# | 168 | // ################################################################################################# |
167 | 169 | ||
170 | Linda* Linda::CreateTimerLinda(lua_State* const L_) | ||
171 | { | ||
172 | STACK_CHECK_START_REL(L_, 0); // L_: | ||
173 | // Initialize 'timerLinda'; a common Linda object shared by all states | ||
174 | lua_pushcfunction(L_, LG_linda); // L_: lanes.linda | ||
175 | luaG_pushstring(L_, "lanes-timer"); // L_: lanes.linda "lanes-timer" | ||
176 | lua_pushinteger(L_, 0); // L_: lanes.linda "lanes-timer" 0 | ||
177 | lua_call(L_, 2, 1); // L_: linda | ||
178 | STACK_CHECK(L_, 1); | ||
179 | |||
180 | // Proxy userdata contents is only a 'DeepPrelude*' pointer | ||
181 | auto const _timerLinda{ *luaG_tofulluserdata<Linda*>(L_, kIdxTop) }; | ||
182 | // increment refcount so that this linda remains alive as long as the universe exists. | ||
183 | _timerLinda->refcount.fetch_add(1, std::memory_order_relaxed); | ||
184 | lua_pop(L_, 1); // L_: | ||
185 | STACK_CHECK(L_, 0); | ||
186 | return _timerLinda; | ||
187 | } | ||
188 | |||
189 | // ################################################################################################# | ||
190 | |||
191 | void Linda::DeleteTimerLinda(lua_State* const L_, Linda* const linda_) | ||
192 | { | ||
193 | if (linda_ != nullptr) { // test in case some early internal error prevented Lanes from creating the deep timer | ||
194 | [[maybe_unused]] auto const _prev_ref_count{ linda_->refcount.fetch_sub(1, std::memory_order_relaxed) }; | ||
195 | LUA_ASSERT(L_, _prev_ref_count == 1); // this should be the last reference | ||
196 | DeepFactory::DeleteDeepObject(L_, linda_); | ||
197 | } | ||
198 | } | ||
199 | |||
200 | // ################################################################################################# | ||
201 | |||
168 | void Linda::freeAllocatedName() | 202 | void Linda::freeAllocatedName() |
169 | { | 203 | { |
170 | if (std::holds_alternative<std::string_view>(nameVariant)) { | 204 | if (std::holds_alternative<std::string_view>(nameVariant)) { |