StendhalScripting/Lua: Difference between revisions

Content deleted Content added
imported>AntumDeluge
Some basics about Lua
imported>AntumDeluge
Line 67:
 
==== Iterating Tables ====
 
Tables can be iterated using the ''pairs'' or ''ipairs'' iterators:
<pre>
local mytable = {
"foo",
"bar",
}
 
print("indexes:")
for idx in pairs(mytable) do
print(idx)
end
 
print("\nvalues:")
for idx, value in pairs(mytable) do
print(value)
end
</pre>
 
Output:
<pre>
indexes:
1
2
 
values:
foo
bar
</pre>
 
Using a key=value table:
<pre>
local mytable = {
["foo"] = "hello",
["bar"] = " world!",
}
 
print("keys:")
for key in pairs(mytable) do
print(key)
end
 
print("\nvalues:")
for key, value in pairs(mytable) do
print(value)
end
</pre>
 
Output:
<pre>
keys:
foo
bar
 
values:
hello
world!
<pre>
 
See also: [http://lua-users.org/wiki/TablesTutorial Lua Tables Tutorial]
 
=== Functions ===