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

→‎About Lua: Rewriting comments a little for clarity; also changing placement as, weirdly, our syntax highlighter doesn't do monospaced whitespace correctly.
(→‎About Lua: Displaying a thumbnail of the first page of a PDF presentation isn't very useful, so converting into a see also link.)
(→‎About Lua: Rewriting comments a little for clarity; also changing placement as, weirdly, our syntax highlighter doesn't do monospaced whitespace correctly.)
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 [[hello world]] function contained in [[Module:HelloWorld]]:
<syntaxhighlight lang="lua">
my_object = {}; -- All Lua modules on Wikipedia must begin by defining a variable that will hold their
-- externally accessible functions. They can have any name and may also hold data.
--that will hold their externally accessible functions.
my_object = {};
--Such variables can have whatever name you want and may
--also contain various data as well as functions.
 
-- Add a function to the variable. Such functions are callable in Wikipedia via the #invoke command.
my_object.hello = function( frame ) --Add a function to "my_object".
-- "frame" will contain the data that Wikipedia sends this function when it is called.
--Such functions are callable in Wikipedia
my_object.hello = function( frame ) --Add a function to "my_object".
--via the #invoke command.
--"frame" will contain the data that Wikipedia
--sends this function when it runs.
local str = "Hello World!" --Declare a local variable and set it equal to
--"Hello World!".
return str --This tells us to quit this function and send the information in
--"str" back to Wikipedia.
end -- end of the function "hello"
 
local str = "Hello World!" -- Declare a local variable and setassign itdata equalto toit.
return my_object --All modules end by returning the variable containing its
local str = "Hello World!"
--functions to Wikipedia.
 
return str --This tells us to quitQuit this function and send the information in "str" back to Wikipedia.
-- Now we can use this module by calling {{#invoke: HelloWorld | hello }}.
-- The "print" function is not allowed, inso Wikipedia. Allall output is accomplished via
-- Note that the first part of the invoke is the name of the Module's wikipage,
-- returning strings in this fashion.
-- and the second part is the name of one of the functions attached to the
return str
-- variable that you returned.
 
end -- end ofEnd the function "hello".
-- The "print" function is not allowed in Wikipedia. All output is accomplished
end
-- via strings "returned" to Wikipedia.
 
return my_object -- All modules end by returning the variable containing its functions to Wikipedia.
return my_object
 
-- Now weWe can now use this module by calling {{#invoke: HelloWorld | hello }}.
-- The #invoke command begins with the module's name, in this case "HelloWorld",
-- then takes the name of one of its functions as an argument, in this case "hello".
</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)]]".
0

edits

"https://te.wikipedia.org/wiki/ప్రత్యేక:MobileDiff/1387547" నుండి వెలికితీశారు