|
|
| Строка 1: |
Строка 1: |
| local p = {} | | local p = {} |
|
| |
|
| local cachedData = nil | | function p.check(frame) |
| local loadCount = 0
| | local success, result = pcall(function() |
| | return _G |
| | end) |
|
| |
|
| local cache = mw.ext.LuaCache and mw.ext.LuaCache.get("entity_data_cache")
| | if success then |
| | | return "LuaStandalone работает корректно." |
| local function loadData(filePath)
| | else |
| if cachedData then | | return "Ошибка: LuaStandalone не доступен, возможно используется LuaSandbox." |
| loadCount = loadCount + 1
| |
| return cachedData | |
| end
| |
| | |
| if cache then
| |
| local cachedContent = cache:get(filePath)
| |
| if cachedContent then
| |
| cachedData = mw.text.jsonDecode(cachedContent)
| |
| return cachedData
| |
| end
| |
| end
| |
| | |
| loadCount = loadCount + 1
| |
| local page = mw.title.new(filePath)
| |
| local content = page and page:getContent()
| |
| | |
| cachedData = content and mw.text.jsonDecode(content) or nil
| |
| | |
| if cachedData and cache then
| |
| cache:set(filePath, content, 3600)
| |
| end
| |
| | |
| return cachedData
| |
| end
| |
| | |
| function p.main(frame)
| |
| local param = frame.args[1]
| |
| local secondaryParam = frame.args[2]
| |
| | |
| local data = loadData('User:IanComradeBot/prototypes/entity sprite.json')
| |
| if not data then
| |
| return 'Ошибка: Невозможно загрузить данные из JSON.'
| |
| end
| |
| | |
| if param == "debug" then
| |
| return "Количество загрузок JSON: " .. loadCount
| |
| end | |
| | |
| if param == "image" and secondaryParam then
| |
| for _, entry in ipairs(data) do
| |
| if entry.id == secondaryParam then
| |
| return entry.Sprite and entry.Sprite.sprite or (entry.Icon and entry.Icon.sprite) or "Ошибка: Спрайт не найден."
| |
| end
| |
| end
| |
| return "Ошибка: ID не найден." | |
| end | | end |
| end | | end |
|
| |
|
| return p | | return p |
Для документации этого модуля может быть создана страница Модуль:Песочница/Pok/doc
local p = {}
function p.check(frame)
local success, result = pcall(function()
return _G
end)
if success then
return "LuaStandalone работает корректно."
else
return "Ошибка: LuaStandalone не доступен, возможно используется LuaSandbox."
end
end
return p