aboutsummaryrefslogtreecommitdiff
path: root/src/deep.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/deep.cpp')
-rw-r--r--src/deep.cpp41
1 files changed, 20 insertions, 21 deletions
diff --git a/src/deep.cpp b/src/deep.cpp
index 1aab6ed..cd5a844 100644
--- a/src/deep.cpp
+++ b/src/deep.cpp
@@ -74,16 +74,16 @@ static constexpr UniqueKey DEEP_PROXY_CACHE_KEY{ 0x05773d6fc26be106ull };
74static void set_deep_lookup( lua_State* L) 74static void set_deep_lookup( lua_State* L)
75{ 75{
76 STACK_GROW( L, 3); 76 STACK_GROW( L, 3);
77 STACK_CHECK( L, 2); // a b 77 STACK_CHECK_START_REL(L, 2); // a b
78 push_registry_subtable( L, DEEP_LOOKUP_KEY); // a b {} 78 push_registry_subtable( L, DEEP_LOOKUP_KEY); // a b {}
79 STACK_MID( L, 3); 79 STACK_CHECK( L, 3);
80 lua_insert( L, -3); // {} a b 80 lua_insert( L, -3); // {} a b
81 lua_pushvalue( L, -1); // {} a b b 81 lua_pushvalue( L, -1); // {} a b b
82 lua_pushvalue( L,-3); // {} a b b a 82 lua_pushvalue( L,-3); // {} a b b a
83 lua_rawset( L, -5); // {} a b 83 lua_rawset( L, -5); // {} a b
84 lua_rawset( L, -3); // {} 84 lua_rawset( L, -3); // {}
85 lua_pop( L, 1); // 85 lua_pop( L, 1); //
86 STACK_END( L, 0); 86 STACK_CHECK( L, 0);
87} 87}
88 88
89/* 89/*
@@ -93,7 +93,7 @@ static void set_deep_lookup( lua_State* L)
93static void get_deep_lookup( lua_State* L) 93static void get_deep_lookup( lua_State* L)
94{ 94{
95 STACK_GROW( L, 1); 95 STACK_GROW( L, 1);
96 STACK_CHECK( L, 1); // a 96 STACK_CHECK_START_REL(L, 1); // a
97 DEEP_LOOKUP_KEY.query_registry(L); // a {} 97 DEEP_LOOKUP_KEY.query_registry(L); // a {}
98 if( !lua_isnil( L, -1)) 98 if( !lua_isnil( L, -1))
99 { 99 {
@@ -101,7 +101,7 @@ static void get_deep_lookup( lua_State* L)
101 lua_rawget( L, -2); // {} b 101 lua_rawget( L, -2); // {} b
102 } 102 }
103 lua_remove( L, -2); // a|b 103 lua_remove( L, -2); // a|b
104 STACK_END( L, 1); 104 STACK_CHECK( L, 1);
105} 105}
106 106
107/* 107/*
@@ -122,9 +122,8 @@ static inline luaG_IdFunction* get_idfunc( lua_State* L, int index, LookupMode m
122 // essentially we are making sure that the metatable of the object we want to copy is stored in our metatable/idfunc database 122 // essentially we are making sure that the metatable of the object we want to copy is stored in our metatable/idfunc database
123 // it is the only way to ensure that the userdata is indeed a deep userdata! 123 // it is the only way to ensure that the userdata is indeed a deep userdata!
124 // of course, we could just trust the caller, but we won't 124 // of course, we could just trust the caller, but we won't
125 luaG_IdFunction* ret;
126 STACK_GROW( L, 1); 125 STACK_GROW( L, 1);
127 STACK_CHECK( L, 0); 126 STACK_CHECK_START_REL(L, 0);
128 127
129 if( !lua_getmetatable( L, index)) // deep ... metatable? 128 if( !lua_getmetatable( L, index)) // deep ... metatable?
130 { 129 {
@@ -134,9 +133,9 @@ static inline luaG_IdFunction* get_idfunc( lua_State* L, int index, LookupMode m
134 // replace metatable with the idfunc pointer, if it is actually a deep userdata 133 // replace metatable with the idfunc pointer, if it is actually a deep userdata
135 get_deep_lookup( L); // deep ... idfunc|nil 134 get_deep_lookup( L); // deep ... idfunc|nil
136 135
137 ret = (luaG_IdFunction*) lua_touserdata( L, -1); // nullptr if not a userdata 136 luaG_IdFunction* const ret{ static_cast<luaG_IdFunction*>(lua_touserdata(L, -1)) }; // nullptr if not a userdata
138 lua_pop( L, 1); 137 lua_pop( L, 1);
139 STACK_END( L, 0); 138 STACK_CHECK( L, 0);
140 return ret; 139 return ret;
141 } 140 }
142} 141}
@@ -228,7 +227,7 @@ char const* push_deep_proxy( Universe* U, lua_State* L, DeepPrelude* prelude, in
228 if( U) MUTEX_UNLOCK( &U->deep_lock); 227 if( U) MUTEX_UNLOCK( &U->deep_lock);
229 228
230 STACK_GROW( L, 7); 229 STACK_GROW( L, 7);
231 STACK_CHECK( L, 0); 230 STACK_CHECK_START_REL(L, 0);
232 231
233 // a new full userdata, fitted with the specified number of uservalue slots (always 1 for Lua < 5.4) 232 // a new full userdata, fitted with the specified number of uservalue slots (always 1 for Lua < 5.4)
234 proxy = (DeepPrelude**) lua_newuserdatauv( L, sizeof(DeepPrelude*), nuv_); // DPC proxy 233 proxy = (DeepPrelude**) lua_newuserdatauv( L, sizeof(DeepPrelude*), nuv_); // DPC proxy
@@ -340,7 +339,7 @@ char const* push_deep_proxy( Universe* U, lua_State* L, DeepPrelude* prelude, in
340 } 339 }
341 } 340 }
342 } 341 }
343 STACK_MID( L, 2); // DPC proxy metatable 342 STACK_CHECK( L, 2); // DPC proxy metatable
344 ASSERT_L( lua_isuserdata( L, -2)); 343 ASSERT_L( lua_isuserdata( L, -2));
345 ASSERT_L( lua_istable( L, -1)); 344 ASSERT_L( lua_istable( L, -1));
346 lua_setmetatable( L, -2); // DPC proxy 345 lua_setmetatable( L, -2); // DPC proxy
@@ -351,7 +350,7 @@ char const* push_deep_proxy( Universe* U, lua_State* L, DeepPrelude* prelude, in
351 lua_rawset( L, -4); // DPC proxy 350 lua_rawset( L, -4); // DPC proxy
352 lua_remove( L, -2); // proxy 351 lua_remove( L, -2); // proxy
353 ASSERT_L( lua_isuserdata( L, -1)); 352 ASSERT_L( lua_isuserdata( L, -1));
354 STACK_END( L, 0); 353 STACK_CHECK( L, 0);
355 return nullptr; 354 return nullptr;
356} 355}
357 356
@@ -382,7 +381,7 @@ int luaG_newdeepuserdata( lua_State* L, luaG_IdFunction* idfunc, int nuv_)
382 char const* errmsg; 381 char const* errmsg;
383 382
384 STACK_GROW( L, 1); 383 STACK_GROW( L, 1);
385 STACK_CHECK( L, 0); 384 STACK_CHECK_START_REL(L, 0);
386 { 385 {
387 int const oldtop = lua_gettop( L); 386 int const oldtop = lua_gettop( L);
388 DeepPrelude* prelude = (DeepPrelude*) idfunc( L, eDO_new); 387 DeepPrelude* prelude = (DeepPrelude*) idfunc( L, eDO_new);
@@ -413,7 +412,7 @@ int luaG_newdeepuserdata( lua_State* L, luaG_IdFunction* idfunc, int nuv_)
413 return luaL_error( L, errmsg); 412 return luaL_error( L, errmsg);
414 } 413 }
415 } 414 }
416 STACK_END( L, 1); 415 STACK_CHECK( L, 1);
417 return 1; 416 return 1;
418} 417}
419 418
@@ -428,7 +427,7 @@ void* luaG_todeep( lua_State* L, luaG_IdFunction* idfunc, int index)
428{ 427{
429 DeepPrelude** proxy; 428 DeepPrelude** proxy;
430 429
431 STACK_CHECK( L, 0); 430 STACK_CHECK_START_REL(L, 0);
432 // ensure it is actually a deep userdata 431 // ensure it is actually a deep userdata
433 if( get_idfunc( L, index, eLM_LaneBody) != idfunc) 432 if( get_idfunc( L, index, eLM_LaneBody) != idfunc)
434 { 433 {
@@ -436,7 +435,7 @@ void* luaG_todeep( lua_State* L, luaG_IdFunction* idfunc, int index)
436 } 435 }
437 436
438 proxy = (DeepPrelude**) lua_touserdata( L, index); 437 proxy = (DeepPrelude**) lua_touserdata( L, index);
439 STACK_END( L, 0); 438 STACK_CHECK( L, 0);
440 439
441 return *proxy; 440 return *proxy;
442} 441}
@@ -460,8 +459,8 @@ bool copydeep(Universe* U, lua_State* L2, int L2_cache_i, lua_State* L, int i, L
460 return false; // not a deep userdata 459 return false; // not a deep userdata
461 } 460 }
462 461
463 STACK_CHECK( L, 0); 462 STACK_CHECK_START_REL(L, 0);
464 STACK_CHECK( L2, 0); 463 STACK_CHECK_START_REL(L2, 0);
465 464
466 // extract all uservalues of the source 465 // extract all uservalues of the source
467 while( lua_getiuservalue( L, i, nuv + 1) != LUA_TNONE) // ... u [uv]* nil 466 while( lua_getiuservalue( L, i, nuv + 1) != LUA_TNONE) // ... u [uv]* nil
@@ -470,7 +469,7 @@ bool copydeep(Universe* U, lua_State* L2, int L2_cache_i, lua_State* L, int i, L
470 } 469 }
471 // last call returned TNONE and pushed nil, that we don't need 470 // last call returned TNONE and pushed nil, that we don't need
472 lua_pop( L, 1); // ... u [uv]* 471 lua_pop( L, 1); // ... u [uv]*
473 STACK_MID( L, nuv); 472 STACK_CHECK( L, nuv);
474 473
475 errmsg = push_deep_proxy( U, L2, *(DeepPrelude**) lua_touserdata( L, i), nuv, mode_); // u 474 errmsg = push_deep_proxy( U, L2, *(DeepPrelude**) lua_touserdata( L, i), nuv, mode_); // u
476 475
@@ -487,8 +486,8 @@ bool copydeep(Universe* U, lua_State* L2, int L2_cache_i, lua_State* L, int i, L
487 } 486 }
488 } 487 }
489 488
490 STACK_END( L2, 1); 489 STACK_CHECK( L2, 1);
491 STACK_END( L, 0); 490 STACK_CHECK( L, 0);
492 491
493 if (errmsg != nullptr) 492 if (errmsg != nullptr)
494 { 493 {