<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>http://www.easyuo.com/openeuo/wiki/index.php?action=history&amp;feed=atom&amp;title=Lua_Introduction</id>
		<title>Lua Introduction - Revision history</title>
		<link rel="self" type="application/atom+xml" href="http://www.easyuo.com/openeuo/wiki/index.php?action=history&amp;feed=atom&amp;title=Lua_Introduction"/>
		<link rel="alternate" type="text/html" href="http://www.easyuo.com/openeuo/wiki/index.php?title=Lua_Introduction&amp;action=history"/>
		<updated>2026-05-14T02:21:47Z</updated>
		<subtitle>Revision history for this page on the wiki</subtitle>
		<generator>MediaWiki 1.26.3</generator>

	<entry>
		<id>http://www.easyuo.com/openeuo/wiki/index.php?title=Lua_Introduction&amp;diff=645&amp;oldid=prev</id>
		<title>76.184.213.234: /* Conclusion */</title>
		<link rel="alternate" type="text/html" href="http://www.easyuo.com/openeuo/wiki/index.php?title=Lua_Introduction&amp;diff=645&amp;oldid=prev"/>
				<updated>2010-10-09T22:42:07Z</updated>
		
		<summary type="html">&lt;p&gt;‎&lt;span dir=&quot;auto&quot;&gt;&lt;span class=&quot;autocomment&quot;&gt;Conclusion&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;table class='diff diff-contentalign-left'&gt;
				&lt;col class='diff-marker' /&gt;
				&lt;col class='diff-content' /&gt;
				&lt;col class='diff-marker' /&gt;
				&lt;col class='diff-content' /&gt;
				&lt;tr style='vertical-align: top;' lang='en'&gt;
				&lt;td colspan='2' style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan='2' style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;Revision as of 22:42, 9 October 2010&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l245&quot; &gt;Line 245:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 245:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;* http://www.lua.org/manual/5.1/manual.html&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;* http://www.lua.org/manual/5.1/manual.html&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;* http://www.lua.org/pil/ - (Old 5.0 version. Not everything works.)&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;* http://www.lua.org/pil/ - (Old 5.0 version. Not everything works.)&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;[[First Steps]]&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;[[ Hello World]]&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>76.184.213.234</name></author>	</entry>

	<entry>
		<id>http://www.easyuo.com/openeuo/wiki/index.php?title=Lua_Introduction&amp;diff=67&amp;oldid=prev</id>
		<title>46.127.27.108: Created page with &quot;This tutorial will focus on the new language Lua and assumes that you already know how script writing and programming works in general.  However, if you have never written anythi...&quot;</title>
		<link rel="alternate" type="text/html" href="http://www.easyuo.com/openeuo/wiki/index.php?title=Lua_Introduction&amp;diff=67&amp;oldid=prev"/>
				<updated>2010-10-07T14:56:08Z</updated>
		
		<summary type="html">&lt;p&gt;Created page with &amp;quot;This tutorial will focus on the new language Lua and assumes that you already know how script writing and programming works in general.  However, if you have never written anythi...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;This tutorial will focus on the new language Lua and assumes that you already know how script writing and programming works in general.&lt;br /&gt;
&lt;br /&gt;
However, if you have never written anything besides scripts then some of the explanations may be a bit complicated. I suggest you just read on, look at the examples and try to figure out what they mean. If you still feel completely lost then don't worry, it will come in time as you get more used to Lua.&lt;br /&gt;
&lt;br /&gt;
== Variables and Types ==&lt;br /&gt;
''You may leave this lesson out if it's too complicated and move on to the next part!''&lt;br /&gt;
&lt;br /&gt;
Variable names are the same as in other languages, a leading A-Za-z_ followed by any number of A-Za-z0-9_ characters. They are case sensitive, so X and x are not the same.&lt;br /&gt;
&lt;br /&gt;
Variables are dynamically typed. That means, a variable can contain any type. Variables do not have types, values do.&lt;br /&gt;
&lt;br /&gt;
Primitive types: number, string, boolean, nil&lt;br /&gt;
(there are more types but I'll leave them away for now)&lt;br /&gt;
&lt;br /&gt;
Numbers are always floating-point Doubles in Lua. Any Double can easily represent an Integer, so don't let that confuse you. Working with Doubles is just as easy as working with Integers.&lt;br /&gt;
&lt;br /&gt;
Strings can be defined using double quotes &amp;lt;nowiki&amp;gt;&amp;quot;&amp;quot; or single quotes ''&amp;lt;/nowiki&amp;gt;. Both are exactly the same (even when using escape sequences). You can concatenate two strings using the .. operator. It also works with a string and a number, in that order.&lt;br /&gt;
&lt;br /&gt;
Booleans can be true or false. Use them in comparisons.&lt;br /&gt;
&lt;br /&gt;
Nil is a special value/type which means &amp;quot;I'm not a value&amp;quot;. It's often used by functions to return a value that signals an error. Undefined variables automatically have the value nil.&lt;br /&gt;
&lt;br /&gt;
 MyVariable1 = 2.14 + 1&lt;br /&gt;
 b = &amp;quot;hello\nworld&amp;quot;&lt;br /&gt;
 c = 'hello' .. '\nworld ' .. 123&lt;br /&gt;
 d = x==3 or y&amp;lt;=7 and not z~=(7-4/2)*3&lt;br /&gt;
 e = nil&lt;br /&gt;
&lt;br /&gt;
In the above example, you also see lots of operators being used. They're mostly the same as in other languages, except for ~= which means &amp;quot;unequal&amp;quot;. Operator precedence works as you would expect.&lt;br /&gt;
&lt;br /&gt;
== Assignments and Functions ==&lt;br /&gt;
''The second half of this lesson may be a bit complex. Try to learn how to assign values to variables and how to create and call functions! Remember you can use print() to check results!''&lt;br /&gt;
&lt;br /&gt;
This is actually not as simple as it seems. Lua uses the idea of stacks extensively and thus can deal with long lists of values quite easily.&lt;br /&gt;
&lt;br /&gt;
 x = 1 --line comment&lt;br /&gt;
 y = 2&lt;br /&gt;
 x,y = 1,2&lt;br /&gt;
 a,b,c = 1,2,3,4 --4 is ignored&lt;br /&gt;
 a,b,c = 1,2 --c is assigned nil&lt;br /&gt;
&lt;br /&gt;
As you can see, you can assign multiple variables in a single assignment statement. In mismatched situations, excess values are ignored and excess variables are assigned nil.&lt;br /&gt;
&lt;br /&gt;
This feature really becomes useful for returning multiple values from a function, which is not possible in most other languages except by passing additional return variables as parameters or by using return structures.&lt;br /&gt;
&lt;br /&gt;
 function Test(a)&lt;br /&gt;
   return a*a, a^3&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 a,b = Test(5) --a=25, b=125&lt;br /&gt;
&lt;br /&gt;
Actually, functions are another type in Lua. The above declaration is just a nice way of writing the following...&lt;br /&gt;
&lt;br /&gt;
 Test = function(a)&lt;br /&gt;
   return a*a, a^3&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
...which means there is a variable Test with (the address of) a function as value. It's similar to other languages that allow function pointers/references.&lt;br /&gt;
&lt;br /&gt;
 function Sum(a,b)&lt;br /&gt;
   return a+b&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 Diff = function(a,b)&lt;br /&gt;
   return a-b&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 function CalcInc(f,a,b)&lt;br /&gt;
   return f(a,b)+1&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 x = CalcInc(Sum,5,3) --x=9&lt;br /&gt;
 y = CalcInc(Diff,5,3) --y=3&lt;br /&gt;
 z = CalcInc(function(a,b) return a*b end,5,3) --z=16 using anonymous function&lt;br /&gt;
&lt;br /&gt;
Parameter passing is always by value. Inside a function, passed parameter names have local scope, so they won't conflict with outside variables. You can also define local variables yourself.&lt;br /&gt;
&lt;br /&gt;
 function Square(a)&lt;br /&gt;
   local b = 123&lt;br /&gt;
   return a*a&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 a = 5&lt;br /&gt;
 b = 5&lt;br /&gt;
 x = Square(3) --x=9, a and b are still 5&lt;br /&gt;
&lt;br /&gt;
In fact, all variables are global unless defined as local. Defining a local variable outside of a function or block means the variable is local to the file and can't be accessed from other files.&lt;br /&gt;
&lt;br /&gt;
 local function Sum(a,b)&lt;br /&gt;
   return a+b&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 local Sum = function(a,b)&lt;br /&gt;
   return a+b&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
The same goes for variables that contain functions. The above function declarations are the same. Both are local to the file so there won't be conflicts with other files or libraries.&lt;br /&gt;
&lt;br /&gt;
Don't try to call functions that are defined later (i.e. further down). It's really just like with variables.&lt;br /&gt;
&lt;br /&gt;
== Control Structures ==&lt;br /&gt;
''This lesson is a must read and should be quite easy to get!''&lt;br /&gt;
&lt;br /&gt;
Control structures are mostly the same as in other languages.&lt;br /&gt;
&lt;br /&gt;
 if x&amp;lt;y then&lt;br /&gt;
   --true&lt;br /&gt;
 else&lt;br /&gt;
   --false&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 if x==1 then&lt;br /&gt;
   --case 1&lt;br /&gt;
 elseif x==2 then&lt;br /&gt;
   --case 2&lt;br /&gt;
 else&lt;br /&gt;
   --other cases&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Note that IF must _always_ be terminated by an END, even if only one statement follows. This goes for all control structures and is a little inconvenient but you'll get used to it.&lt;br /&gt;
&lt;br /&gt;
 for i = 1,10 do&lt;br /&gt;
   print(i)&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 for i = 10,1,-1 do --step value is -1&lt;br /&gt;
   local x=1&lt;br /&gt;
   print(i-x)&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Each block has its own local scope. So if you declare local variables inside a block, it will disappear if you leave that block (even if only for another iteration). FOR variables are automatically declared local.&lt;br /&gt;
&lt;br /&gt;
 repeat&lt;br /&gt;
   --do something&lt;br /&gt;
 until x&amp;gt;10&lt;br /&gt;
 &lt;br /&gt;
 while x&amp;lt;=10 do&lt;br /&gt;
   if x==7 then&lt;br /&gt;
     break&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 do&lt;br /&gt;
   --simple block&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
You can use BREAK to jump out of REPEAT/WHILE/FOR structures. By definition, BREAK can only occur before an END keyword which seems a little odd at first but usually works out that way (any following statements couldn't be reached anyway).&lt;br /&gt;
&lt;br /&gt;
Unfortunately, there is no CONTINUE. You must use nested IFs instead which is inconvenient as well but we'll just have to live with it.&lt;br /&gt;
&lt;br /&gt;
 --this won't work, there is no continue!!!&lt;br /&gt;
 for y=1,20 do&lt;br /&gt;
   if y==10 then continue end&lt;br /&gt;
   for x=1,80 do&lt;br /&gt;
     if x==40 then continue end&lt;br /&gt;
     --do something (except when: y=10 or x=40)&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 --use nested ifs instead&lt;br /&gt;
 for y=1,20 do&lt;br /&gt;
   if y~=10 then&lt;br /&gt;
     for x=1,80 do&lt;br /&gt;
       if x~=40 then&lt;br /&gt;
         --do something except when y=10 or x=40&lt;br /&gt;
       end&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
There is also a FOR..IN statement that is used like a &amp;quot;foreach&amp;quot; in other languages. I'll cover that one later.&lt;br /&gt;
&lt;br /&gt;
SWITCH isn't supported either but can be emulated using keyed hash tables and anonymous functions.&lt;br /&gt;
&lt;br /&gt;
== Tables ==&lt;br /&gt;
''Ignore this lesson is you had problems with the previous ones. You won't need tables or arrays for basic scripts!''&lt;br /&gt;
&lt;br /&gt;
Tables really deserve their own tutorial because the topic is extensive! I'll just show you the basics here. And just like functions, tables are another type in Lua.&lt;br /&gt;
&lt;br /&gt;
 a = {22,84,63}&lt;br /&gt;
 print(&amp;quot;Num: &amp;quot; .. a[2]) --prints 84&lt;br /&gt;
 &lt;br /&gt;
 a = {3.14,&amp;quot;test&amp;quot;,true,MyFunc}&lt;br /&gt;
 --tables can hold all kinds of values...&lt;br /&gt;
 &lt;br /&gt;
 --...even other tables&lt;br /&gt;
 a = {{&amp;quot;1&amp;quot;,&amp;quot;2&amp;quot;},{&amp;quot;3&amp;quot;,&amp;quot;4&amp;quot;}}&lt;br /&gt;
 print(a[2][1]) --prints 3&lt;br /&gt;
 &lt;br /&gt;
 a = {} --empty table, not the same as nil!&lt;br /&gt;
&lt;br /&gt;
If you use a table like an array as shown above, indexing starts at 1 (unlike C++/Java etc where indexing starts at zero). The # operator tells you how many (numbered) elements there are in a table.&lt;br /&gt;
&lt;br /&gt;
 a = {&amp;quot;aaa&amp;quot;,&amp;quot;bbb&amp;quot;,&amp;quot;ccc&amp;quot;} --#a is 3&lt;br /&gt;
 for i = 1,#a do&lt;br /&gt;
   print(a[i])&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
But tables are not just arrays, they can do a lot more. They're actually hash tables with key/value pairs. That means you can use any value as index, not just numbers. You give it a key, it tells you the associated value.&lt;br /&gt;
&lt;br /&gt;
 a = {&lt;br /&gt;
   [1] = &amp;quot;aaa&amp;quot;,&lt;br /&gt;
   [2] = &amp;quot;bbb&amp;quot;,&lt;br /&gt;
   [3] = &amp;quot;ccc&amp;quot;&lt;br /&gt;
 } --same array as in last example&lt;br /&gt;
 &lt;br /&gt;
 a = {&lt;br /&gt;
   [&amp;quot;a&amp;quot;] = &amp;quot;aaa&amp;quot;,&lt;br /&gt;
   [&amp;quot;YouNameIt&amp;quot;] = &amp;quot;bbb&amp;quot;,&lt;br /&gt;
   [3.14] = &amp;quot;ccc&amp;quot;&lt;br /&gt;
 }&lt;br /&gt;
 print(a[3.14]) --prints ccc&lt;br /&gt;
 &lt;br /&gt;
 a = {[7]=&amp;quot;num&amp;quot;,[&amp;quot;7&amp;quot;]=&amp;quot;str&amp;quot;}&lt;br /&gt;
 print(a[7]) --prints num&lt;br /&gt;
&lt;br /&gt;
If you don't specify a key when defining a table, incremental numeric indices will be used which is why you can use tables as arrays. You can also mix, i.e. specify keys for some values and not for others. Unlike traditional arrays which have a fixed number of elements, tables also allow you to insert new elements.&lt;br /&gt;
&lt;br /&gt;
 a = {}&lt;br /&gt;
 a[4] = &amp;quot;ddd&amp;quot;&lt;br /&gt;
 a[5] = &amp;quot;eee&amp;quot;&lt;br /&gt;
&lt;br /&gt;
So you don't need to declare everything inside {...}, it's just a nice way of doing it. But you must set the type of a variable to &amp;quot;table&amp;quot; by using at least {}. You cannot index a nonexistent table. When you access a nonexistent element, nil is returned. So deleting means setting an element to nil. It's the same as with variables. However, be careful when using the # operator on mixed tables that contain nil elements. You might get unexpected results.&lt;br /&gt;
&lt;br /&gt;
Btw: When using valid identifiers as keys, you can also specify them directly (leaving away enclosing brackets and string markers) and use a dot to index in an object-like manner:&lt;br /&gt;
&lt;br /&gt;
 t = {id3 = 3}&lt;br /&gt;
 print(t.id3)&lt;br /&gt;
 &lt;br /&gt;
 --is the same as...&lt;br /&gt;
 &lt;br /&gt;
 t = {[&amp;quot;id3&amp;quot;] = 3}&lt;br /&gt;
 print(t[&amp;quot;id3&amp;quot;])&lt;br /&gt;
&lt;br /&gt;
The enclosing brackets are really only there to allow prior evaluation of the index so that something like t[&amp;quot;id&amp;quot;..3] becomes possible, but with simple identifiers it's not necessary.&lt;br /&gt;
&lt;br /&gt;
There is a lot more to tables: A table library with more utilities, tables used as objects, metatables that define how values are accessed etc...&lt;br /&gt;
&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
&lt;br /&gt;
Still with me? Understood some of the examples? Great! Lua is a wonderful little language with many quirks and sometimes tricky besides. But you can also write very plain and simple code. Keep to the basics at first and move on to more difficult Lua concepts when you feel secure!&lt;br /&gt;
&lt;br /&gt;
External links of interest:&lt;br /&gt;
* http://www.lua.org&lt;br /&gt;
* http://www.lua.org/manual/5.1/manual.html&lt;br /&gt;
* http://www.lua.org/pil/ - (Old 5.0 version. Not everything works.)&lt;/div&gt;</summary>
		<author><name>46.127.27.108</name></author>	</entry>

	</feed>