Changeset 85 for trunk/src/lua/lua_raw.cc
- Timestamp:
- 06/02/13 18:25:29 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lua/lua_raw.cc
r51 r85 27 27 } 28 28 29 void nlua_pushreversed( lua_State *L, int index ) 30 { 31 index = lua_absindex( L, index ); 32 int len = lua_rawlen( L, index ); 33 int i = len; 34 lua_createtable( L, len, 0 ); 35 while ( i != 0 ) 36 { 37 lua_rawgeti( L, index, i ); 38 lua_rawseti( L, -2, len-i+1 ); 39 i--; 40 } 41 } 42 43 29 44 void nlua_shallowcopy( lua_State *L, int index ) 30 45 { 31 index = lua_absindex( L,index);32 lua_ newtable(L);33 lua_pushnil( L);46 index = lua_absindex( L, index ); 47 lua_createtable( L, 0, 0 ); 48 lua_pushnil( L ); 34 49 35 50 while ( lua_next( L, index ) != 0 ) 36 51 { 37 lua_pushvalue( L, -2);38 lua_insert( L, -2);39 lua_settable( L, -4);52 lua_pushvalue( L, -2 ); 53 lua_insert( L, -2 ); 54 lua_settable( L, -4 ); 40 55 } 56 } 57 58 void nlua_shallowicopy( lua_State *L, int index ) 59 { 60 index = lua_absindex( L, index ); 61 lua_createtable( L, 0, 0 ); 62 int i = 0; 63 for(;;) 64 { 65 i++; 66 lua_rawgeti( L, 1, i ); 67 if ( lua_isnil( L, -1 ) ) 68 { 69 lua_pop( L, 1 ); 70 break; 71 } 72 lua_rawseti( L, 2, i ); 73 }; 41 74 } 42 75 43 76 void nlua_shallowmerge( lua_State *L, int index ) 44 77 { 45 index = lua_absindex( L,index);46 lua_pushnil( L);78 index = lua_absindex( L, index ); 79 lua_pushnil( L ); 47 80 48 while( lua_next( L, index) != 0 )81 while( lua_next( L, index ) != 0 ) 49 82 { 50 lua_pushvalue( L, -2);51 lua_insert( L, -2);52 lua_rawset( L, -4);83 lua_pushvalue( L, -2 ); 84 lua_insert( L, -2 ); 85 lua_rawset( L, -4 ); 53 86 } 54 87 } … … 56 89 void nlua_deepcopy( lua_State *L, int index ) 57 90 { 58 index = lua_absindex( L,index);59 lua_ newtable(L);60 lua_pushnil( L);91 index = lua_absindex( L, index ); 92 lua_createtable( L, 0, 0 ); 93 lua_pushnil( L ); 61 94 62 95 while ( lua_next( L, index ) != 0 ) … … 68 101 lua_pop( L, 1 ); 69 102 } 70 lua_pushvalue( L, -2);71 lua_insert( L, -2);72 lua_settable( L, -4);103 lua_pushvalue( L, -2 ); 104 lua_insert( L, -2 ); 105 lua_settable( L, -4 ); 73 106 } 74 107 } 75 108 109 void nlua_toset( lua_State *L, int index ) 110 { 111 index = lua_absindex( L, index ); 112 lua_createtable( L, 0, 0 ); 113 int i = 0; 114 for(;;) 115 { 116 i++; 117 lua_rawgeti( L, index, i ); 118 if ( lua_isnil( L, -1 ) ) 119 { 120 lua_pop( L, 1 ); 121 break; 122 } 123 lua_pushboolean( L, true ); 124 lua_rawset( L, -3 ); 125 }; 126 } 127 128 void nlua_tokeyset( lua_State *L, int index ) 129 { 130 index = lua_absindex( L, index ); 131 lua_createtable( L, 0, 0 ); 132 lua_pushnil( L ); 133 while ( lua_next( L, index ) != 0 ) 134 { 135 lua_pushvalue( L, -2 ); 136 lua_pushboolean( L, true ); 137 lua_settable( L, -5 ); 138 lua_pop( L, 1 ); 139 } 140 } 141 142 void nlua_register( lua_State *L, const char* fname, lua_CFunction func, int index ) 143 { 144 index = lua_absindex( L, index ); 145 lua_pushstring( L, fname ); 146 lua_pushcfunction( L, func ); 147 lua_rawset( L, index ); 148 } 149 150 void nlua_register( lua_State *L, const luaL_Reg *l, int index ) 151 { 152 index = lua_absindex( L, index ); 153 for (; l->name != NULL; l++) 154 { 155 lua_pushstring( L, l->name ); 156 lua_pushcfunction( L, l->func ); 157 lua_rawset( L, index ); 158 } 159 } 160 161 void nlua_register( lua_State *L, const char* lname, const char* fname, lua_CFunction func ) 162 { 163 lua_getglobal( L, lname ); 164 if ( !lua_istable( L, -1 ) ) 165 { 166 lua_pop( L, 1 ); 167 lua_createtable( L, 0, 0 ); 168 nlua_register( L, fname, func, -1 ); 169 lua_setglobal( L, lname ); 170 return; 171 } 172 nlua_register( L, fname, func, -1 ); 173 lua_pop( L, 1 ); 174 } 175 176 void nlua_register( lua_State *L, const char* lname, const luaL_Reg *l ) 177 { 178 lua_getglobal( L, lname ); 179 if ( !lua_istable( L, -1 ) ) 180 { 181 lua_pop( L, 1 ); 182 lua_createtable( L, 0, 0 ); 183 nlua_register( L, l, -1 ); 184 lua_setglobal( L, lname ); 185 return; 186 } 187 nlua_register( L, l, -1 ); 188 lua_pop( L, 1 ); 189 }
Note: See TracChangeset
for help on using the changeset viewer.