| 358 | |
| 359 | |
| 360 | CppiaLoadedModule LoadCppia(const unsigned char *inData, int inDataLength) |
| 361 | { |
| 362 | if (!gAllCppiaModules.mPtr) |
| 363 | { |
| 364 | gAllCppiaModules = Array_obj<Dynamic>::__new(); |
| 365 | GCAddRoot( (hx::Object **)&gAllCppiaModules.mPtr ); |
| 366 | } |
| 367 | |
| 368 | CppiaModule *cppiaPtr = new CppiaModule(); |
| 369 | CppiaLoadedModule loadedModule = new CppiaObject(cppiaPtr); |
| 370 | gAllCppiaModules->push(loadedModule); |
| 371 | |
| 372 | |
| 373 | CppiaModule &cppia = *cppiaPtr; |
| 374 | CppiaStream stream(cppiaPtr,inData, inDataLength); |
| 375 | |
| 376 | String error; |
| 377 | try |
| 378 | { |
| 379 | std::string tok = stream.getAsciiToken(); |
| 380 | if (tok!="CPPIA" && tok!="CPPIB") |
| 381 | throw "Bad magic"; |
| 382 | |
| 383 | stream.setBinary(tok=="CPPIB"); |
| 384 | |
| 385 | int stringCount = stream.getAsciiInt(); |
| 386 | for(int s=0;s<stringCount;s++) |
| 387 | cppia.strings[s] = stream.readString(); |
| 388 | |
| 389 | int typeCount = stream.getAsciiInt(); |
| 390 | cppia.types.resize(typeCount); |
| 391 | DBGLOG("Type count : %d\n", typeCount); |
| 392 | for(int t=0;t<typeCount;t++) |
| 393 | cppia.types[t] = new TypeData(stream.readString()); |
| 394 | |
| 395 | int classCount = stream.getAsciiInt(); |
| 396 | DBGLOG("Class count : %d\n", classCount); |
| 397 | |
| 398 | if (stream.binary) |
| 399 | { |
| 400 | int newLine = stream.getByte(); |
| 401 | if (newLine!='\n') |
| 402 | throw "Missing new-line after class count"; |
| 403 | } |
| 404 | |
| 405 | cppia.classes.reserve(classCount); |
| 406 | for(int c=0;c<classCount;c++) |
| 407 | { |
| 408 | CppiaClassInfo *info = new CppiaClassInfo(cppia); |
| 409 | if (info->load(stream)) |
| 410 | cppia.classes.push_back(info); |
| 411 | } |
| 412 | |
| 413 | tok = stream.getToken(); |
| 414 | if (tok=="MAIN") |
| 415 | { |
| 416 | DBGLOG("Main...\n"); |
| 417 | cppia.main = new ScriptCallable(createCppiaExpr(stream)); |
no test coverage detected