MCPcopy Create free account
hub / github.com/CppCXY/EmmyLuaCodeStyle / spell_suggest

Function spell_suggest

CodeFormatLib/src/CodeFormatLib.cpp:720–755  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

718}
719
720int 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
757static const luaL_Reg lib[] = {
758 {"format", format },

Callers

nothing calls this directly

Calls 11

lua_gettopFunction · 0.85
lua_isstringFunction · 0.85
lua_pushstringFunction · 0.85
lua_rawsetiFunction · 0.85
lua_settopFunction · 0.85
lua_pushbooleanFunction · 0.85
lua_pushlstringFunction · 0.85
SpellCorrectMethod · 0.45
emptyMethod · 0.45
whatMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected