| 225 | CppiaConst::CppiaConst() : type(cNull), ival(0), dval(0) { } |
| 226 | |
| 227 | void CppiaConst::fromStream(CppiaStream &stream) |
| 228 | { |
| 229 | std::string tok = stream.getToken(); |
| 230 | if (tok[0]=='i') |
| 231 | { |
| 232 | type = cInt; |
| 233 | |
| 234 | dval = ival = stream.getInt(); |
| 235 | } |
| 236 | else if (tok=="true") |
| 237 | { |
| 238 | type = cInt; |
| 239 | dval = ival = 1; |
| 240 | } |
| 241 | else if (tok=="false") |
| 242 | { |
| 243 | type = cInt; |
| 244 | dval = ival = 0; |
| 245 | } |
| 246 | else if (tok[0]=='f') |
| 247 | { |
| 248 | type = cFloat; |
| 249 | int strIndex = stream.getInt(); |
| 250 | String val = stream.module->strings[strIndex]; |
| 251 | dval = atof(val.out_str()); |
| 252 | ival = dval; |
| 253 | } |
| 254 | else if (tok[0]=='s') |
| 255 | { |
| 256 | type = cString; |
| 257 | ival = stream.getInt(); |
| 258 | } |
| 259 | else if (tok=="NULL") |
| 260 | type = cNull; |
| 261 | else if (tok=="THIS") |
| 262 | type = cThis; |
| 263 | else if (tok=="SUPER") |
| 264 | type = cSuper; |
| 265 | else |
| 266 | throw "unknown const value"; |
| 267 | } |
| 268 | |
| 269 | |
| 270 | |