| 718 | } |
| 719 | |
| 720 | int spell_suggest(lua_State *L) { |
| 721 | int top = lua_gettop(L); |
| 722 | |
| 723 | if (top != 1) { |
| 724 | return 0; |
| 725 | } |
| 726 | |
| 727 | if (lua_isstring(L, 1)) { |
| 728 | try { |
| 729 | std::string word = lua_tostring(L, 1); |
| 730 | auto suggests = LuaCodeFormat::GetInstance().SpellCorrect(word); |
| 731 | int count = 1; |
| 732 | lua_newtable(L); |
| 733 | for (auto &suggest: suggests) { |
| 734 | if (!suggest.Term.empty()) { |
| 735 | lua_pushstring(L, suggest.Term.c_str()); |
| 736 | lua_rawseti(L, -2, count); |
| 737 | count++; |
| 738 | } |
| 739 | // 15个已经可以了 |
| 740 | if (count == 15) { |
| 741 | break; |
| 742 | } |
| 743 | } |
| 744 | |
| 745 | return 2; |
| 746 | } catch (std::exception &e) { |
| 747 | std::string err = e.what(); |
| 748 | lua_settop(L, top); |
| 749 | lua_pushboolean(L, false); |
| 750 | lua_pushlstring(L, err.c_str(), err.size()); |
| 751 | return 2; |
| 752 | } |
| 753 | } |
| 754 | return 0; |
| 755 | } |
| 756 | |
| 757 | static const luaL_Reg lib[] = { |
| 758 | {"format", format }, |
nothing calls this directly
no test coverage detected