| 568 | } |
| 569 | |
| 570 | int spell_analysis(lua_State *L) { |
| 571 | int top = lua_gettop(L); |
| 572 | |
| 573 | if (top < 2) { |
| 574 | return 0; |
| 575 | } |
| 576 | |
| 577 | if (lua_isstring(L, 1) && lua_isstring(L, 2)) { |
| 578 | try { |
| 579 | std::string filename = lua_tostring(L, 1); |
| 580 | std::string text = lua_tostring(L, 2); |
| 581 | |
| 582 | CodeSpellChecker::CustomDictionary tempDict; |
| 583 | |
| 584 | if (top == 3 && lua_istable(L, 3)) { |
| 585 | lua_pushnil(L); |
| 586 | while (lua_next(L, -2) != 0) { |
| 587 | auto value = luaToString(L, -1); |
| 588 | tempDict.insert(value); |
| 589 | lua_pop(L, 1); |
| 590 | } |
| 591 | } |
| 592 | |
| 593 | auto spellResult = LuaCodeFormat::GetInstance().SpellCheck(filename, std::move(text), tempDict); |
| 594 | if (spellResult.Type == ResultType::Err) { |
| 595 | lua_pushboolean(L, false); |
| 596 | return 1; |
| 597 | } |
| 598 | |
| 599 | auto &diagnostics = spellResult.Data; |
| 600 | lua_pushboolean(L, true); |
| 601 | PushDiagnosticToLua(L, diagnostics); |
| 602 | |
| 603 | return 2; |
| 604 | } catch (std::exception &e) { |
| 605 | std::string err = e.what(); |
| 606 | lua_settop(L, top); |
| 607 | lua_pushboolean(L, false); |
| 608 | lua_pushlstring(L, err.c_str(), err.size()); |
| 609 | return 2; |
| 610 | } |
| 611 | } |
| 612 | return 0; |
| 613 | } |
| 614 | |
| 615 | InfoNode CreateFromLua(InfoTree &t, lua_State *L) { |
| 616 | if (lua_istable(L, -1)) { |
nothing calls this directly
no test coverage detected