在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
#include "tolua_fix.h" #include "WordFilter.h" #include "LuaBasicConversions.h" #include "lua_sensitive_binding.h" int lua_sensitive_loadfile(lua_State* tolua_S) { size_t sz = 0; const char *filePath = luaL_checklstring(tolua_S, 1, &sz); std::thread threadLoadFile(&CWordFilter::loadFileByThread, CWordFilter::getInstance(), filePath); threadLoadFile.detach(); return 1; } int censorStr(lua_State *tolua_S) { size_t sz = 0; std::string source = luaL_checklstring(tolua_S, 1, &sz); if (CWordFilter::getInstance()->censorStr(source)) { return 0; } else if (CWordFilter::getInstance()->censorStrWithOutSymbol(source)) { return 0; } return 1; } static luaL_Reg lua_sensitive_funcs[] = { { "loadFile", lua_sensitive_loadfile }, { "censorStr", censorStr }, { NULL, NULL } }; int init_sensitive_binding(lua_State* tolua_S){ lua_newtable(tolua_S); lua_pushvalue(tolua_S, -1); lua_setfield(tolua_S, LUA_GLOBALSINDEX, "SensitiveChecker"); luaL_Reg* lib = lua_sensitive_funcs; for (; lib->func; lib++) { lua_pushcfunction(tolua_S, lib->func); lua_setfield(tolua_S, -2, lib->name); } lua_pop(tolua_S, 1); return 1; } int register_sensitive_binding(lua_State* tolua_S) { return init_sensitive_binding(tolua_S); } 将需要用的函数插入到 名字为 SensitiveChecker 的全局变量表中, 这里我加入了两个函数。用于之前的敏感词屏蔽操作,因为只需要用到这两个接口,所以没有必要去把一个类添加到项目中去,为了省事就加了个全局的表 |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论