View Full Version : LUA Boot Camp
etron
November 7th, 2008, 06:44 AM
While I am trying to learn yet another language, I figured I would start this thread, which would document all the 'basics' of programming in LUA. The official Girder documentation does contain a lot of information, I spent way too much time trying to find out how to do some of the basic things. So let's put all the useful examples in this thread.
Some basic LUA rules:
LUA is case sensitive
to comment out a line, start the line with 2 dashes. Example: --this is a comment
Ending lines with a semi-colon is optional
Would be great if this thread could be set 'sticky', making it easier to find this basic knowledge.
etron
November 7th, 2008, 06:48 AM
Simple if-else examples:
if varA == 0 and varB == 0 then
return "yes"
else
return "false"
end
Valid operators can be found in the Girder manual (PDF file in your Program Files directory).
etron
November 7th, 2008, 06:52 AM
Splitting a delimited string into a usable array (similar to explode() in PHP). Keep in mind that the array starts at 1, not 0 as in most other languages:
local strTest = "yellow|red|green"
local arrTest = string.Split(strTest, "|")
print(arrTest[1])
print(arrTest[2])
print(arrTest[3])
This would print:
yellow
red
green
Ron
November 7th, 2008, 08:41 AM
personal favorite function
table.print(arrTest)
will print the complete array in one go.
Solosid
January 8th, 2009, 05:50 PM
come on all,
keep 'em coming....
trying to learn Lua
every days a school day....
Mark
heinoskriver
January 24th, 2009, 12:36 PM
Hi
I'm also trying to learn...
When you use print ex. print(arrTest[1])
Where can you se the output? Could be usefull for debugging i think.
Rob H
January 25th, 2009, 06:06 AM
The output should appear in the Interactive Lua Scripting Console (see the view menu)
heinoskriver
January 25th, 2009, 06:21 AM
So it does. Thanks..
Powered by vBulletin® Version 4.2.0 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.