# Lua/Title Library

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 Title library in your scripts.

## Prerequisites

This lesson assumes you have already completed the Tables lesson.

## Create a Lua Script that Uses the Title Library

To create a Lua script that uses the Title library:
* Navigate to Module:Sandbox.
* 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:

## Test Your Lua Script

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:
The result should be similar to:

   ### baseText

       Sandbox

   ### canTalk

       true

   ### exists

       true

   ### fileExists

       false

   ### fragment
   ### fullText

       Module talk:Sandbox

   ### getContent

       == Welcome == Welcome to the Wikiversity Sandbox. Feel free to experiment with edits on this page.

   ### id

       150785

   ### inNamespace

       false

   ### inNamespaces

       false

   ### interwiki
   ### isContentPage

       false

   ### isExternal

       false

   ### isLocal

       true

   ### isRedirect

       false

   ### isSpecialPage

       false

   ### isSubpage

       false

   ### isTalkPage

       true

   ### isSubpageOf

       false

   ### new

       150784

   ### nsText

       Module_talk

   ### prefixedText

       Module talk:Sandbox

   ### rootText

       Sandbox

   ### subjectNsText

       Module

   ### subpageText

       Sandbox

   ### text

       Sandbox

## Understand Your Lua Script

To understand your Lua script:
* local title = mw.title.getCurrentTitle gets the title object for the current page and assigns it to the variable named title.
* title.canTalk returns whether the title can have a talk page.
* title.baseText returns the base title text or parent page text if this is a subpage.
* title.exists returns whether the title exists.
* title.fileExists returns whether the file or image exists.
* title.fragment returns the title fragment.
* title.fullText returns the full text of the page title, with the namespace prefix.
* title:getContent returns the page content for the title.
* title.id returns the title id.
* title:inNamespace(0) returns whether the title is in the given namespace.
* title:inNamespaces(0) returns whether the title is in the given namespaces.
* title.interwiki returns the title interwiki prefix, if any.
* title.isContentPage returns whether the title is in a content namespace.
* title.isExternal returns whether the title has an interwiki prefix.
* title.isLocal returns whether the title is in this wiki project.
* title.isRedirect returns whether the title is a redirect.
* title.isSpecialPage returns whether the title is a special page.
* title.isSubpage returns whether the title is a subpage.
* title.isTalkPage returns whether the title is a talk page.
* title:isSubpageOf(title2)) returns whether the title is a subpage of title2.
* mw.title.new(text, namespace) gets the title object for the given page and namespace.
* title.nsText returns the namespace text for the title.
* title.prefixedText returns the title of the page, with the namespace and interwiki prefixes.
* title.rootText returns the title of the root page without prefixes.
* title.subjectNsText returns the text of the subject namespace for the title.
* title.subpageText returns the subpage name for the title.
* title.text returns The title text without namespace or interwiki prefixes.

## Conclusion

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

## See Also

* Lua Tables