Skip to content

Commit

Permalink
fix: lua_msg_call
Browse files Browse the repository at this point in the history
修复lua调用函数不能正确取到函数名的bug
  • Loading branch information
mystringEmpty committed Feb 11, 2024
1 parent ab81390 commit 69b93b0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
12 changes: 5 additions & 7 deletions Dice/DiceLua.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ bool lua_msg_call(DiceEvent* msg, const AttrVar& lua) {
if (luaFile.empty() && lua.is_character() && fmt->has_lua(lua)) {
luaFile = fmt->lua_path(lua);
}
else luaFunc = lua.is_table() ? lua.to_obj()["func"] : lua;
else luaFunc = lua.is_table() ? lua.to_obj()->get("func") : lua;
LuaState L{ luaFile };
if (!L)return false;
lua_push_Context(L, msg->shared_from_this());
Expand Down Expand Up @@ -1578,6 +1578,7 @@ void DiceModManager::loadPlugin(ResList& res) {
int cntTask{ 0 };
plugin_reply.clear();
taskcall.clear();
AnysTable lua_tab;
for (const auto& pathFile : files) {
if ((pathFile.extension() != ".lua")) {
if (pathFile.extension() != ".toml")continue;
Expand Down Expand Up @@ -1613,6 +1614,7 @@ void DiceModManager::loadPlugin(ResList& res) {
err << "msg_order类型错误(" + string(LuaTypes[lua_type(L, -1)]) + "):" + file;
continue;
}
lua_tab.set("file", file);
auto orders{ lua_to_table(L) };
for (auto& [key, val] : orders.as_dict()) {
if (val.is_table()) {
Expand All @@ -1622,13 +1624,9 @@ void DiceModManager::loadPlugin(ResList& res) {
plugin_reply[key] = reply;
}
else {
AttrObject ans;
lua_tab.set("func", val);
plugin_reply[key] = DiceMsgReply::set_order(key, AttrVars{
{ "lua", AttrObject{
AttrVars{
{"file",file}, {"func",val},
}
}}
{ "lua", lua_tab }
});
}
}
Expand Down
2 changes: 1 addition & 1 deletion Dice/DiceMod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ bool DiceModManager::mod_dlpkg(const string& name, const string& pkg, string& de
fs::copy(desc, pathJson);
}
else {
des = "\npkg解压无文件" + name + ".json";
des = "\npkg don't exist " + name + ".json";
return false;
}
}
Expand Down

0 comments on commit 69b93b0

Please sign in to comment.