aboutsummaryrefslogtreecommitdiff
path: root/src/tools.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/tools.cpp')
-rw-r--r--src/tools.cpp82
1 files changed, 41 insertions, 41 deletions
diff --git a/src/tools.cpp b/src/tools.cpp
index 6f4a06a..e6ebdba 100644
--- a/src/tools.cpp
+++ b/src/tools.cpp
@@ -48,7 +48,7 @@ THE SOFTWARE.
48#include "uniquekey.h" 48#include "uniquekey.h"
49 49
50// functions implemented in deep.c 50// functions implemented in deep.c
51extern bool_t copydeep( Universe* U, lua_State* L2, uint_t L2_cache_i, lua_State* L, uint_t i, LookupMode mode_, char const* upName_); 51extern bool copydeep( Universe* U, lua_State* L2, uint_t L2_cache_i, lua_State* L, uint_t i, LookupMode mode_, char const* upName_);
52extern void push_registry_subtable( lua_State* L, UniqueKey key_); 52extern void push_registry_subtable( lua_State* L, UniqueKey key_);
53 53
54DEBUGSPEW_CODE( char const* debugspew_indent = "----+----!----+----!----+----!----+----!----+----!----+----!----+----!----+"); 54DEBUGSPEW_CODE( char const* debugspew_indent = "----+----!----+----!----+----!----+----!----+----!----+----!----+----!----+");
@@ -766,14 +766,14 @@ static char const* find_lookup_name( lua_State* L, uint_t i, LookupMode mode_, c
766/* 766/*
767 * Push a looked-up table, or nothing if we found nothing 767 * Push a looked-up table, or nothing if we found nothing
768 */ 768 */
769static bool_t lookup_table( lua_State* L2, lua_State* L, uint_t i, LookupMode mode_, char const* upName_) 769static bool lookup_table( lua_State* L2, lua_State* L, uint_t i, LookupMode mode_, char const* upName_)
770{ 770{
771 // get the name of the table we want to send 771 // get the name of the table we want to send
772 size_t len; 772 size_t len;
773 char const* fqn = find_lookup_name( L, i, mode_, upName_, &len); 773 char const* fqn = find_lookup_name( L, i, mode_, upName_, &len);
774 if( NULL == fqn) // name not found, it is some user-created table 774 if( NULL == fqn) // name not found, it is some user-created table
775 { 775 {
776 return FALSE; 776 return false;
777 } 777 }
778 // push the equivalent table in the destination's stack, retrieved from the lookup table 778 // push the equivalent table in the destination's stack, retrieved from the lookup table
779 STACK_CHECK( L2, 0); // L // L2 779 STACK_CHECK( L2, 0); // L // L2
@@ -782,7 +782,7 @@ static bool_t lookup_table( lua_State* L2, lua_State* L, uint_t i, LookupMode mo
782 { 782 {
783 default: // shouldn't happen, in theory... 783 default: // shouldn't happen, in theory...
784 (void) luaL_error( L, "internal error: unknown lookup mode"); 784 (void) luaL_error( L, "internal error: unknown lookup mode");
785 return FALSE; 785 return false;
786 786
787 case eLM_ToKeeper: 787 case eLM_ToKeeper:
788 // push a sentinel closure that holds the lookup name as upvalue 788 // push a sentinel closure that holds the lookup name as upvalue
@@ -803,7 +803,7 @@ static bool_t lookup_table( lua_State* L2, lua_State* L, uint_t i, LookupMode mo
803 { 803 {
804 lua_pop( L2, 2); // 804 lua_pop( L2, 2); //
805 STACK_MID( L2, 0); 805 STACK_MID( L2, 0);
806 return FALSE; 806 return false;
807 } 807 }
808 else if( !lua_istable( L2, -1)) 808 else if( !lua_istable( L2, -1))
809 { 809 {
@@ -822,13 +822,13 @@ static bool_t lookup_table( lua_State* L2, lua_State* L, uint_t i, LookupMode mo
822 , fqn 822 , fqn
823 , to ? to : "main" 823 , to ? to : "main"
824 ); 824 );
825 return FALSE; 825 return false;
826 } 826 }
827 lua_remove( L2, -2); // t 827 lua_remove( L2, -2); // t
828 break; 828 break;
829 } 829 }
830 STACK_END( L2, 1); 830 STACK_END( L2, 1);
831 return TRUE; 831 return true;
832} 832}
833 833
834 834
@@ -839,12 +839,12 @@ static bool_t lookup_table( lua_State* L2, lua_State* L, uint_t i, LookupMode mo
839 * 839 *
840 * Always pushes a table to 'L2'. 840 * Always pushes a table to 'L2'.
841 * 841 *
842 * Returns TRUE if the table was cached (no need to fill it!); FALSE if 842 * Returns true if the table was cached (no need to fill it!); false if
843 * it's a virgin. 843 * it's a virgin.
844 */ 844 */
845static bool_t push_cached_table( lua_State* L2, uint_t L2_cache_i, lua_State* L, uint_t i) 845static bool push_cached_table( lua_State* L2, uint_t L2_cache_i, lua_State* L, uint_t i)
846{ 846{
847 bool_t not_found_in_cache; // L2 847 bool not_found_in_cache; // L2
848 DECLARE_CONST_UNIQUE_KEY( p, lua_topointer( L, i)); 848 DECLARE_CONST_UNIQUE_KEY( p, lua_topointer( L, i));
849 849
850 ASSERT_L( L2_cache_i != 0); 850 ASSERT_L( L2_cache_i != 0);
@@ -854,11 +854,11 @@ static bool_t push_cached_table( lua_State* L2, uint_t L2_cache_i, lua_State* L,
854 // We don't need to use the from state ('L') in ID since the life span 854 // We don't need to use the from state ('L') in ID since the life span
855 // is only for the duration of a copy (both states are locked). 855 // is only for the duration of a copy (both states are locked).
856 // push a light userdata uniquely representing the table 856 // push a light userdata uniquely representing the table
857 push_unique_key( L2, p); // ... p 857 push_unique_key( L2, p); // ... p
858 858
859 //fprintf( stderr, "<< ID: %s >>\n", lua_tostring( L2, -1)); 859 //fprintf( stderr, "<< ID: %s >>\n", lua_tostring( L2, -1));
860 860
861 lua_rawget( L2, L2_cache_i); // ... {cached|nil} 861 lua_rawget( L2, L2_cache_i); // ... {cached|nil}
862 not_found_in_cache = lua_isnil( L2, -1); 862 not_found_in_cache = lua_isnil( L2, -1);
863 if( not_found_in_cache) 863 if( not_found_in_cache)
864 { 864 {
@@ -1391,7 +1391,7 @@ static void copy_cached_func( Universe* U, lua_State* L2, uint_t L2_cache_i, lua
1391 } 1391 }
1392} 1392}
1393 1393
1394static bool_t push_cached_metatable( Universe* U, lua_State* L2, uint_t L2_cache_i, lua_State* L, uint_t i, enum eLookupMode mode_, char const* upName_) 1394static bool push_cached_metatable( Universe* U, lua_State* L2, uint_t L2_cache_i, lua_State* L, uint_t i, enum eLookupMode mode_, char const* upName_)
1395{ 1395{
1396 STACK_CHECK( L, 0); 1396 STACK_CHECK( L, 0);
1397 if( lua_getmetatable( L, i)) // ... mt 1397 if( lua_getmetatable( L, i)) // ... mt
@@ -1434,10 +1434,10 @@ static bool_t push_cached_metatable( Universe* U, lua_State* L2, uint_t L2_cache
1434 lua_pop( L, 1); // ... 1434 lua_pop( L, 1); // ...
1435 STACK_END( L2, 1); 1435 STACK_END( L2, 1);
1436 STACK_MID( L, 0); 1436 STACK_MID( L, 0);
1437 return TRUE; 1437 return true;
1438 } 1438 }
1439 STACK_END( L, 0); 1439 STACK_END( L, 0);
1440 return FALSE; 1440 return false;
1441} 1441}
1442 1442
1443static void inter_copy_keyvaluepair( Universe* U, lua_State* L2, uint_t L2_cache_i, lua_State* L, enum e_vt vt, LookupMode mode_, char const* upName_) 1443static void inter_copy_keyvaluepair( Universe* U, lua_State* L2, uint_t L2_cache_i, lua_State* L, enum e_vt vt, LookupMode mode_, char const* upName_)
@@ -1510,7 +1510,7 @@ static void inter_copy_keyvaluepair( Universe* U, lua_State* L2, uint_t L2_cache
1510*/ 1510*/
1511static DECLARE_CONST_UNIQUE_KEY( CLONABLES_CACHE_KEY, 0xD04EE018B3DEE8F5); 1511static DECLARE_CONST_UNIQUE_KEY( CLONABLES_CACHE_KEY, 0xD04EE018B3DEE8F5);
1512 1512
1513static bool_t copyclone( Universe* U, lua_State* L2, uint_t L2_cache_i, lua_State* L, uint_t source_i_, LookupMode mode_, char const* upName_) 1513static bool copyclone( Universe* U, lua_State* L2, uint_t L2_cache_i, lua_State* L, uint_t source_i_, LookupMode mode_, char const* upName_)
1514{ 1514{
1515 void* const source = lua_touserdata( L, source_i_); 1515 void* const source = lua_touserdata( L, source_i_);
1516 source_i_ = lua_absindex( L, source_i_); 1516 source_i_ = lua_absindex( L, source_i_);
@@ -1524,7 +1524,7 @@ static bool_t copyclone( Universe* U, lua_State* L2, uint_t L2_cache_i, lua_Stat
1524 if ( !lua_isnil( L2, -1)) 1524 if ( !lua_isnil( L2, -1))
1525 { 1525 {
1526 STACK_MID( L2, 1); 1526 STACK_MID( L2, 1);
1527 return TRUE; 1527 return true;
1528 } 1528 }
1529 else 1529 else
1530 { 1530 {
@@ -1536,7 +1536,7 @@ static bool_t copyclone( Universe* U, lua_State* L2, uint_t L2_cache_i, lua_Stat
1536 if( !lua_getmetatable( L, source_i_)) // ... mt? 1536 if( !lua_getmetatable( L, source_i_)) // ... mt?
1537 { 1537 {
1538 STACK_MID( L, 0); 1538 STACK_MID( L, 0);
1539 return FALSE; 1539 return false;
1540 } 1540 }
1541 1541
1542 // no __lanesclone? -> not clonable 1542 // no __lanesclone? -> not clonable
@@ -1545,7 +1545,7 @@ static bool_t copyclone( Universe* U, lua_State* L2, uint_t L2_cache_i, lua_Stat
1545 { 1545 {
1546 lua_pop( L, 2); // ... 1546 lua_pop( L, 2); // ...
1547 STACK_MID( L, 0); 1547 STACK_MID( L, 0);
1548 return FALSE; 1548 return false;
1549 } 1549 }
1550 1550
1551 // we need to copy over the uservalues of the userdata as well 1551 // we need to copy over the uservalues of the userdata as well
@@ -1620,16 +1620,16 @@ static bool_t copyclone( Universe* U, lua_State* L2, uint_t L2_cache_i, lua_Stat
1620 STACK_END( L2, 1); 1620 STACK_END( L2, 1);
1621 lua_pop( L, 1); // ... 1621 lua_pop( L, 1); // ...
1622 STACK_END( L, 0); 1622 STACK_END( L, 0);
1623 return TRUE; 1623 return true;
1624} 1624}
1625 1625
1626static bool_t inter_copy_userdata( Universe* U, lua_State* L2, uint_t L2_cache_i, lua_State* L, uint_t i, enum e_vt vt, LookupMode mode_, char const* upName_) 1626static bool inter_copy_userdata( Universe* U, lua_State* L2, uint_t L2_cache_i, lua_State* L, uint_t i, enum e_vt vt, LookupMode mode_, char const* upName_)
1627{ 1627{
1628 STACK_CHECK( L, 0); 1628 STACK_CHECK( L, 0);
1629 STACK_CHECK( L2, 0); 1629 STACK_CHECK( L2, 0);
1630 if( vt == VT_KEY) 1630 if( vt == VT_KEY)
1631 { 1631 {
1632 return FALSE; 1632 return false;
1633 } 1633 }
1634 1634
1635 // try clonable userdata first 1635 // try clonable userdata first
@@ -1637,7 +1637,7 @@ static bool_t inter_copy_userdata( Universe* U, lua_State* L2, uint_t L2_cache_i
1637 { 1637 {
1638 STACK_MID( L, 0); 1638 STACK_MID( L, 0);
1639 STACK_MID( L2, 1); 1639 STACK_MID( L2, 1);
1640 return TRUE; 1640 return true;
1641 } 1641 }
1642 1642
1643 STACK_MID( L, 0); 1643 STACK_MID( L, 0);
@@ -1649,7 +1649,7 @@ static bool_t inter_copy_userdata( Universe* U, lua_State* L2, uint_t L2_cache_i
1649 { 1649 {
1650 STACK_MID( L, 0); 1650 STACK_MID( L, 0);
1651 STACK_MID( L2, 1); 1651 STACK_MID( L2, 1);
1652 return TRUE; 1652 return true;
1653 } 1653 }
1654 1654
1655 STACK_MID( L, 0); 1655 STACK_MID( L, 0);
@@ -1668,14 +1668,14 @@ static bool_t inter_copy_userdata( Universe* U, lua_State* L2, uint_t L2_cache_i
1668 1668
1669 STACK_END( L2, 1); 1669 STACK_END( L2, 1);
1670 STACK_END( L, 0); 1670 STACK_END( L, 0);
1671 return TRUE; 1671 return true;
1672} 1672}
1673 1673
1674static bool_t inter_copy_function( Universe* U, lua_State* L2, uint_t L2_cache_i, lua_State* L, uint_t source_i_, enum e_vt vt, LookupMode mode_, char const* upName_) 1674static bool inter_copy_function( Universe* U, lua_State* L2, uint_t L2_cache_i, lua_State* L, uint_t source_i_, enum e_vt vt, LookupMode mode_, char const* upName_)
1675{ 1675{
1676 if( vt == VT_KEY) 1676 if( vt == VT_KEY)
1677 { 1677 {
1678 return FALSE; 1678 return false;
1679 } 1679 }
1680 1680
1681 STACK_CHECK( L, 0); // L (source) // L2 (destination) 1681 STACK_CHECK( L, 0); // L (source) // L2 (destination)
@@ -1699,7 +1699,7 @@ static bool_t inter_copy_function( Universe* U, lua_State* L2, uint_t L2_cache_i
1699 lua_pop( L, 1); // ... 1699 lua_pop( L, 1); // ...
1700 STACK_MID( L, 0); 1700 STACK_MID( L, 0);
1701 STACK_MID( L2, 1); 1701 STACK_MID( L2, 1);
1702 return TRUE; 1702 return true;
1703 } 1703 }
1704 lua_pop( L2, 1); // ... 1704 lua_pop( L2, 1); // ...
1705 1705
@@ -1761,14 +1761,14 @@ static bool_t inter_copy_function( Universe* U, lua_State* L2, uint_t L2_cache_i
1761 } 1761 }
1762 STACK_END( L2, 1); 1762 STACK_END( L2, 1);
1763 STACK_END( L, 0); 1763 STACK_END( L, 0);
1764 return TRUE; 1764 return true;
1765} 1765}
1766 1766
1767static bool_t inter_copy_table( Universe* U, lua_State* L2, uint_t L2_cache_i, lua_State* L, uint_t i, enum e_vt vt, LookupMode mode_, char const* upName_) 1767static bool inter_copy_table( Universe* U, lua_State* L2, uint_t L2_cache_i, lua_State* L, uint_t i, enum e_vt vt, LookupMode mode_, char const* upName_)
1768{ 1768{
1769 if( vt == VT_KEY) 1769 if( vt == VT_KEY)
1770 { 1770 {
1771 return FALSE; 1771 return false;
1772 } 1772 }
1773 1773
1774 STACK_CHECK( L, 0); 1774 STACK_CHECK( L, 0);
@@ -1782,7 +1782,7 @@ static bool_t inter_copy_table( Universe* U, lua_State* L2, uint_t L2_cache_i, l
1782 if( lookup_table( L2, L, i, mode_, upName_)) 1782 if( lookup_table( L2, L, i, mode_, upName_))
1783 { 1783 {
1784 ASSERT_L( lua_istable( L2, -1) || (lua_tocfunction( L2, -1) == table_lookup_sentinel)); // from lookup datables // can also be table_lookup_sentinel if this is a table we know 1784 ASSERT_L( lua_istable( L2, -1) || (lua_tocfunction( L2, -1) == table_lookup_sentinel)); // from lookup datables // can also be table_lookup_sentinel if this is a table we know
1785 return TRUE; 1785 return true;
1786 } 1786 }
1787 1787
1788 /* Check if we've already copied the same table from 'L' (during this transmission), and 1788 /* Check if we've already copied the same table from 'L' (during this transmission), and
@@ -1797,7 +1797,7 @@ static bool_t inter_copy_table( Universe* U, lua_State* L2, uint_t L2_cache_i, l
1797 if( push_cached_table( L2, L2_cache_i, L, i)) 1797 if( push_cached_table( L2, L2_cache_i, L, i))
1798 { 1798 {
1799 ASSERT_L( lua_istable( L2, -1)); // from cache 1799 ASSERT_L( lua_istable( L2, -1)); // from cache
1800 return TRUE; 1800 return true;
1801 } 1801 }
1802 ASSERT_L( lua_istable( L2, -1)); 1802 ASSERT_L( lua_istable( L2, -1));
1803 1803
@@ -1821,7 +1821,7 @@ static bool_t inter_copy_table( Universe* U, lua_State* L2, uint_t L2_cache_i, l
1821 } 1821 }
1822 STACK_END( L2, 1); 1822 STACK_END( L2, 1);
1823 STACK_END( L, 0); 1823 STACK_END( L, 0);
1824 return TRUE; 1824 return true;
1825} 1825}
1826 1826
1827/* 1827/*
@@ -1832,11 +1832,11 @@ static bool_t inter_copy_table( Universe* U, lua_State* L2, uint_t L2_cache_i, l
1832* 1832*
1833* 'i' is an absolute index (no -1, ...) 1833* 'i' is an absolute index (no -1, ...)
1834* 1834*
1835* Returns TRUE if value was pushed, FALSE if its type is non-supported. 1835* Returns true if value was pushed, false if its type is non-supported.
1836*/ 1836*/
1837bool_t inter_copy_one( Universe* U, lua_State* L2, uint_t L2_cache_i, lua_State* L, uint_t i, enum e_vt vt, LookupMode mode_, char const* upName_) 1837bool inter_copy_one( Universe* U, lua_State* L2, uint_t L2_cache_i, lua_State* L, uint_t i, enum e_vt vt, LookupMode mode_, char const* upName_)
1838{ 1838{
1839 bool_t ret = TRUE; 1839 bool ret{ true };
1840 int val_type = lua_type( L, i); 1840 int val_type = lua_type( L, i);
1841 static int const pod_mask = (1 << LUA_TNIL) | (1 << LUA_TBOOLEAN) | (1 << LUA_TLIGHTUSERDATA) | (1 << LUA_TNUMBER) | (1 << LUA_TSTRING); 1841 static int const pod_mask = (1 << LUA_TNIL) | (1 << LUA_TBOOLEAN) | (1 << LUA_TLIGHTUSERDATA) | (1 << LUA_TNUMBER) | (1 << LUA_TSTRING);
1842 STACK_GROW( L2, 1); 1842 STACK_GROW( L2, 1);
@@ -1870,7 +1870,7 @@ bool_t inter_copy_one( Universe* U, lua_State* L2, uint_t L2_cache_i, lua_State*
1870 1870
1871 case LUA_TBOOLEAN: 1871 case LUA_TBOOLEAN:
1872 { 1872 {
1873 bool_t v = lua_toboolean( L, i); 1873 int const v{ lua_toboolean(L, i) };
1874 DEBUGSPEW_CODE( fprintf( stderr, "%s\n", v ? "true" : "false")); 1874 DEBUGSPEW_CODE( fprintf( stderr, "%s\n", v ? "true" : "false"));
1875 lua_pushboolean( L2, v); 1875 lua_pushboolean( L2, v);
1876 } 1876 }
@@ -1921,7 +1921,7 @@ bool_t inter_copy_one( Universe* U, lua_State* L2, uint_t L2_cache_i, lua_State*
1921 case LUA_TNIL: 1921 case LUA_TNIL:
1922 if( vt == VT_KEY) 1922 if( vt == VT_KEY)
1923 { 1923 {
1924 ret = FALSE; 1924 ret = false;
1925 break; 1925 break;
1926 } 1926 }
1927 lua_pushnil( L2); 1927 lua_pushnil( L2);
@@ -1939,7 +1939,7 @@ bool_t inter_copy_one( Universe* U, lua_State* L2, uint_t L2_cache_i, lua_State*
1939 1939
1940 case 10: // LuaJIT CDATA 1940 case 10: // LuaJIT CDATA
1941 case LUA_TTHREAD: 1941 case LUA_TTHREAD:
1942 ret = FALSE; 1942 ret = false;
1943 break; 1943 break;
1944 } 1944 }
1945 1945
@@ -1964,7 +1964,7 @@ int luaG_inter_copy( Universe* U, lua_State* L, lua_State* L2, uint_t n, LookupM
1964 uint_t i, j; 1964 uint_t i, j;
1965 char tmpBuf[16]; 1965 char tmpBuf[16];
1966 char const* pBuf = U->verboseErrors ? tmpBuf : "?"; 1966 char const* pBuf = U->verboseErrors ? tmpBuf : "?";
1967 bool_t copyok = TRUE; 1967 bool copyok{ true };
1968 1968
1969 DEBUGSPEW_CODE( fprintf( stderr, INDENT_BEGIN "luaG_inter_copy()\n" INDENT_END)); 1969 DEBUGSPEW_CODE( fprintf( stderr, INDENT_BEGIN "luaG_inter_copy()\n" INDENT_END));
1970 DEBUGSPEW_CODE( ++ U->debugspew_indent_depth); 1970 DEBUGSPEW_CODE( ++ U->debugspew_indent_depth);