User:OrenBochman/Intoduction To Lua
In this unit we Introduce the first Lua Module.
Introducing Lua
editLua is a relatively new scripting language. It has been used successfully in a number of situations. It has similar capabilities to Javascript but avoids most of it shortcomings. Lua is a small programming language. Its syntax resembles other languages.
The first lessons is a quick introduction aimed at absolute beginners.
Scribunto
editModule Name Space
editLua modules are created in their own name space - the module name space. This allows the MediaWiki software to treat them different from other articles, talk pages and template.
Creating Hello World Lua
editTo create your first Lua module access scribunto and create a page called:
- [[Module:Hello]].
Then add to it the following Lua code:
local p = {}
function p.hello()
return 'Hello, world!'
end
return p
explanation:
Using Hello World Lua
editTo invoke hello world Lua use:
{{#invoke: Hello | hello }}
and the result should look like:
Hello, world!
Readable Lua Code
editYou can document you code using short one line comments or longer multiline comments
-- This is defines p as a local ?? definition
local p = {}
--[[
And This is a function definition.
It uses p already defined
--]]
function p.hello()
return 'Hello, world!'
end
return p
By adding comments and indenting the code with spaces you will make your code not only readable to others but also readable for yourself when you have to change it later.
See Also
edit- Programming in Lua
- lua reference manual
- Scribunto
- lua user group
- The Evolution of Lua Lua in a historical perspecitve