forked from qt-creator/qt-creator
Lua: Add Timer to the Utils bindings
Change-Id: I7702bae1770f668ffb2f937a357a0156b7db84b4 Reviewed-by: Marcus Tillmanns <marcus.tillmanns@qt.io>
This commit is contained in:
@@ -164,6 +164,26 @@ void addUtilsModule()
|
||||
utils["FilePath"]["searchInPath_cb"] = utils["__searchInPath_cb__"];
|
||||
utils["FilePath"]["searchInPath"] = wrap(utils["__searchInPath_cb__"]);
|
||||
|
||||
utils.new_usertype<QTimer>(
|
||||
"Timer",
|
||||
"create",
|
||||
[guard = pluginSpec](int timeout, bool singleShort, sol::function callback)
|
||||
-> std::unique_ptr<QTimer> {
|
||||
auto timer = std::make_unique<QTimer>();
|
||||
timer->setInterval(timeout);
|
||||
timer->setSingleShot(singleShort);
|
||||
QObject::connect(
|
||||
timer.get(), &QTimer::timeout, guard->connectionGuard.get(), [callback]() {
|
||||
::Lua::LuaEngine::void_safe_call(callback);
|
||||
});
|
||||
|
||||
return timer;
|
||||
},
|
||||
"start",
|
||||
[](QTimer *timer) { timer->start(); },
|
||||
"stop",
|
||||
[](QTimer *timer) { timer->stop(); });
|
||||
|
||||
return utils;
|
||||
});
|
||||
}
|
||||
|
@@ -107,4 +107,19 @@ function utils.HostOsInfo.isMacHost() end
|
||||
function utils.HostOsInfo.isLinuxHost() end
|
||||
|
||||
|
||||
---@class Timer
|
||||
utils.Timer = {}
|
||||
|
||||
---@param timeoutMs integer The timeout in milliseconds.
|
||||
---@param singleShot boolean Whether the timer should only fire once.
|
||||
---@param callback function The callback to call when the timeout is reached.
|
||||
---@return Timer timer The created timer.
|
||||
function utils.Timer.create(timeoutMs, singleShot, callback) end
|
||||
|
||||
--- Starts the timer. Calling start on a running timer restarts the timer.
|
||||
function utils.Timer:start() end
|
||||
|
||||
--- Stops the timer.
|
||||
function utils.Timer:stop() end
|
||||
|
||||
return utils
|
||||
|
Reference in New Issue
Block a user