"వికీపీడియా:Lua" కూర్పుల మధ్య తేడాలు

→‎About Lua: Use a hello world example rather than the dysfunctional factorial example (we don't even support "print")
(→‎About Lua: don't mention coroutines, we don't support them)
(→‎About Lua: Use a hello world example rather than the dysfunctional factorial example (we don't even support "print"))
== About Lua ==
[[File:WMF Tech Talk 2013-02-28 slides - Scribunto presentation.pdf|thumbnail|Brad Jorsch’s short presentation for a basic example of how to convert a wikitext template into a Lua module.]]
Lua is a [[scripting language]] which can be used to analyze data, calculate expressions, and format results using functions or [[object-oriented programming]]. Although some Lua script can be kept simple, for easy understanding, Lua allows complex structures which would challenge a [[computer scientist]], with tables, dynamic functions, and [[associative array]]s where index [[subscript]]s can be words as well as index numbers. Lua also supports [[recursion]] of re-nested functions, so care should be taken to avoid excessive complexity where other users would not understand how to maintain a Lua module. The following is an example of Lua [[source code]] for a [[factorialhello world]] function contained in [[Module:HelloWorld]]:
<syntaxhighlight lang="lua">
my_object = {}; --All Lua modules on Wikipedia must begin by defining a variable
function factorial(n)
--that will hold their externally accessible functions.
if n == 0 then
--Such variables can have whatever name you want and may
return 1 --this returns the result 1 when passed zero
--also contain various data as well as functions.
else
 
return n * factorial(n - 1)
my_object.hello = function( frame ) --Add a function to "my_object".
end
--Such functions are callable in Wikipedia
end
--via the #invoke command.
for index = 1,5 do
--"frame" will contain the data that Wikipedia
print(index, "n! = ", factorial(index) )
--sends this function when it runs.
end
else
local str = "Hello World!" --Declare a local variable and set it equal to
--"Hello World!".
end
return str --This tells us to quit this function and send the information in
--"str" back to Wikipedia.
end -- end of the function "hello"
 
return my_object --All modules end by returning the variable containing its
--functions to Wikipedia.
 
-- Now we can use this module by calling {{#invoke: HelloWorld | hello }}.
-- Note that the first part of the invoke is the name of the Module's wikipage,
-- and the second part is the name of one of the functions attached to the
-- variable that you returned.
 
-- The "print" function is not allowed in Wikipedia. All output is accomplished
-- via strings "returned" to Wikipedia.
</syntaxhighlight>
A sample of Lua is highlighted by tag "&lt;source lang="lua">...&lt;/source>" placed around the Lua source code. To view some more complex examples of Lua, see article: "[[Lua (programming language)]]".
"https://te.wikipedia.org/wiki/ప్రత్యేక:MobileDiff/1387545" నుండి వెలికితీశారు