aboutsummaryrefslogtreecommitdiff
path: root/src/state.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/state.cpp')
-rw-r--r--src/state.cpp34
1 files changed, 17 insertions, 17 deletions
diff --git a/src/state.cpp b/src/state.cpp
index ebb24dd..2893907 100644
--- a/src/state.cpp
+++ b/src/state.cpp
@@ -64,10 +64,10 @@ THE SOFTWARE.
64 // Using 'lua_pcall()' to catch errors; otherwise a failing 'require' would 64 // Using 'lua_pcall()' to catch errors; otherwise a failing 'require' would
65 // leave us locked, blocking any future 'require' calls from other lanes. 65 // leave us locked, blocking any future 'require' calls from other lanes.
66 66
67 U->require_cs.lock(); 67 U->requireMutex.lock();
68 // starting with Lua 5.4, require may return a second optional value, so we need LUA_MULTRET 68 // starting with Lua 5.4, require may return a second optional value, so we need LUA_MULTRET
69 rc = lua_pcall(L_, args, LUA_MULTRET, 0 /*errfunc*/); // L_: err|result(s) 69 rc = lua_pcall(L_, args, LUA_MULTRET, 0 /*errfunc*/); // L_: err|result(s)
70 U->require_cs.unlock(); 70 U->requireMutex.unlock();
71 71
72 // the required module (or an error message) is left on the stack as returned value by original require function 72 // the required module (or an error message) is left on the stack as returned value by original require function
73 73
@@ -205,14 +205,14 @@ static void copy_one_time_settings(Universe* U_, SourceState L1_, DestState L2_)
205 205
206// ################################################################################################# 206// #################################################################################################
207 207
208void initialize_on_state_create(Universe* U_, lua_State* L_) 208void initializeOnStateCreate(Universe* U_, lua_State* L_)
209{ 209{
210 STACK_CHECK_START_REL(L_, 1); // L_: settings 210 STACK_CHECK_START_REL(L_, 1); // L_: settings
211 lua_getfield(L_, -1, "on_state_create"); // L_: settings on_state_create|nil 211 lua_getfield(L_, -1, "on_state_create"); // L_: settings on_state_create|nil
212 if (!lua_isnil(L_, -1)) { 212 if (!lua_isnil(L_, -1)) {
213 // store C function pointer in an internal variable 213 // store C function pointer in an internal variable
214 U_->on_state_create_func = lua_tocfunction(L_, -1); // L_: settings on_state_create 214 U_->onStateCreateFunc = lua_tocfunction(L_, -1); // L_: settings on_state_create
215 if (U_->on_state_create_func != nullptr) { 215 if (U_->onStateCreateFunc != nullptr) {
216 // make sure the function doesn't have upvalues 216 // make sure the function doesn't have upvalues
217 char const* upname = lua_getupvalue(L_, -1, 1); // L_: settings on_state_create upval? 217 char const* upname = lua_getupvalue(L_, -1, 1); // L_: settings on_state_create upval?
218 if (upname != nullptr) { // should be "" for C functions with upvalues if any 218 if (upname != nullptr) { // should be "" for C functions with upvalues if any
@@ -224,7 +224,7 @@ void initialize_on_state_create(Universe* U_, lua_State* L_)
224 lua_setfield(L_, -3, "on_state_create"); // L_: settings on_state_create 224 lua_setfield(L_, -3, "on_state_create"); // L_: settings on_state_create
225 } else { 225 } else {
226 // optim: store marker saying we have such a function in the config table 226 // optim: store marker saying we have such a function in the config table
227 U_->on_state_create_func = (lua_CFunction) initialize_on_state_create; 227 U_->onStateCreateFunc = reinterpret_cast<lua_CFunction>(initializeOnStateCreate);
228 } 228 }
229 } 229 }
230 lua_pop(L_, 1); // L_: settings 230 lua_pop(L_, 1); // L_: settings
@@ -240,17 +240,17 @@ lua_State* create_state(Universe* U_, lua_State* from_)
240 // for some reason, LuaJIT 64 bits does not support creating a state with lua_newstate... 240 // for some reason, LuaJIT 64 bits does not support creating a state with lua_newstate...
241 L = luaL_newstate(); 241 L = luaL_newstate();
242#else // LUAJIT_FLAVOR() == 64 242#else // LUAJIT_FLAVOR() == 64
243 if (U_->provide_allocator != nullptr) { // we have a function we can call to obtain an allocator 243 if (U_->provideAllocator != nullptr) { // we have a function we can call to obtain an allocator
244 lua_pushcclosure(from_, U_->provide_allocator, 0); 244 lua_pushcclosure(from_, U_->provideAllocator, 0);
245 lua_call(from_, 0, 1); 245 lua_call(from_, 0, 1);
246 { 246 {
247 AllocatorDefinition* const def{ lua_tofulluserdata<AllocatorDefinition>(from_, -1) }; 247 AllocatorDefinition* const def{ lua_tofulluserdata<AllocatorDefinition>(from_, -1) };
248 L = lua_newstate(def->m_allocF, def->m_allocUD); 248 L = lua_newstate(def->allocF, def->allocUD);
249 } 249 }
250 lua_pop(from_, 1); 250 lua_pop(from_, 1);
251 } else { 251 } else {
252 // reuse the allocator provided when the master state was created 252 // reuse the allocator provided when the master state was created
253 L = lua_newstate(U_->protected_allocator.m_allocF, U_->protected_allocator.m_allocUD); 253 L = lua_newstate(U_->protectedAllocator.allocF, U_->protectedAllocator.allocUD);
254 } 254 }
255#endif // LUAJIT_FLAVOR() == 64 255#endif // LUAJIT_FLAVOR() == 64
256 256
@@ -262,14 +262,14 @@ lua_State* create_state(Universe* U_, lua_State* from_)
262 262
263// ################################################################################################# 263// #################################################################################################
264 264
265void call_on_state_create(Universe* U_, lua_State* L_, lua_State* from_, LookupMode mode_) 265void callOnStateCreate(Universe* U_, lua_State* L_, lua_State* from_, LookupMode mode_)
266{ 266{
267 if (U_->on_state_create_func != nullptr) { 267 if (U_->onStateCreateFunc != nullptr) {
268 STACK_CHECK_START_REL(L_, 0); 268 STACK_CHECK_START_REL(L_, 0);
269 DEBUGSPEW_CODE(fprintf(stderr, INDENT_BEGIN "calling on_state_create()\n" INDENT_END(U_))); 269 DEBUGSPEW_CODE(fprintf(stderr, INDENT_BEGIN "calling on_state_create()\n" INDENT_END(U_)));
270 if (U_->on_state_create_func != (lua_CFunction) initialize_on_state_create) { 270 if (U_->onStateCreateFunc != reinterpret_cast<lua_CFunction>(initializeOnStateCreate)) {
271 // C function: recreate a closure in the new state, bypassing the lookup scheme 271 // C function: recreate a closure in the new state, bypassing the lookup scheme
272 lua_pushcfunction(L_, U_->on_state_create_func); // on_state_create() 272 lua_pushcfunction(L_, U_->onStateCreateFunc); // on_state_create()
273 } else { // Lua function located in the config table, copied when we opened "lanes.core" 273 } else { // Lua function located in the config table, copied when we opened "lanes.core"
274 if (mode_ != LookupMode::LaneBody) { 274 if (mode_ != LookupMode::LaneBody) {
275 // if attempting to call in a keeper state, do nothing because the function doesn't exist there 275 // if attempting to call in a keeper state, do nothing because the function doesn't exist there
@@ -323,7 +323,7 @@ lua_State* luaG_newstate(Universe* U_, SourceState from_, char const* libs_)
323 STACK_CHECK(L, 0); 323 STACK_CHECK(L, 0);
324 324
325 // neither libs (not even 'base') nor special init func: we are done 325 // neither libs (not even 'base') nor special init func: we are done
326 if (libs_ == nullptr && U_->on_state_create_func == nullptr) { 326 if (libs_ == nullptr && U_->onStateCreateFunc == nullptr) {
327 DEBUGSPEW_CODE(fprintf(stderr, INDENT_BEGIN "luaG_newstate(nullptr)\n" INDENT_END(U_))); 327 DEBUGSPEW_CODE(fprintf(stderr, INDENT_BEGIN "luaG_newstate(nullptr)\n" INDENT_END(U_)));
328 return L; 328 return L;
329 } 329 }
@@ -384,7 +384,7 @@ lua_State* luaG_newstate(Universe* U_, SourceState from_, char const* libs_)
384 384
385 // call this after the base libraries are loaded and GC is restarted 385 // call this after the base libraries are loaded and GC is restarted
386 // will raise an error in from_ in case of problem 386 // will raise an error in from_ in case of problem
387 call_on_state_create(U_, L, from_, LookupMode::LaneBody); 387 callOnStateCreate(U_, L, from_, LookupMode::LaneBody);
388 388
389 STACK_CHECK(L, 0); 389 STACK_CHECK(L, 0);
390 // after all this, register everything we find in our name<->function database 390 // after all this, register everything we find in our name<->function database
@@ -398,7 +398,7 @@ lua_State* luaG_newstate(Universe* U_, SourceState from_, char const* libs_)
398 lua_pushnil(L); // L: {} nil 398 lua_pushnil(L); // L: {} nil
399 while (lua_next(L, -2)) { // L: {} k v 399 while (lua_next(L, -2)) { // L: {} k v
400 lua_getglobal(L, "print"); // L: {} k v print 400 lua_getglobal(L, "print"); // L: {} k v print
401 int const indent{ U_->debugspew_indent_depth.load(std::memory_order_relaxed) }; 401 int const indent{ U_->debugspewIndentDepth.load(std::memory_order_relaxed) };
402 lua_pushlstring(L, DebugSpewIndentScope::debugspew_indent, indent); // L: {} k v print " " 402 lua_pushlstring(L, DebugSpewIndentScope::debugspew_indent, indent); // L: {} k v print " "
403 lua_pushvalue(L, -4); // L: {} k v print " " k 403 lua_pushvalue(L, -4); // L: {} k v print " " k
404 lua_pushvalue(L, -4); // L: {} k v print " " k v 404 lua_pushvalue(L, -4); // L: {} k v print " " k v