| 509 | // *********************************************************************** |
| 510 | |
| 511 | bool CompileAndLoadModule(String modulePath, i32 nReturns) { |
| 512 | bool wasError = false; |
| 513 | |
| 514 | // run typechecking |
| 515 | Luau::CheckResult result = pState->frontend.check(modulePath.pData); |
| 516 | |
| 517 | if (!result.errors.empty()) |
| 518 | wasError = true; |
| 519 | |
| 520 | // print errors and lint warnings |
| 521 | for (Luau::TypeError& error : result.errors) { |
| 522 | std::string humanReadableName = pState->frontend.fileResolver->getHumanReadableModuleName(error.moduleName); |
| 523 | if (const Luau::SyntaxError* syntaxError = Luau::get_if<Luau::SyntaxError>(&error.data)) |
| 524 | Log::Warn("SyntaxError in [%s:%d] - %s", humanReadableName.c_str(), error.location.begin.line + 1, syntaxError->message.c_str()); |
| 525 | else |
| 526 | Log::Warn("TypeError in [%s:%d] - %s", humanReadableName.c_str(), error.location.begin.line + 1, Luau::toString(error, Luau::TypeErrorToStringOptions{pState->frontend.fileResolver}).c_str()); |
| 527 | } |
| 528 | |
| 529 | for (Luau::LintWarning& error : result.lintResult.errors) { |
| 530 | std::string humanReadableName = pState->frontend.fileResolver->getHumanReadableModuleName(error.moduleName); |
| 531 | Log::Warn("LintError in [%s:%d] (%s) - %s",humanReadableName.c_str(), error.location.begin.line + 1, |
| 532 | Luau::LintWarning::getName(error.code), error.text.c_str()); |
| 533 | } |
| 534 | |
| 535 | for (Luau::LintWarning& error : result.lintResult.warnings) { |
| 536 | std::string humanReadableName = pState->frontend.fileResolver->getHumanReadableModuleName(error.moduleName); |
| 537 | Log::Warn("LintWarning in [%s:%d] (%s) - %s", humanReadableName.c_str(), error.location.begin.line + 1, |
| 538 | Luau::LintWarning::getName(error.code), error.text.c_str()); |
| 539 | } |
| 540 | |
| 541 | // Compile and load |
| 542 | if (wasError == false) { |
| 543 | i64 sourceSize; |
| 544 | char* pSource = ReadWholeFile(modulePath, &sourceSize, g_pArenaFrame); |
| 545 | |
| 546 | u64 bytecodeSize = 0; |
| 547 | char* pBytecode = luau_compile(pSource, sourceSize, nullptr, &bytecodeSize); |
| 548 | int result = luau_load(pState->pProgramState, modulePath.pData, pBytecode, bytecodeSize, 0); |
| 549 | |
| 550 | if (result != 0) { |
| 551 | Log::Warn("Lua Load Error: %s", lua_tostring(pState->pProgramState, lua_gettop(pState->pProgramState))); |
| 552 | lua_pop(pState->pProgramState, 1); |
| 553 | return false; |
| 554 | } |
| 555 | |
| 556 | if (lua_pcall(pState->pProgramState, 0, nReturns, 0) != LUA_OK) { |
| 557 | Log::Warn("Lua Runtime Error: %s", lua_tostring(pState->pProgramState, lua_gettop(pState->pProgramState))); |
| 558 | lua_pop(pState->pProgramState, 1); |
| 559 | return false; |
| 560 | } |
| 561 | } |
| 562 | return !wasError; |
| 563 | } |
| 564 | |
| 565 | // *********************************************************************** |
| 566 |
no test coverage detected