Lua/Modules

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. This lesson will show you how to add multiple functions to a module.

Prerequisites
This lesson assumes you have already completed the Scribunto/Lua lesson.

Create a Lua Script with Multiple Functions
To create a Lua script with multiple functions: ""
 * 1) Navigate to Module:Sandbox.
 * 2) 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.
 * 1) Add the following code and save the page:

Test Your Lua Script
To test your Lua script:
 * 1) Navigate to either the Module_talk:Sandbox page, the Sandbox page, or your own user or sandbox page.
 * 2) Add the following code and save the page:

The result should be:
 * Hello!
 * Nice to meet you!

Understand Your Lua Script
To understand your Lua script: Each Lua module can contain one or more functions that may be called individually.
 * 1)   adds a function named.
 * 2)   adds a function named.
 * 3)   calls the Sandbox module   function.
 * 4)   calls the Sandbox module   function.

Conclusion
Congratulations! You've now created, tested, and understood a Lua module with multiple functions. Continue on to the Variables lesson.