Hello
I want to tell you this honestly
I used AI to build one of my plugin
And I came across something really cool by accident
I live in Iran, the economy is not good here, so people usually have weak computers
I have a hard drive that was sold to me new, but later I found out that it had been working for 10 years
And I have a stock i7-3770 CPU
And the interesting thing was that it analyzes each line of code with about 100 programming rules and tells me about about 4 thousand scripts in less than 1.5 seconds
That is, it prepares a list of all the problems and sends it to the UI
And the thing is that it is very fast
Do you think this is an innovation? What if I make a YouTube video?
local RunService = game:GetService(“RunService”)
local ScriptAnalyzer = {}
-- پارامترهای دینامیک برای مدیریت بودجه زمانی (بر حسب ثانیه)
local BASE_BUDGET = 0.012 -- شروع با 12ms
local MAX_BUDGET = 0.05 -- حداکثر 50ms
local MIN_BUDGET = 0.005 -- حداقل 5ms
local BUDGET_STEP = 0.002 -- گام تنظیم خودکار
-- اطمینان از وجود جدول قوانین
assert(rules, "ScriptAnalyzer: rules table is not defined")
-- آمادهسازی matcherها بر اساس الگو یا تابع
for _, rule in ipairs(rules) do
if type(rule.pattern) == "string" then
local pat = rule.pattern
rule._matcher = function(line)
return string.find(line, pat)
end
elseif type(rule.test) == "function" then
rule._matcher = rule.test
else
error("Invalid rule: must have .pattern (string) or .test (function)")
end
end
-- تابع کمکی: بررسی همهی قوانین روی یک خط
local function matchAll(line)
local matches = {}
for _, rule in ipairs(rules) do
local success, match = pcall(rule._matcher, line)
if success and match then
table.insert(matches, rule.message)
end
end
return matches
end
function ScriptAnalyzer.AnalyzeAsync(callback, targets)
assert(type(callback) == "function", "AnalyzeAsync: callback must be a function")
local sourceList = (type(targets) == "table" and #targets > 0) and targets or game:GetDescendants()
local scripts = {}
for _, obj in ipairs(sourceList) do
if obj:IsA("Script") or obj:IsA("LocalScript") or obj:IsA("ModuleScript") then
table.insert(scripts, obj)
end
end
local total = #scripts
if total == 0 then
task.defer(function() callback({}, 1) end)
return
end
local results = {}
local scriptIndex = 1
local currentScript, lines, lineIndex
local timeBudget = BASE_BUDGET
local conn
conn = RunService.Heartbeat:Connect(function()
local frameStart = os.clock()
while (os.clock() - frameStart) < timeBudget do
if not currentScript then
if scriptIndex > total then
conn:Disconnect()
task.defer(function() callback(results, 1) end)
return
end
currentScript = scripts[scriptIndex]
scriptIndex = scriptIndex + 1
local ok, src = pcall(function() return currentScript.Source end)
if ok and type(src) == "string" then
lines = string.split(src, "\n")
lineIndex = 1
else
warn(('[Analyzer] Couldn\'t read source of %s'):format(currentScript:GetFullName()))
table.insert(results, { message = "Failed to read source", line = 0, script = currentScript })
currentScript = nil
end
end
if currentScript and lines then
while lineIndex <= #lines do
local ln = lineIndex
local line = lines[ln]
lineIndex = lineIndex + 1
-- نادیده گرفتن خطوط کامنتشده
if not line:match("^%s*%-%-") then
local msgs = matchAll(line)
for _, msg in ipairs(msgs) do
-- اضافه کردن شماره خط و خود محتویات خط به پیام
table.insert(results, {
message = ("line %d: %s\n>> %s"):format(ln, msg, line),
line = ln,
script = currentScript,
})
end
end
if (os.clock() - frameStart) >= timeBudget then
return
end
end
currentScript, lines, lineIndex = nil, nil, nil
local prog = math.clamp((scriptIndex - 1) / total, 0, 1)
task.defer(function() callback(results, prog) end)
end
end
local used = os.clock() - frameStart
if used < timeBudget * 0.5 and timeBudget < MAX_BUDGET then
timeBudget = math.min(timeBudget + BUDGET_STEP, MAX_BUDGET)
elseif used > timeBudget * 0.9 and timeBudget > MIN_BUDGET then
timeBudget = math.max(timeBudget - BUDGET_STEP, MIN_BUDGET)
end
end)
end
function ScriptAnalyzer.Analyze()
local done, output = false, {}
ScriptAnalyzer.AnalyzeAsync(function(res, prog)
output = res
if prog >= 1 then done = true end
end)
repeat task.wait() until done
return output
end
return ScriptAnalyzer
If you don’t understand what I’m saying, check out this plugin.