Add support for `require("strict")`
starcitizen>Alistair3149 (Use `pcall` to invoke `getInvokeCallList` from `p._main` to avoid breaking {{Documentation}} when the template page doesn’t yet exist) |
starcitizen>Alistair3149 (Add support for `require("strict")`) |
||
| Рядок 1: | Рядок 1: | ||
require("strict"); | |||
local p = {} | local p = {} | ||
local libraryUtil = require( 'libraryUtil' ) | local libraryUtil = require( 'libraryUtil' ) | ||
| Рядок 13: | Рядок 14: | ||
local MAX_DYNAMIC_REQUIRE_LIST_LENGTH = 30 | local MAX_DYNAMIC_REQUIRE_LIST_LENGTH = 30 | ||
local dynamicRequireListQueryCache = {} | local dynamicRequireListQueryCache = {} | ||
local builtins = { | |||
-- ["libraryUtil"] = "mw:Special:MyLanguage/Extension:Scribunto/Lua reference manual#libraryUtil", | |||
["strict"] = "mw:Special:MyLanguage/Extension:Scribunto/Lua reference manual#strict", | |||
}; | |||
--- Used in case 'require( varName )' is found. Attempts to find a string value stored in 'varName'. | --- Used in case 'require( varName )' is found. Attempts to find a string value stored in 'varName'. | ||
| Рядок 56: | Рядок 62: | ||
---@param str string | ---@param str string | ||
---@return string | ---@return string | ||
local function formatModuleName( str ) | local function formatModuleName( str, allowBuiltins ) | ||
if allowBuiltins then | |||
local name = mw.text.trim(str) | |||
-- Only remove quotes at start and end of string if both are the same type | |||
:gsub([[^(['"])(.-)%1$]], function(_, x) return x end); | |||
local builtin = builtins[name]; | |||
if builtin then | |||
return builtin .. "|" .. name; | |||
end | |||
end | |||
local module = formatPageName( str ) | local module = formatPageName( str ) | ||
| Рядок 141: | Рядок 158: | ||
end | end | ||
elseif match ~= '' then | elseif match ~= '' then | ||
match = formatModuleName( match ) | match = formatModuleName( match, true ) | ||
table.insert( requireList, match ) | table.insert( requireList, match ) | ||
end | end | ||
| Рядок 155: | Рядок 172: | ||
end | end | ||
elseif match ~= '' then | elseif match ~= '' then | ||
match = formatModuleName( match ) | match = formatModuleName( match, true ) | ||
table.insert( loadDataList, match ) | table.insert( loadDataList, match ) | ||
end | end | ||
| Рядок 169: | Рядок 186: | ||
end | end | ||
elseif match ~= '' then | elseif match ~= '' then | ||
match = formatModuleName( match ) | match = formatModuleName( match, true ) | ||
table.insert( loadDataList, match ) | table.insert( loadDataList, match ) | ||
end | end | ||