JS はクライアント上で実行され、Lua はサーバー上で実行されるため、これを直接行うことはできません。できることは、JS から MediaWiki API を使用してモジュールを呼び出すことです。具体的にはexpandtemplates
API モジュールを使用します。
たとえば、Module:Hexh2d
からパラメーター(ウィキテキスト内) と結果を使用して関数を呼び出したい場合、JS は次のようになります。FF
{{#invoke:hex|h2d|FF}}
alert
var api = new mw.Api();
api.get( {
action: 'expandtemplates',
text: '{{#invoke:hex|h2d|FF}}'
} ).done ( function ( data ) {
alert(data.expandtemplates['*']);
} );
OPの特定のケースでは、英語のウィクショナリーで実行されています:
var langName = 'Esperanto';
(new mw.Api()).get({
action: 'expandtemplates',
format: 'json',
prop: 'wikitext',
text: '{{#invoke:languages/templates|getByCanonicalName|' + langName + '|getCode}}'
}).done(function(data) {
alert('Language name: ' + langName + '\nLanguage code: ' + data.expandtemplates.wikitext);
});
( prop: 'wikitext'
API からの警告を回避しdata.expandtemplates.wikitext
、少し不可解な ではなくas として結果にアクセスできるようにしますdata.expandtemplates['*']
。それ以外の場合、違いはありません。)