Lua/OS 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 OS library in your scripts.

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

Create a Lua Script that Uses the OS Library
To create a Lua script that uses the OS library: ""
 * 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:
 * clock
 * 0.003786627


 * date
 * Sat 28 Dec 2013 03:20:55 AM UTC


 * difftime
 * 31535999


 * time
 * 1388200855

Understand Your Lua Script
To understand your Lua script:
 * 1)   returns the approximate amount of CPU time used by the script.
 * 2)   returns the current date.
 * 3)   defines a local variable   as a table with the given date and time values.
 * indicates that the time value is not daylight savings time.
 * 1)   defines a local variable   as a table with the given date and time values.
 * 2)   returns the difference in seconds between   and.
 * 3)   returns the current time in seconds.

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