GitXplorerGitXplorer
t

lua-presentation

public
6 stars
0 forks
0 issues

Commits

List of commits on branch master.
Unverified
5e769528ffd8b02b9e50d37016f7037c823e188d

Fix typo

ttrevrosen committed 8 years ago
Unverified
d971bd494b937987d88deb63e80011b48cadebb1

polish README

ttrevrosen committed 9 years ago
Unverified
ffa1fe278573f275cf838913569437fb59e5b384

Fix really dumb mistake

ttrevrosen committed 11 years ago
Unverified
431f078621d4c9b794f96429b8bad652258378af

Renamed a bunch of stuff for presentation

ttrevrosen committed 12 years ago
Unverified
177650334f38be720bd78c7cbdfe9552ded9ec3b

Lots of fix-ups

ttrevrosen committed 12 years ago
Unverified
bb219378e7edf29256c05997ccf21e847f0e31f6

Clean up kata a bit

ttrevrosen committed 12 years ago

README

The README file for this repository.

E a Lua - não a Ruby

"This is Lua - it's not Ruby"

At the November 2012 Austin.rb meeting, we introduce the Lua programming language from the point of view of a Rubyist. Lua is a language with many interesting applications, a fascinating history, and a lot of visibility in a wide array of uses from embedded scripting engines to cross-platform mobile game programming.

This repository contains heavily commented code examples for showing how to do various "getting started"-style things with Lua.

History

Lua was born (and is still officially maintained) at the Pontifícal Catholic University of Rio de Janeiro. The Tecgraf research group there was asked to help the state oil company, PETROBRAS, by creating a language that could be used for manipulating large data sets used in simulations.

PETROBRAS' status as a state-owned concern included many restrictions on the way the company could spend money, especially as it applied to importing computer technology. The language tools that PUC/Tecgraf was developing would need to run on any of the various kinds of hardware that the massive oil company had in use -- everything from Unix to Windows to MacOS to a host of embedded systems.

Among Tecgraf's first efforts was a specialized configuration langugage called SOL (Structured Object Language) which allowed for type definitions and other features of data description. By the time the Tecgraf team had completed an implementation, they realized they'd need something more robust - "a real programming language, with assignment, control structures, sub-routines, and the like" - that could be used for general purpose programming.

Because the language evolved from SOL ("Sol" means "Sun" in Portuguese), someone suggested that the new language could be called "Lua", which means "moon".

Lua has been in active use since its introduction in 1994.

Weird Stuff

Lua makes a lot of sense, but there are a number of gotchas you might want to check out. Among them are these:

  • A table is sort of like an array, sort of like a hash, and is Lua's only complex data type.
  • Indices for tables start at 1 instead of 0
  • All numbers are floating point
  • Functions can return multiple values
  • Regular stuff like socket IO is implemented in modules instead of Lua's stdlib in order to keep the core of the language as small as possible. Keep in mind that Ruby's stdlib is pretty big (xml parsers, web servers, templating, lots of protocols, etc), so we're kind of spoiled.
  • Patterns are NOT full-on (i.e. POSIX/PCRE) regex - even if they sort of look like they are
  • Table keys don't look like strings. They look like undeclared variables, but… they work :-)
  • Tables are Lua's only things resembling classic "objects" - inheritance and other standard OOP behaviors are implemented with them in a prototypal way reminiscent of Javascript

Interesting Uses

Lua is popping up all over the place. Its portability has always been a core feature, and that ability to be embedded in such a small footprint has made it the language of choice for multiple software projects' native scripting engines, as well as a higher-level language used to produce code in things like game frameworks. Here are a few of the places it's in use today:

Installing

We will need two things: the Lua interpreter and the LuaRocks package system (similar to RubyGems)

Installing on OSX

Use Homebrew:

Note: you need to update Homebrew to ensure that you catch a recent patch to make Lua 5.1.4 the default instead of the more bleeding edge 5.2. Lots of libraries aren't fully compatible w/ 5.2 yet, including ones we're using tonight.

$> brew update
$> brew install lua luarocks
$> luarocks install luasocket

Installing on (Ubuntu 12.04) Linux

$> sudo apt-get install lua5.1 luarocks
$> sudo luarocks install luasocket

Lua interactive

After you've installed Lua, you can get into the interactive shell like this:

$> lua
Lua 5.1.4  Copyright (C) 1994-2008 Lua.org, PUC-Rio
> print('hello, world!')
hello, world!
>

Exit the shell with Ctrl-D