Talk:Lua/Tutorial

Your Two Cents
As all things wiki, this is a living document. I encourage you to improve it. While it is new (or undergoing any significant changes), you may want to share your ideas, here, on the Talk page. Thanks for your contributions! Deeb (talk) 00:31, 31 May 2012 (UTC)

On performance, loading data, etc.
Someone asked Brad what the constraints of Lua within Scribunto were. He said:


 * It depends on what the question means by "constraints". It certainly is a constraint that Lua can only get input as text strings passed to the and what can be fetched via frame:expandTemplate,  frame:preprocess, and the like. There's also the constraint that it can  only output wikitext not including pre-save transforms or transclusions  and other  constructs. It's  also a constraint that all Lua in the page is limited to 10 seconds CPU  time. And relative to standard Lua, Scribunto's Lua lacks all sorts of  functions (see mw:Extension:Scribunto/Lua reference manual).


 * Performance gains: Some templates are used to store data, and are invoked with #ifexist: in a main template. There are thousands of such "data"  templates.  With Lua, it's a lot more efficient to deal with a large  data structure in one module than a  in wikitext can handle.  The   function (probably coming to your wiki with MediaWiki  version 1.21wmf11; see the  deployment schedule) helps there too by only having to load  that data once per page no matter how many times the module is  #invoked.  Lua is pretty good about loading large blobs of static data,  and mw.loadData avoids the overhead of reparsing for each #invoke, so in  general things should be pretty good there.

Sharihareswara (WMF) (talk) 03:29, 13 March 2013 (UTC)

Tutorial not novice friendly
I'm the old syntax user to write Wiki templates without actual knowledge of other programming languages like C. But the tutorial in this page has skipped way too much detail. What is "local", "function" or "return"? No explanation. And where should I insert this   into the previous codes? I tried myself many times but all I get is just script error. I know veterans hate babysitting, but this is not the way you attract people to help contribute the project. I would like to see a tutorial truly customized to Wiki users that shows a side-by-side comparison between a syntax template and lua module which use the same input and output the same result. Sorry if I'm being too rude in this message. -- Sameboat (talk) 05:08, 18 March 2013 (UTC)
 * This tutorial, at least in my view, is not a tutorial for Lua per se; rather, it is a tutorial for using Lua with MediaWiki. Again, the tutorial on the official Lua website is an excellent source of information. -happy5214 09:30, 18 March 2013 (UTC)
 * I am surprised that this is the only discussion I see about how lua can be used by a novice (sans C-like). I Was expecting a little better clue on how to implement even a simple variable function on a wiki page using lua. (Not the syntax of lua itself, but the structural syntax within Wiki.) Seems not working. Could someone elaborate the doc page a little bit more please? Viswaprabha (talk) 17:46, 29 April 2013 (UTC)
 * Oh I just saw this one! That is what I was looking for! So, it may be a good idea to keep a link here in the tutorial page too! Viswaprabha (talk) 18:41, 29 April 2013 (UTC)

Calling Lua from template code
I tried to call a Lua routine from inside a template code:

My aim was to test the possibility od a "double-step" template->scribuntu conversion, replacing template code with a call to a scribuntu script while keeping template call identical, so allowing a transparent-for-users conversion and deferring any change into page code. I searched a little bit but I couldn't find the trick. Have you a suggestion/a link for me? --Alex brollo (talk) 06:58, 22 May 2013 (UTC)

Explanation of Code
As someone else alluded to earlier, this tutorial isn't terribly clear for beginners. Now I often like that kind of tutorial, because I'm a programmer and can probably figure it out by context. But it certainly can't hurt to give relative newbies the option of seeing a clearer explanation of what's going on.

Then again, we don't want to clutter the tutorial in a way that will annoy the 1337 among us. So I made it collapsed, like this:

It's only a rough draft explanation, of course. Any additional clarity people could add to it would be welcome. — Kazvorpal (talk) 16:02, 27 December 2016 (UTC)

Some changes to the example code
Changed the "p" to "export", since that makes more logical sense (following example as seen in existing code).

Changed "hello" to "show", because, again that makes more logical sense. (following example as seen in existing code).


 * Many installations specifically require the returned object to be named "p", so your first suggestion should not be taken. As for the second, that's not really following the typical convention of such an introductory fragment of code. DSquirrelGM &#120035;&#120031;&#120018; 06:16, 7 January 2019 (UTC)


 * I undid these changes primarily because they (inadvertently I'm sure) broke both the code itself and the Explanation of Code section. I suppose I could have fixed what was broken, but this was easier. I don't have an opinion on whether or not the name changes made the code more readable, and I have no input on DSquirrelGM's concerns (I simply don't know), so others should feel free to improve things. Gurnec (talk)

strict.lua
I have run into an issue when importing a Template into my wiki:

 

Upon inspecting the error, I see that Module:Message box is using.

Upon researching, I found on this page under Lua/Tutorial that in order to use it, one should create a file named.

Please forgive my ignorance, but where exactly am I supposed to create this file? Somewhere under the Scribunto extension folder? I have tried creating a similar file both under  and under   to no avail. Lwangaman (talk) 15:12, 23 October 2022 (UTC)