×
新規記事を作成
ここにページのタイトルを記入:
We currently have 2 articles on 政治ボールwiki 日本語版. Type your article name above or click on one of the titles below and start writing!



    政治ボールwiki 日本語版
    2026年7月13日 (月) 19:18時点におけるLiberalPolandball (トーク | 投稿記録)による版 (ページの作成:「local function processResult(options, success, ...) if not success then local message = tostring(... or '(メッセージなし)') if options.removeLocation then message = string.gsub(message, '^Module:[^:]+:%d+: ', '', 1) message = string.gsub(message, '^モジュール:[^:]+:%d+: ', '', 1) end return string.format(options.errFormat, message) end return ... end local function protect(func, errFormat, options) if type(errFormat) == 'table' the…」)
    (差分) ← 古い版 | 最新版 (差分) | 新しい版 → (差分)

    このモジュールは他のモジュールでエラー処理を簡略化するために使用されます。エラーを投げる可能性のある関数を変換して、エラーを投げる代わりにエラーメッセージを返すようにします。

    local protect = require('モジュール:Protect')
    local protectedFunc = protect(func, errFormat, options)
    

    戻り値のテンプレート:Codeは関数であり、渡された引数をそのままテンプレート:Codeに渡し、その戻り値はそのままテンプレート:Codeの戻り値になります。テンプレート:Codeがエラーを投げた場合、テンプレート:Codeエラーを投げず、代わりにエラーメッセージを返します。

    local protect = require('Module:Protect')
    
    local p = {}
    
    function p.main(frame)
        if not frame.args[1] then
            error('引数未入力')
        end
        return frame.args[1]
    end
    
    p.main = protect(p.main)
    
    return p
    

    main関数を引数なしで呼び出すと、エラー: 引数未入力と返されます。 テンプレート:Sandbox other


    local function processResult(options, success, ...)
    	if not success then
    		local message = tostring(... or '(メッセージなし)')
    		if options.removeLocation then
    			message = string.gsub(message, '^Module:[^:]+:%d+: ', '', 1)
    			message = string.gsub(message, '^モジュール:[^:]+:%d+: ', '', 1)
    		end
    		return string.format(options.errFormat, message)
    	end
    	return ...
    end
    
    local function protect(func, errFormat, options)
    	if type(errFormat) == 'table' then
    		options = options or errFormat
    		errFormat = nil
    	end
    	options = mw.clone(options) or {}
    	options.errFormat = errFormat or options.errFormat or 'エラー: %s'
    	if not options.raw then
    		options.errFormat = '<strong class="error">' .. options.errFormat .. '</strong>'
    	end
    	options.removeLocation = options.removeLocation == nil or options.removeLocation
    	
    	return function (...)
    		return processResult(options, pcall(func, ...))
    	end
    end
    
    return protect