Discovering murgaLua

From Murga-Projects Wiki

Jump to: navigation, search

Crash course in LUA

Lua is a lean programming language that combines simple procedural syntax with powerful constructs for handling data and extensible semantics. It is also dynamically typed, which releases you from the burden of declaring variables, and has advanced features like automatic memory management and garbage collection to make sure your programs still run well.

Another neat thing about Lua is that it provides meta-mechanisms for implementing features instead of bloating itself with too many features to remember. For example, Lua is not a object-oriented language, but it provided mechanisms for implementing classes and inheritance if its a feature that is important to you.

Tables deserve special mention, as they really are the foundation for data storage in Lua. You can write pseudo-classes with them, they can be arrays, they are FAST, they can be pretty much whatever you want and the syntax to manipulate them is pretty cool.

Anyway, an in-depth discussion on the syntax and usage of Lua is out of the scope of this document ... And people have explained it better than I could have. Have a look at the following links :

A nice overview from the always great Wikipedia :
http://en.wikipedia.org/wiki/Lua_programming_language

A cool tutorial from the DeveloperWorks web-site :
http://www-128.ibm.com/developerworks/library/l-lua.html?ca=drs-

An overview to the language by the people who created Lua :
http://www.lua.org/spe.html

The official manual :
http://www.lua.org/manual/5.1/
This is an online version of the first edition of the "Programming in Lua" book :
http://www.lua.org/pil/ (Or buy the new edition - http://www.inf.puc-rio.br/~roberto/pil2/)

Tables deserve a few tutorials of their own :
http://lua-users.org/wiki/TablesTutorial
http://www.gammon.com.au/forum/bbshowpost.php?bbsubject_id=6036

Your first program

I guess your first program would have to be the ubiquitous "Hello World".

If you think it kinda sucks you may want to skip to the next tutorial :-)

If not, so open up a file in the directory you extracted this archive to (normally named "murgaLua").

And type the following :

fltk.fl_message("Hello Word")
print("Hello World")


Save the file as "helloWorld.lua", and then run at the prompt :

bin/murgaLua helloWorld.lua


REMEMBER - If you are running in Windows the slash ("/") goes the other way, so do "bin\murgaLua".

Anyway, you'll see a nice FLTK message box with "Hello World", and the same on the standard Lua console output.

Linux users may want to copy "murgaLua" to "/usr/bin", and put the following as the first line of the program :
#!/usr/bin/murgaLua


Not you can make the script executable (chmod), and run it like a standard Linux utility.

Personal tools