| 470 | // *********************************************************************** |
| 471 | |
| 472 | void Init() { |
| 473 | Arena* pArena = ArenaCreate(); |
| 474 | pState = New(pArena, State); |
| 475 | pState->pArena = pArena; |
| 476 | pState->appLoaded = false; |
| 477 | |
| 478 | pState->pWatcher = FileWatcherCreate(OnFileChanged, FC_MODIFIED, (void*)pState, true); |
| 479 | |
| 480 | // Setup our frontend |
| 481 | Luau::FrontendOptions frontendOptions; |
| 482 | frontendOptions.runLintChecks = true; |
| 483 | |
| 484 | // regrettably luau::frontend is very RAII heavy, so we must do this |
| 485 | PlacementNew(&pState->fileResolver) LuaFileResolver(); |
| 486 | PlacementNew(&pState->configResolver) Luau::NullConfigResolver(); |
| 487 | PlacementNew(&pState->frontend) Luau::Frontend(&pState->fileResolver, &pState->configResolver, frontendOptions); |
| 488 | |
| 489 | unfreeze(pState->frontend.globals.globalTypes); |
| 490 | Luau::registerBuiltinGlobals(pState->frontend, pState->frontend.globals); |
| 491 | |
| 492 | // Add our global type definitions |
| 493 | Luau::LoadDefinitionFileResult loadResult = pState->frontend.loadDefinitionFile( |
| 494 | pState->frontend.globals, pState->frontend.globals.globalScope, std::string_view(polyboxDefinitions.pData), "@polybox", /* captureComments */ false, false); |
| 495 | Luau::freeze(pState->frontend.globals.globalTypes); // Marks the type memory as read only |
| 496 | |
| 497 | // give errors on parsing the type definitions |
| 498 | for (Luau::ParseError& error : loadResult.parseResult.errors) { |
| 499 | Log::Warn("Builtins SyntaxError at [%d] - %s", error.getLocation().begin.line + 1, error.getMessage().c_str()); |
| 500 | } |
| 501 | |
| 502 | if (loadResult.module) { |
| 503 | for (Luau::TypeError& error : loadResult.module->errors) { |
| 504 | Log::Warn("Builtins TypeError at [%d] - %s", error.location.begin.line + 1, Luau::toString(error, Luau::TypeErrorToStringOptions{pState->frontend.fileResolver}).c_str()); |
| 505 | } |
| 506 | } |
| 507 | } |
| 508 | |
| 509 | // *********************************************************************** |
| 510 | |