diff options
author | Benoit Germain <bnt period germain arrobase gmail period com> | 2017-05-12 10:24:32 +0200 |
---|---|---|
committer | Benoit Germain <bnt period germain arrobase gmail period com> | 2017-05-12 10:24:32 +0200 |
commit | e75210b564d06ed7b3a377ad5463d9bc48ad9835 (patch) | |
tree | 40ec0131246380b065370ac6b5398c4eaa531f10 | |
parent | f52a6dabba0f6739979fe6312a2c28d02e594a9f (diff) | |
download | lanes-e75210b564d06ed7b3a377ad5463d9bc48ad9835.tar.gz lanes-e75210b564d06ed7b3a377ad5463d9bc48ad9835.tar.bz2 lanes-e75210b564d06ed7b3a377ad5463d9bc48ad9835.zip |
Some code formatting and other non-changes
-rw-r--r-- | src/tools.c | 102 |
1 files changed, 52 insertions, 50 deletions
diff --git a/src/tools.c b/src/tools.c index 0e8d132..50a9310 100644 --- a/src/tools.c +++ b/src/tools.c | |||
@@ -8,7 +8,7 @@ | |||
8 | =============================================================================== | 8 | =============================================================================== |
9 | 9 | ||
10 | Copyright (C) 2002-10 Asko Kauppi <akauppi@gmail.com> | 10 | Copyright (C) 2002-10 Asko Kauppi <akauppi@gmail.com> |
11 | 2011-14 benoit Germain <bnt.germain@gmail.com> | 11 | 2011-17 benoit Germain <bnt.germain@gmail.com> |
12 | 12 | ||
13 | Permission is hereby granted, free of charge, to any person obtaining a copy | 13 | Permission is hereby granted, free of charge, to any person obtaining a copy |
14 | of this software and associated documentation files (the "Software"), to deal | 14 | of this software and associated documentation files (the "Software"), to deal |
@@ -71,48 +71,52 @@ DEBUGSPEW_CODE( char const* debugspew_indent = "----+----!----+----!----+----!-- | |||
71 | 71 | ||
72 | /*---=== luaG_dump ===---*/ | 72 | /*---=== luaG_dump ===---*/ |
73 | 73 | ||
74 | void luaG_dump( lua_State* L ) { | 74 | void luaG_dump( lua_State* L) |
75 | 75 | { | |
76 | int top= lua_gettop(L); | 76 | int top = lua_gettop( L); |
77 | int i; | 77 | int i; |
78 | 78 | ||
79 | fprintf( stderr, "\n\tDEBUG STACK:\n" ); | 79 | fprintf( stderr, "\n\tDEBUG STACK:\n"); |
80 | 80 | ||
81 | if (top==0) | 81 | if( top == 0) |
82 | fprintf( stderr, "\t(none)\n" ); | 82 | fprintf( stderr, "\t(none)\n"); |
83 | 83 | ||
84 | for( i=1; i<=top; i++ ) { | 84 | for( i = 1; i <= top; ++ i) |
85 | int type= lua_type( L, i ); | 85 | { |
86 | int type = lua_type( L, i); | ||
86 | 87 | ||
87 | fprintf( stderr, "\t[%d]= (%s) ", i, lua_typename(L,type) ); | 88 | fprintf( stderr, "\t[%d]= (%s) ", i, lua_typename(L, type)); |
88 | 89 | ||
89 | // Print item contents here... | 90 | // Print item contents here... |
90 | // | 91 | // |
91 | // Note: this requires 'tostring()' to be defined. If it is NOT, | 92 | // Note: this requires 'tostring()' to be defined. If it is NOT, |
92 | // enable it for more debugging. | 93 | // enable it for more debugging. |
93 | // | 94 | // |
94 | STACK_CHECK( L); | 95 | STACK_CHECK( L); |
95 | STACK_GROW( L, 2); | 96 | STACK_GROW( L, 2); |
96 | 97 | ||
97 | lua_getglobal( L, "tostring" ); | 98 | lua_getglobal( L, "tostring"); |
98 | // | 99 | // |
99 | // [-1]: tostring function, or nil | 100 | // [-1]: tostring function, or nil |
100 | 101 | ||
101 | if (!lua_isfunction(L,-1)) { | 102 | if( !lua_isfunction(L, -1)) |
102 | fprintf( stderr, "('tostring' not available)" ); | 103 | { |
103 | } else { | 104 | fprintf( stderr, "('tostring' not available)"); |
104 | lua_pushvalue( L, i ); | ||
105 | lua_call( L, 1 /*args*/, 1 /*retvals*/ ); | ||
106 | |||
107 | // Don't trust the string contents | ||
108 | // | ||
109 | fprintf( stderr, "%s", lua_tostring(L,-1) ); | ||
110 | } | ||
111 | lua_pop(L,1); | ||
112 | STACK_END( L, 0); | ||
113 | fprintf( stderr, "\n" ); | ||
114 | } | 105 | } |
115 | fprintf( stderr, "\n" ); | 106 | else |
107 | { | ||
108 | lua_pushvalue( L, i); | ||
109 | lua_call( L, 1 /*args*/, 1 /*retvals*/); | ||
110 | |||
111 | // Don't trust the string contents | ||
112 | // | ||
113 | fprintf( stderr, "%s", lua_tostring(L, -1)); | ||
114 | } | ||
115 | lua_pop( L, 1); | ||
116 | STACK_END( L, 0); | ||
117 | fprintf( stderr, "\n"); | ||
118 | } | ||
119 | fprintf( stderr, "\n"); | ||
116 | } | 120 | } |
117 | 121 | ||
118 | void initialize_on_state_create( struct s_Universe* U, lua_State* L) | 122 | void initialize_on_state_create( struct s_Universe* U, lua_State* L) |
@@ -813,13 +817,13 @@ static int buf_writer( lua_State *L, const void* b, size_t n, void* B ) { | |||
813 | * Returns TRUE if the table was cached (no need to fill it!); FALSE if | 817 | * Returns TRUE if the table was cached (no need to fill it!); FALSE if |
814 | * it's a virgin. | 818 | * it's a virgin. |
815 | */ | 819 | */ |
816 | static bool_t push_cached_table( lua_State *L2, uint_t L2_cache_i, lua_State *L, uint_t i ) | 820 | static bool_t push_cached_table( lua_State* L2, uint_t L2_cache_i, lua_State* L, uint_t i) |
817 | { | 821 | { |
818 | bool_t ret; | 822 | bool_t ret; |
819 | 823 | ||
820 | ASSERT_L( L2_cache_i != 0 ); | 824 | ASSERT_L( L2_cache_i != 0); |
821 | 825 | ||
822 | STACK_GROW(L2,3); | 826 | STACK_GROW( L2, 3); |
823 | 827 | ||
824 | // L2_cache[id_str]= [{...}] | 828 | // L2_cache[id_str]= [{...}] |
825 | // | 829 | // |
@@ -828,33 +832,32 @@ static bool_t push_cached_table( lua_State *L2, uint_t L2_cache_i, lua_State *L, | |||
828 | // We don't need to use the from state ('L') in ID since the life span | 832 | // We don't need to use the from state ('L') in ID since the life span |
829 | // is only for the duration of a copy (both states are locked). | 833 | // is only for the duration of a copy (both states are locked). |
830 | // | 834 | // |
831 | lua_pushlightuserdata( L2, (void*)lua_topointer( L, i )); // push a light userdata uniquely representing the table | 835 | lua_pushlightuserdata( L2, (void*)lua_topointer( L, i)); // push a light userdata uniquely representing the table |
832 | 836 | ||
833 | //fprintf( stderr, "<< ID: %s >>\n", lua_tostring(L2,-1) ); | 837 | //fprintf( stderr, "<< ID: %s >>\n", lua_tostring(L2,-1) ); |
834 | 838 | ||
835 | lua_pushvalue( L2, -1 ); | 839 | lua_pushvalue( L2, -1); |
836 | lua_rawget( L2, L2_cache_i ); | 840 | lua_rawget( L2, L2_cache_i); |
837 | // | 841 | // |
838 | // [-2]: identity table pointer lightuserdata | 842 | // [-2]: identity table pointer lightuserdata |
839 | // [-1]: table|nil | 843 | // [-1]: table|nil |
840 | 844 | ||
841 | if (lua_isnil(L2,-1)) | 845 | if( lua_isnil( L2, -1)) |
842 | { | 846 | { |
843 | lua_pop(L2,1); | 847 | lua_pop( L2, 1); |
844 | lua_newtable(L2); | 848 | lua_newtable( L2); |
845 | lua_pushvalue(L2,-1); | 849 | lua_pushvalue( L2, -1); |
846 | lua_insert(L2,-3); | 850 | lua_insert( L2, -3); |
847 | // | 851 | // |
848 | // [-3]: new table (2nd ref) | 852 | // [-3]: new table (2nd ref) |
849 | // [-2]: identity table pointer lightuserdata | 853 | // [-2]: identity table pointer lightuserdata |
850 | // [-1]: new table | 854 | // [-1]: new table |
851 | 855 | ||
852 | lua_rawset(L2, L2_cache_i); | 856 | lua_rawset( L2, L2_cache_i); |
853 | // | 857 | // |
854 | // [-1]: new table (tied to 'L2_cache' table') | 858 | // [-1]: new table (tied to 'L2_cache' table') |
855 | 859 | ||
856 | ret= FALSE; // brand new | 860 | ret = FALSE; // brand new |
857 | |||
858 | } | 861 | } |
859 | else | 862 | else |
860 | { | 863 | { |
@@ -865,7 +868,7 @@ static bool_t push_cached_table( lua_State *L2, uint_t L2_cache_i, lua_State *L, | |||
865 | // | 868 | // |
866 | // L2 [-1]: table to use as destination | 869 | // L2 [-1]: table to use as destination |
867 | 870 | ||
868 | ASSERT_L( lua_istable(L2,-1) ); | 871 | ASSERT_L( lua_istable( L2, -1)); |
869 | return ret; | 872 | return ret; |
870 | } | 873 | } |
871 | 874 | ||
@@ -1537,7 +1540,7 @@ static bool_t inter_copy_one_( struct s_Universe* U, lua_State* L2, uint_t L2_ca | |||
1537 | * to the same subtable. | 1540 | * to the same subtable. |
1538 | * | 1541 | * |
1539 | * Note: Even metatables need to go through this test; to detect | 1542 | * Note: Even metatables need to go through this test; to detect |
1540 | * loops s.a. those in required module tables (getmetatable(lanes).lanes == lanes) | 1543 | * loops such as those in required module tables (getmetatable(lanes).lanes == lanes) |
1541 | */ | 1544 | */ |
1542 | if( push_cached_table( L2, L2_cache_i, L, i)) | 1545 | if( push_cached_table( L2, L2_cache_i, L, i)) |
1543 | { | 1546 | { |
@@ -1555,8 +1558,7 @@ static bool_t inter_copy_one_( struct s_Universe* U, lua_State* L2, uint_t L2_ca | |||
1555 | uint_t val_i = lua_gettop(L); | 1558 | uint_t val_i = lua_gettop(L); |
1556 | uint_t key_i = val_i - 1; | 1559 | uint_t key_i = val_i - 1; |
1557 | 1560 | ||
1558 | /* Only basic key types are copied over; others ignored | 1561 | // Only basic key types are copied over; others ignored |
1559 | */ | ||
1560 | if( inter_copy_one_( U, L2, 0 /*key*/, L, key_i, VT_KEY, mode_, upName_)) | 1562 | if( inter_copy_one_( U, L2, 0 /*key*/, L, key_i, VT_KEY, mode_, upName_)) |
1561 | { | 1563 | { |
1562 | char* valPath = (char*) upName_; | 1564 | char* valPath = (char*) upName_; |