Lua/Frame Object

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 use the Lua Frame object in your scripts.

Prerequisites
This lesson assumes you have already completed the Tables lesson.

Create a Lua Script that Uses the Frame Object
To create a Lua script that uses the Frame object: ""
 * 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 similar to:
 * args
 * table[1] is These
 * table[2] is are
 * table['arg3'] is frame args.


 * callParserFunction
 * 2013-12-20 02:20:13


 * expandTemplate
 * 2


 * extensionTag
 * text


 * getParent
 * Module talk:Sandbox


 * getTitle
 * Module:Sandbox

Understand Your Lua Script
To understand your Lua script:
 * 1)   declares a local function named   that accepts a single parameter , which is the table to be converted to a string.
 * See Lua/Tables for more information.
 * 1)   declares a function named   which accepts a single parameter , which is the interface to the calling object.
 * 2) *  is a table of arguments passed to the function.
 * 3) * Positional arguments are accessed by numeric position.
 * 4) * Named arguments are accessed by name.
 * 5)   calls the  parser function , passing the string literal   to display the current time.
 * 6)   calls the   template, passing a table of parameter arguments and returns the result.
 * 7)   tags the given text to control processing when the text is returned to the calling object.
 * 8)   returns the parent of the calling object, or in this case the page that invoked the module.
 * 9)   returns a string containing the title of the frame.

Conclusion
Congratulations! You've now created, tested, and understood a Lua script that uses the Frame object. Return to the main Lua page to learn about other Lua code libraries.