MCPcopy Create free account
hub / github.com/DavidColson/Polybox / LoadApp

Function LoadApp

source/cpu.cpp:567–662  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

565// ***********************************************************************
566
567void LoadApp(String appName) {
568 // eventually we'll support multiple independant programs running on the cpu,
569 // and each will have it's own lua state, but for now there's just one
570 if (appName.length == 0) {
571 Log::Warn("No app specified to boot");
572 return;
573 }
574
575 if (appName == "shared") {
576 Log::Warn("\"shared\" is not a valid name for a project, this conflicts with system folders");
577 return;
578 }
579
580 pState->appName= appName;
581 pState->luaFilesToWatch.pArena = pState->pArena;
582 pState->assetsToWatch.pArena = pState->pArena;
583
584 // search for a project in system/ with appname
585 StringBuilder builder(g_pArenaFrame);
586 builder.Append("system/");
587 builder.Append(appName);
588
589 // watch the project's directory for luau file changes
590 FileWatcherAddDirectory(pState->pWatcher, builder.CreateString(g_pArenaFrame, false));
591
592 builder.Append("/main.luau");
593 String appMainPath = builder.CreateString(pState->pArena);
594
595 if (!FileExists(appMainPath)) {
596 Log::Warn("A main.lua file for project '%s' could not be found", appName.pData);
597 return;
598 }
599 pState->luaFilesToWatch.PushBack(appMainPath);
600
601 pState->pImportTable = AssetImporter::LoadImportTable(appName);
602
603 // re-import any changed assets
604 for (i64 i = 0; i < pState->pImportTable->table.tableSize; i++) {
605 HashNode<String, AssetImporter::ImportTableAsset>& node = pState->pImportTable->table.pTable[i];
606 if (node.hash != UNUSED_HASH) {
607 File file = OpenFile(node.key, FM_READ);
608 defer(CloseFile(file));
609 if (IsValid(file)) {
610 u64 lastWriteTime = GetFileLastWriteTime(file);
611 if (lastWriteTime > node.value.lastImportTime && node.value.enableAutoImport) {
612
613 i32 res = AssetImporter::ImportFile(g_pArenaFrame, node.value.importFormat, node.key, node.value.outputPath);
614 if (res >= 0) {
615 pState->pImportTable->table[node.key] = AssetImporter::ImportTableAsset{
616 .outputPath = node.value.outputPath,
617 .enableAutoImport = true,
618 .lastImportTime = lastWriteTime,
619 .importFormat = node.value.importFormat
620 };
621 continue;
622 }
623 Log::Warn("Attempted to re-import %S, but it failed", node.key);
624 }

Callers 1

mainFunction · 0.85

Calls 9

LoadImportTableFunction · 0.85
ImportFileFunction · 0.85
SaveImportTableFunction · 0.85
BindGraphicsFunction · 0.85
BindInputFunction · 0.85
BindUserDataFunction · 0.85
BindSerializationFunction · 0.85
BindFileSystemFunction · 0.85
CompileAndLoadModuleFunction · 0.85

Tested by

no test coverage detected