Category: GUITools

Lua

Lua is a scripting language that is very lightweight and at the same time powerful. Although it's not as widely known as Perl or Python, it's used as an extension language in many projects and commercial products, probably because of it's small footprint, simplicity and good performance.


Contents

[edit] Quick Tutorial

If you already have scripting/programming experience, it shouldn't take more than a couple of hours (or minutes) to be able to understand and write code in Lua. If you have lua installed, you can start the interpreter and type commands directly to execute them. From MySQL Workbench you can press Ctrl + F3, which will open a command interpreter for its internal scripting system, which supports Lua scripting.

[edit] A Simple Program

TODO: Add a simple program here.


[edit] Data Types

Main data types:

[edit] Control Structures

if <expr> then
  <stuff>
else
  <stuff> 
end
Ex.:
if (var > 50) and (flag ~= 0) then
  print("Something")
elif (var > 30) and (flag ~= 0) then
  print("Something else")
else
  print("Another something else")
end 
for <counter>=<start>,<end> do
  <stuff>
end
Ex.:
for i= 1, 10 do
  print("Hello")
  for j= i, 1, -1 do
    print("!")
  end
end
while <expr> do
  <stuff>
end
Ex.:
while i < 10 do
  i= i+1
  if some_condition == true then
    break
  end
end

[edit] Expressions and Operators

1+1
1+1 ~= 3
1 > 2
1 < 2
1 <= 2
2+2 == 4
true and false or not true
"Hello".." ".."World" --> will give "Hello World"

[edit] Functions

function foo(arg1, arg2, arg3)
  <stuff>
  return result
end

[edit] Some Handy Functions

print("Hello World")
string.sub("Hello World", 7, 9)  --> will give 'Wor'

table.getn({32,4321,32,56}) --> 4 (number of elements in table)
table.insert({3,5,6}, 2, 4) --> {3,4,5,6}

[edit] References

Retrieved from "http://forge.mysql.com/wiki/Lua"

This page has been accessed 14,806 times. This page was last modified 12:05, 22 July 2008.

Find

Browse
MySQLForge
Main Page
Current events
Recent changes
Random page
Help
Edit
Edit this page
Editing help
This page
Discuss this page
Post a comment
Printable version
Context
Page history
What links here
Related changes
My pages
Special pages
New pages
File list
Statistics
Bug reports
More...