/
CountZero
/
quik-cscalp-lua
Обзор
Документация
Войти
/
CountZero
/
quik-cscalp-lua
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
main
QuikSharp.lua
109 строк
3 KB
CountZero
Update
05 авг 2026, 20:59
05 авг 2026, 20:59
500bdaf
Код
Авторство
О чём код?
-- Licensed under the Apache License, Version 2.0. -- Production entry point for the CScalp <-> QUIK bridge. local function running_in_quik() return type(_G.getScriptPath) == "function" end -- These globals are part of the QLua/module boundary. quikVersion = running_in_quik() and _VERSION or _VERSION script_path = running_in_quik() and getScriptPath() or "." is_started = true local library_path = "\\clibs\\5.1_MD\\" if quikVersion == "Lua 5.4" then library_path = "\\clibs64\\54_MD\\" elseif quikVersion == "Lua 5.3" then library_path = "\\clibs64\\53_MD\\" end package.path = package.path .. ";" .. script_path .. "\\?.lua" .. ";" .. script_path .. "\\?.luac" .. ";.\\?.lua" .. ";.\\?.luac" package.cpath = package.cpath .. ";" .. script_path .. library_path .. "?.dll" .. ";." .. library_path .. "?.dll" local util = require("qsutils") local functions = require("qsfunctions") require("qscallbacks") local bridge = functions.bridge() log("Detected QUIK Lua version: " .. tostring(quikVersion) .. "; native path=" .. tostring(library_path), "info") local function traceback(error_value) if debug and type(debug.traceback) == "function" then return debug.traceback(tostring(error_value), 2) end return tostring(error_value) end local function iteration() bridge:housekeeping() util.housekeeping() if bridge.state == "CONFIG_ERROR" and not is_connected then delay(200) return end if not is_connected then util.connect() return end local request, receive_error = receiveRequest() if not request then if receive_error ~= "timeout" and receive_error ~= "not connected" then log("Request receive failed: " .. tostring(receive_error), "warn") end return end local response, dispatch_error = functions.dispatch_and_process(request) if not response then log("Request dispatch returned no response: " .. tostring(dispatch_error), "error") return end local sent, send_error = sendResponse(response) if not sent and send_error ~= "not connected" then log("Response send failed: " .. tostring(send_error), "warn") end end function do_main() log("Entered supervised main loop", "info") bridge:initialize() local consecutive_failures = 0 while is_started do local ok, iteration_error = xpcall(iteration, traceback) if ok then consecutive_failures = 0 else consecutive_failures = consecutive_failures + 1 log("Main-loop iteration failed; supervisor remains active: " .. tostring(iteration_error), "error") local backoff = math.min(5000, 100 * (2 ^ math.min(consecutive_failures - 1, 6))) delay(backoff) end end end function main() do_main() bridge:stop("main loop finished") util.close("main loop finished") end if not running_in_quik() then log("QUIK# loaded outside QUIK; main loop is not started automatically", "info") end