| 164 | } |
| 165 | |
| 166 | int CScriptVarsTable::save(IWriter& memory_stream) |
| 167 | { |
| 168 | memory_stream.w_u32(m_map.size()); |
| 169 | int saved = 0; |
| 170 | auto it = m_map.begin(); |
| 171 | auto end = m_map.end(); |
| 172 | for (; it != end; it++) |
| 173 | { |
| 174 | saved++; |
| 175 | SCRIPT_VAR& sv = it->second; |
| 176 | memory_stream.w_stringZ(it->first); |
| 177 | |
| 178 | if (LUA_TTABLE == sv.eff_type()) |
| 179 | { |
| 180 | int type = sv.type; |
| 181 | sv.type = LUA_TTABLE; |
| 182 | if (sv.T->is_array) |
| 183 | sv.type |= SVT_ARRAY_TABLE; |
| 184 | if (sv.T->zero_key) |
| 185 | sv.type |= SVT_ARRAY_ZEROK; |
| 186 | if ((type & SVT_KEY_MASK) == SVT_KEY_BOOLEAN) |
| 187 | sv.type |= SVT_KEY_BOOLEAN; |
| 188 | else if ((type & SVT_KEY_MASK) == SVT_KEY_NUMERIC) |
| 189 | sv.type |= SVT_KEY_NUMERIC; |
| 190 | |
| 191 | memory_stream.w_s32(sv.type); |
| 192 | saved += sv.T->save(memory_stream); |
| 193 | continue; |
| 194 | } |
| 195 | |
| 196 | memory_stream.w_s32(sv.type); |
| 197 | |
| 198 | if (LUA_TNETPACKET == sv.eff_type()) |
| 199 | { |
| 200 | memory_stream.w_u32(sv.P->B.count); |
| 201 | memory_stream.w_u32(sv.P->r_tell()); |
| 202 | memory_stream.w(&sv.P->B.data, sv.P->B.count); |
| 203 | continue; |
| 204 | } |
| 205 | memory_stream.w_u32(sv.size); // sizeof *data |
| 206 | if (sv.size > sizeof(sv.s_value)) |
| 207 | memory_stream.w(sv.data, sv.size); |
| 208 | else |
| 209 | memory_stream.w(&sv.s_value, sv.size); |
| 210 | } |
| 211 | |
| 212 | memory_stream.w_s32(-1); |
| 213 | return saved; |
| 214 | } |
| 215 | |
| 216 | void CScriptVarsTable::release() |
| 217 | { |
no test coverage detected