模組:沙盒/Oudoubleyang/arguments

文档图示 模块文档[创建]
local p={}

function p.ar(frame)
	local args
	local str
	
	if frame == mw.getCurrentFrame() then
        -- called via #invoke
        args = frame.args
        can_call_parse = true
    else
        -- called from another module
        args = frame
        if type(args) ~= type({}) then args = {frame} end
    end
    
    if args[1] then str = args[1] else str = args['1'] end
    if args['start'] then
    	head = args['start']
    else
    	if args['length'] then
    		length = tonumber(args['length'])
    	else
    		if args[2] then second = args[2] else second = args['2'] end
    		if type(tonumber(second)) == 'number' then length = tonumber(second) else head = second end
    	end
    end
    
    if length then
    	return length
    else
    	return head
    end
end

return p