「
モジュール:Arguments/doc
」を編集中 (節単位)
ナビゲーションに移動
検索に移動
警告:
ログインしていません。編集を行うと、あなたの IP アドレスが公開されます。
ログイン
または
アカウントを作成
すれば、あなたの編集はその利用者名とともに表示されるほか、その他の利点もあります。
スパム攻撃防止用のチェックです。 けっして、ここには、値の入力は
しない
でください!
=== Frames and parent frames === Arguments in the <code>args</code> table can be passed from the current frame or from its parent frame at the same time. To understand what this means, it is easiest to give an example. Let's say that we have a module called <code>Module:ExampleArgs</code>. This module prints the first two positional arguments that it is passed. {{cot|Module:ExampleArgs code}} <syntaxhighlight lang="lua"> local getArgs = require('Module:Arguments').getArgs local p = {} function p.main(frame) local args = getArgs(frame) return p._main(args) end function p._main(args) local first = args[1] or '' local second = args[2] or '' return first .. ' ' .. second end return p </syntaxhighlight> {{cob}} <code>Module:ExampleArgs</code> is then called by <code>Template:ExampleArgs</code>, which contains the code <code><nowiki>{{#invoke:ExampleArgs|main|firstInvokeArg}}</nowiki></code>. This produces the result "firstInvokeArg". Now if we were to call <code>Template:ExampleArgs</code>, the following would happen: {| class="wikitable" style="width: 50em; max-width: 100%;" |- ! style="width: 60%;" | Code ! style="width: 40%;" | Result |- | <code><nowiki>{{ExampleArgs}}</nowiki></code> | firstInvokeArg |- | <code><nowiki>{{ExampleArgs|firstTemplateArg}}</nowiki></code> | firstInvokeArg |- | <code><nowiki>{{ExampleArgs|firstTemplateArg|secondTemplateArg}}</nowiki></code> | firstInvokeArg secondTemplateArg |} There are three options you can set to change this behaviour: <code>frameOnly</code>, <code>parentOnly</code> and <code>parentFirst</code>. If you set <code>frameOnly</code> then only arguments passed from the current frame will be accepted; if you set <code>parentOnly</code> then only arguments passed from the parent frame will be accepted; and if you set <code>parentFirst</code> then arguments will be passed from both the current and parent frames, but the parent frame will have priority over the current frame. Here are the results in terms of <code>Template:ExampleArgs</code>: ; frameOnly {| class="wikitable" style="width: 50em; max-width: 100%;" |- ! style="width: 60%;" | Code ! style="width: 40%;" | Result |- | <code><nowiki>{{ExampleArgs}}</nowiki></code> | firstInvokeArg |- | <code><nowiki>{{ExampleArgs|firstTemplateArg}}</nowiki></code> | firstInvokeArg |- | <code><nowiki>{{ExampleArgs|firstTemplateArg|secondTemplateArg}}</nowiki></code> | firstInvokeArg |} ; parentOnly {| class="wikitable" style="width: 50em; max-width: 100%;" |- ! style="width: 60%;" | Code ! style="width: 40%;" | Result |- | <code><nowiki>{{ExampleArgs}}</nowiki></code> | |- | <code><nowiki>{{ExampleArgs|firstTemplateArg}}</nowiki></code> | firstTemplateArg |- | <code><nowiki>{{ExampleArgs|firstTemplateArg|secondTemplateArg}}</nowiki></code> | firstTemplateArg secondTemplateArg |} ; parentFirst {| class="wikitable" style="width: 50em; max-width: 100%;" |- ! style="width: 60%;" | Code ! style="width: 40%;" | Result |- | <code><nowiki>{{ExampleArgs}}</nowiki></code> | firstInvokeArg |- | <code><nowiki>{{ExampleArgs|firstTemplateArg}}</nowiki></code> | firstTemplateArg |- | <code><nowiki>{{ExampleArgs|firstTemplateArg|secondTemplateArg}}</nowiki></code> | firstTemplateArg secondTemplateArg |} Notes: # If you set both the <code>frameOnly</code> and <code>parentOnly</code> options, the module won't fetch any arguments at all from #invoke. This is probably not what you want. # In some situations a parent frame may not be available, e.g. if getArgs is passed the parent frame rather than the current frame. In this case, only the frame arguments will be used (unless parentOnly is set, in which case no arguments will be used) and the <code>parentFirst</code> and <code>frameOnly</code> options will have no effect.
編集内容の要約:
たのしいRPGへの投稿はすべて、他の投稿者によって編集、変更、除去される場合があります。 自分が書いたものが他の人に容赦なく編集されるのを望まない場合は、ここに投稿しないでください。
また、投稿するのは、自分で書いたものか、パブリック ドメインまたはそれに類するフリーな資料からの複製であることを約束してください(詳細は
たのしいRPG:著作権
を参照)。
著作権保護されている作品は、許諾なしに投稿しないでください!
キャンセル
編集の仕方
(新しいウィンドウで開きます)
案内メニュー
個人用ツール
ログインしていません
トーク
ダークモード
投稿記録
アカウント作成
ログイン
名前空間
モジュール
議論
日本語
表示
閲覧
ソースを編集
履歴表示
その他
キャッシュを削除
検索
案内
メインページ
最近の更新
おまかせ表示
MediaWikiについてのヘルプ
ツール
リンク元
関連ページの更新状況
特別ページ
ページ情報
短縮URLを取得する