| 408 | } |
| 409 | |
| 410 | int diagnose_file(lua_State *L) { |
| 411 | int top = lua_gettop(L); |
| 412 | |
| 413 | if (top < 2) { |
| 414 | return 0; |
| 415 | } |
| 416 | |
| 417 | if (lua_isstring(L, 1) && lua_isstring(L, 2)) { |
| 418 | try { |
| 419 | std::string filename = lua_tostring(L, 1); |
| 420 | std::string text = lua_tostring(L, 2); |
| 421 | auto diagnosticResult = LuaCodeFormat::GetInstance().Diagnostic(filename, std::move(text)); |
| 422 | if (diagnosticResult.Type == ResultType::Err) { |
| 423 | lua_pushboolean(L, false); |
| 424 | return 1; |
| 425 | } |
| 426 | |
| 427 | auto &diagnostics = diagnosticResult.Data; |
| 428 | lua_pushboolean(L, true); |
| 429 | PushDiagnosticToLua(L, diagnostics); |
| 430 | |
| 431 | return 2; |
| 432 | } catch (std::exception &e) { |
| 433 | std::string err = e.what(); |
| 434 | lua_settop(L, top); |
| 435 | lua_pushboolean(L, false); |
| 436 | lua_pushlstring(L, err.c_str(), err.size()); |
| 437 | return 2; |
| 438 | } |
| 439 | } |
| 440 | return 0; |
| 441 | } |
| 442 | |
| 443 | int set_default_config(lua_State *L) { |
| 444 | int top = lua_gettop(L); |
nothing calls this directly
no test coverage detected