Skip to content

Commit

Permalink
temp
Browse files Browse the repository at this point in the history
  • Loading branch information
horror-proton committed Nov 10, 2023
1 parent fd2c873 commit dba8f1c
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 19 deletions.
18 changes: 8 additions & 10 deletions resource/lua/maav0.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,29 @@ if maav0 ~= nil then
return maav0
end

---@param ms number
function M.sleep(ms)end

---@return boolean
M.uuid = function()
end
function M.uuid() end

---@param x number
---@param y number
---@return boolean
M.click = function(x, y)
end
function M.click(x, y) end

---@param x1 number
---@param y1 number
---@param x2 number
---@param y2 number
---@return boolean
M.swipe = function(x1, y1, x2, y2)
end
function M.swipe(x1, y1, x2, y2) end

---@return boolean
M.screencap = function()
end
function M.screencap() end

---@param name string
---@return number, number, number, number, number
M.match_task = function(name)
end
function M.match_task(name) end

return M
19 changes: 11 additions & 8 deletions src/MaaCore/Task/Interface/LuaTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,16 @@ bool asst::LuaTask::run()

luaL_openlibs(l);
lua_add_path(l, {
ResDir.get().string() + "/lua/?.lua",
ResDir.get().string() + "/lua/?/init.lua",
ResDir.get() / "lua" / "?.lua",
ResDir.get() / "lua" / "?" / "init.lua",
});

lua_newtable(l);
lua_pushvalue(l, -1); // duplicate it on stack
lua_setglobal(l, "maav0"); // this pops one

add_closure(l, [](lua_State* s, LuaTask* p) -> int {
p->sleep(luaL_checknumber(s, 1));
return 0;
});
p->sleep(static_cast<unsigned>(std::max(0., luaL_checknumber(s, 1))));
return 0;
});
lua_setfield(l, -2, "sleep");

add_closure(l, [](lua_State* s, LuaTask* p) -> int {
Expand Down Expand Up @@ -88,7 +86,7 @@ bool asst::LuaTask::run()
});
lua_setfield(l, -2, "match_task");

lua_pop(l, 1); // global maav0
lua_setglobal(l, "maav0");

std::string script = R"(
print(package.path)
Expand All @@ -113,3 +111,8 @@ print("done")
lua_close(l);
return true;
}

bool asst::LuaTask::set_params(const json::value&)
{
return true;
}
4 changes: 3 additions & 1 deletion src/MaaCore/Task/Interface/LuaTask.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@ namespace asst
class LuaTask : public InterfaceTask
{
public:
inline static constexpr std::string_view TaskType = "Lua";
inline static constexpr std::string_view TaskType = "Custom";

LuaTask(const AsstCallback& callback, Assistant* inst) : InterfaceTask(callback, inst, TaskType) {}
~LuaTask() override = default;

bool run() override;

bool set_params(const json::value &params) override;

private:
template <typename Func>
void add_closure(lua_State* L, Func&&)
Expand Down

0 comments on commit dba8f1c

Please sign in to comment.