aboutsummaryrefslogtreecommitdiff
path: root/src/universe.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/universe.cpp')
-rw-r--r--src/universe.cpp31
1 files changed, 14 insertions, 17 deletions
diff --git a/src/universe.cpp b/src/universe.cpp
index 4f21306..548475e 100644
--- a/src/universe.cpp
+++ b/src/universe.cpp
@@ -150,10 +150,9 @@ void Universe::closeKeepers()
150void Universe::initializeAllocatorFunction(lua_State* L_) 150void Universe::initializeAllocatorFunction(lua_State* L_)
151{ 151{
152 STACK_CHECK_START_REL(L_, 1); // L_: settings 152 STACK_CHECK_START_REL(L_, 1); // L_: settings
153 lua_getfield(L_, -1, "allocator"); // L_: settings allocator|nil|"protected" 153 if (luaG_getfield(L_, -1, "allocator") != LuaType::NIL) { // L_: settings allocator|nil|"protected"
154 if (!lua_isnil(L_, -1)) {
155 // store C function pointer in an internal variable 154 // store C function pointer in an internal variable
156 provideAllocator = lua_tocfunction(L_, -1); // L_: settings allocator 155 provideAllocator = lua_tocfunction(L_, -1); // L_: settings allocator
157 if (provideAllocator != nullptr) { 156 if (provideAllocator != nullptr) {
158 // make sure the function doesn't have upvalues 157 // make sure the function doesn't have upvalues
159 char const* upname = lua_getupvalue(L_, -1, 1); // L_: settings allocator upval? 158 char const* upname = lua_getupvalue(L_, -1, 1); // L_: settings allocator upval?
@@ -179,18 +178,16 @@ void Universe::initializeAllocatorFunction(lua_State* L_)
179 lua_pop(L_, 1); // L_: settings 178 lua_pop(L_, 1); // L_: settings
180 STACK_CHECK(L_, 1); 179 STACK_CHECK(L_, 1);
181 180
182 lua_getfield(L_, -1, "internal_allocator"); // L_: settings "libc"|"allocator" 181 std::ignore = luaG_getfield(L_, -1, "internal_allocator"); // L_: settings "libc"|"allocator"
183 { 182 std::string_view const _allocator{ lua_tostringview(L_, -1) };
184 char const* const _allocator{ lua_tostring(L_, -1) }; 183 if (_allocator == "libc") {
185 if (strcmp(_allocator, "libc") == 0) { 184 internalAllocator = AllocatorDefinition{ libc_lua_Alloc, nullptr };
186 internalAllocator = AllocatorDefinition{ libc_lua_Alloc, nullptr }; 185 } else if (provideAllocator == luaG_provide_protected_allocator) {
187 } else if (provideAllocator == luaG_provide_protected_allocator) { 186 // user wants mutex protection on the state's allocator. Use protection for our own allocations too, just in case.
188 // user wants mutex protection on the state's allocator. Use protection for our own allocations too, just in case. 187 internalAllocator = protectedAllocator.makeDefinition();
189 internalAllocator = protectedAllocator.makeDefinition(); 188 } else {
190 } else { 189 // no protection required, just use whatever we have as-is.
191 // no protection required, just use whatever we have as-is. 190 internalAllocator = protectedAllocator;
192 internalAllocator = protectedAllocator;
193 }
194 } 191 }
195 lua_pop(L_, 1); // L_: settings 192 lua_pop(L_, 1); // L_: settings
196 STACK_CHECK(L_, 1); 193 STACK_CHECK(L_, 1);
@@ -213,7 +210,7 @@ void Universe::initializeKeepers(lua_State* L_)
213{ 210{
214 LUA_ASSERT(L_, lua_gettop(L_) == 1 && lua_istable(L_, 1)); 211 LUA_ASSERT(L_, lua_gettop(L_) == 1 && lua_istable(L_, 1));
215 STACK_CHECK_START_REL(L_, 0); // L_: settings 212 STACK_CHECK_START_REL(L_, 0); // L_: settings
216 lua_getfield(L_, 1, "nb_keepers"); // L_: settings nb_keepers 213 std::ignore = luaG_getfield(L_, 1, "nb_keepers"); // L_: settings nb_keepers
217 int const _nb_keepers{ static_cast<int>(lua_tointeger(L_, -1)) }; 214 int const _nb_keepers{ static_cast<int>(lua_tointeger(L_, -1)) };
218 lua_pop(L_, 1); // L_: settings 215 lua_pop(L_, 1); // L_: settings
219 if (_nb_keepers < 1) { 216 if (_nb_keepers < 1) {
@@ -221,7 +218,7 @@ void Universe::initializeKeepers(lua_State* L_)
221 } 218 }
222 STACK_CHECK(L_, 0); 219 STACK_CHECK(L_, 0);
223 220
224 lua_getfield(L_, 1, "keepers_gc_threshold"); // L_: settings keepers_gc_threshold 221 std::ignore = luaG_getfield(L_, 1, "keepers_gc_threshold"); // L_: settings keepers_gc_threshold
225 int const keepers_gc_threshold{ static_cast<int>(lua_tointeger(L_, -1)) }; 222 int const keepers_gc_threshold{ static_cast<int>(lua_tointeger(L_, -1)) };
226 lua_pop(L_, 1); // L_: settings 223 lua_pop(L_, 1); // L_: settings
227 STACK_CHECK(L_, 0); 224 STACK_CHECK(L_, 0);