MCPcopy Create free account
hub / github.com/HaxeFoundation/hxcpp / LoadCppia

Function LoadCppia

src/hx/cppia/CppiaModule.cpp:360–511  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

358
359
360CppiaLoadedModule 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));

Callers 3

__scriptable_load_cppiaFunction · 0.85

Calls 15

__newFunction · 0.85
createCppiaExprFunction · 0.85
RegisterResourcesFunction · 0.85
ThrowFunction · 0.85
getAsciiTokenMethod · 0.80
setBinaryMethod · 0.80
getAsciiIntMethod · 0.80
readStringMethod · 0.80
getByteMethod · 0.80
getTokenMethod · 0.80
skipCharMethod · 0.80
readBytesMethod · 0.80

Tested by

no test coverage detected