MediaWiki talk:Gadget-libLua.js

Wiktionary
I'm trying to use this script on Wiktionary. I would like to be able to, for instance, use a module to return the language name associated with a language code. I was using a test module, wikt:Module:User:Erutuon/languages. The code I placed in the script sandbox was the following:

I also added  to my common.js. (Then I did a more explicit call: . No difference.)

But, when loading a category page containing a catfix with a language code, I consistently get the notifications "Error!!!" and "langName is undefined." There are no console messages from the script sandbox script that I can see, though there is a message  that I don't understand.

What's going wrong? Is this script not currently working or not supposed to work on Wiktionary, or is my code faulty? — Eru·tuon 21:04, 22 May 2017 (UTC)
 * For you to be able to load this script with  from Wiktionary, it needs to be made into a gadget there. That involves loading it from a page in Wiktionary's MediaWiki namespace, and then giving it an entry in wikt:MediaWiki:Gadgets-definition. If you load it directly with   then you can avoid fiddling around with gadget definitions, but then you need to load the script's dependencies manually. libLua depends on the   module, so you need to load that as well, either in your script or in your common.js. If that doesn't fix the problem, let me know and I'll take a look at it. — Mr. Stradivarius  ♪ talk ♪ 08:26, 23 May 2017 (UTC)
 * Okay, I went back to the raw loading of this gadget, since it isn't installed on Wiktionary as far as I know. I'm sorry for such a basic question, but how do I load ? I tried   and , but neither seems to make   work. [Edit: if it helps,   is  .] — Eru·tuon 18:23, 23 May 2017 (UTC)
 * is the correct syntax, so I'm not sure why it wasn't working for you. I was able to get it to work on Wiktionary in my browser console by entering the following (one after the other, as the scripts need time to load):


 * Give that a try and see if it works for you. Best — Mr. Stradivarius  ♪ talk ♪ 14:09, 24 May 2017 (UTC)
 * That's odd! When I try it in the script sandbox, it gives an error –  – but when I try it in the console, it logs "English" just like it does for you. — Eru·tuon 17:34, 24 May 2017 (UTC)
 * That probably means that you are trying to use the library before it has finished loading. For example, if you copy all three lines above and execute them all at once in the browser console, you will get the same error (Firefox gives me "TypeError: mw.libs.lua is undefined"). However, if you try it a second time, then it will probably work, as your first request to load the library will probably have completed by then. If you want to make sure the library is loaded before your code is run, you can use  for mw.Api, and $.get to load mw.libs.lua. (mw.loader.load doesn't have any way of signalling when the load is complete, at least last time I checked, but $.get has a callback function that you can define for when the request completes.) — Mr. Stradivarius  ♪ talk ♪ 09:02, 25 May 2017 (UTC)