Questions about this topic? Sign up to ask in the talk tab.
Difference between revisions of "LUA"
From NetSec
(→Global Variables vs Local Variables) |
|||
Line 50: | Line 50: | ||
return Sum | return Sum | ||
end | end | ||
+ | </source> | ||
+ | }} | ||
+ | |||
+ | |||
+ | =Tables= | ||
+ | Lua tables are a bit like arrays, except that an array is.. well an array of values. | ||
+ | A Table, is an array of Keys, and those Keys have values. | ||
+ | |||
+ | {{Protip|Unlike what you would expect, the index for a table starts at 1, instead of 0.}} | ||
+ | Declaring a Table: | ||
+ | {{code|text= | ||
+ | <source lang="lua"> | ||
+ | MyTable = {} --declares an empty table. | ||
</source> | </source> | ||
}} | }} |
Revision as of 20:14, 4 May 2012
Lua is a portable interpreted language. It is mainly used in Games, however it is also used by NMAP's Scripting Engine
Comments
-- This is a single line comment
|
--[[
This
is
a
multi-line
comment
]]
|
Variables
In Lua, variables are very simple, you don't even have to declare a datatype, all you need to do is assign a value.
Var = 1 Var2 = "Im a var!" Var3 = 2 Var4 = Var * Var3 |
Global Variables vs Local Variables
When you declare a variable in Lua, it is globally accessible unless otherwise specified with local.
GlobalVar = 0 local LocalVar = 1337 |
Functions
Functions in lua are quite easy as well.
function SimpleAddition(x,y,z) local Sum = x + y + z --only accessible from within this context. SumTimesTwo = Sum * 2 -- can be referenced from anywhere in the current file, or wherever file is loaded. return Sum end |
Tables
Lua tables are a bit like arrays, except that an array is.. well an array of values. A Table, is an array of Keys, and those Keys have values.
Protip: Unlike what you would expect, the index for a table starts at 1, instead of 0.
Declaring a Table:
MyTable = {} --declares an empty table. |