恪別𡧲版𢯢𢷮𧵑「Module:Arguments」
no edit summary
SaigonSarang (討論 | 㨂𢵰) n (SaigonSarang 㐌𢷮「Mô đun:Arguments」成「模撴:Arguments」(㐌𤎕𢷮向)) |
SaigonSarang (討論 | 㨂𢵰) 空固𥿂略𢯢𢷮 |
||
𣳔1: | 𣳔1: | ||
-- This module provides easy processing of arguments passed to Scribunto from | -- This module provides easy processing of arguments passed to Scribunto from | ||
-- # | -- #invoke. It is intended for use by other Lua modules, and should not be | ||
-- from # | -- called from #invoke directly. | ||
local libraryUtil = require('libraryUtil') | local libraryUtil = require('libraryUtil') | ||
𣳔13: | 𣳔13: | ||
local function tidyValDefault(key, val) | local function tidyValDefault(key, val) | ||
if type(val) == 'string' then | if type(val) == 'string' then | ||
val = | val = val:match('^%s*(.-)%s*$') | ||
if val == '' then | if val == '' then | ||
return nil | return nil | ||
𣳔26: | 𣳔26: | ||
local function tidyValTrimOnly(key, val) | local function tidyValTrimOnly(key, val) | ||
if type(val) == 'string' then | if type(val) == 'string' then | ||
return | return val:match('^%s*(.-)%s*$') | ||
else | else | ||
return val | return val | ||
𣳔167: | 𣳔167: | ||
if type(tidyVal) ~= 'function' then | if type(tidyVal) ~= 'function' then | ||
error( | error( | ||
" | "bad value assigned to option 'valueFunc'" | ||
.. | .. '(function expected, got ' | ||
.. type(tidyVal) | .. type(tidyVal) | ||
.. ')', | .. ')', | ||
𣳔270: | 𣳔270: | ||
if options.readOnly then | if options.readOnly then | ||
error( | error( | ||
' | 'could not write to argument table key "' | ||
.. tostring(key) | .. tostring(key) | ||
.. ' | .. '"; the table is read-only', | ||
2 | 2 | ||
) | ) | ||
elseif options.noOverwrite and args[key] ~= nil then | elseif options.noOverwrite and args[key] ~= nil then | ||
error( | error( | ||
' | 'could not write to argument table key "' | ||
.. tostring(key) | |||
.. '"; overwriting existing arguments is not permitted', | |||
2 | 2 | ||
) | ) |