« Introduction au Lua/Modules » : différence entre les versions
Contenu supprimé Contenu ajouté
Aucun résumé des modifications |
m 11 révisions importées depuis en:Lua/Modules : Pour traduction en français |
||
Ligne 1 :
Lua modules based on the Scribunto/Lua extension are stored in resource pages using the Module: namespace. Each module uses a table to hold functions and variables, and that containing table is returned at the end of the module code.<ref>http://www.mediawiki.org/wiki/Extension:Scribunto/Lua_reference_manual</ref> This lesson will show you how to add multiple functions to a module.
__TOC__
==
==
To create a Lua script with multiple functions:
#
# Clear all existing code.
#: It's a sandbox. Everyone is free to play in the sandbox. But if you find another user is actively editing the sandbox at the same time, you may also use Module:Sandbox/Username, where Username is your Wikiversity username.
# Add the following code and save the page:
<blockquote><pre>
local p = {}
Ligne 20 :
function p.meet()
return '
end
Ligne 26 :
</pre></blockquote>
==
To test your Lua script:
# Navigate to either the [[Module_talk:Sandbox]] page, the [[Wikiversity:Sandbox]] page, or your own user or sandbox page.
# Add the following code and save the page:
<blockquote><pre>
* {{#invoke:Sandbox|hello}}
Ligne 34 ⟶ 35 :
</pre></blockquote>
The result should be:
<blockquote>
*
*
</blockquote>
==
To understand your Lua script:
# <code>function p.
# <code>
# <code><nowiki>{{#invoke:Sandbox|
# <code><nowiki>{{#invoke:Sandbox|meet}}</nowiki></code> calls the Sandbox module <code>meet</code> function.
Each Lua module can contain one or more functions that may be called individually.
== Conclusion ==
== References ==
{{reflist}}
{{CourseCat}}
[[Category: Lessons]]
[[Category: Completed resources]]
|