So far Lua is strikingly similar to ruby. This of course only appears to be the case for very simple scripts.
Some common things so far:
- Condition expressions accepts any value, and false / nil are the only things which are failures. 0 and "" are both true.
- The concept of a
Nilclass which only has nil as a value. - The use of
endto denote closing blocks for if, for, function definitions, etc. - The general way in which a program feels.
Lua Fibonacci:
Ruby Fibonacci:
The differences?
- Lua statements can't be taken as returning a value, hence in the fibonacci example we need to explicitly use
return. - Lua has a boolean type, unlike in ruby, which has a FalseClass and a TrueClass.
- Lua only has only double precision floating point numbers to represent any number. Ruby has Fixnum, Bignum, Float.
- Lua takes the more
functionalapproach for converting between types, e.g.tonumber,tostringinstead of Ruby, which has a to_i, to_s method for numeric and string types. - Lua requires parenthesis when calling functions. I guess Ruby is very unique in this regard.
- Accessing any variable, even undefined ones, are legal, and always returns nil. This also applies to
tables, i.e. accessing an undefined key returnsnil. - Lua has a somewhat weird looking concatenation operator
... Ruby just uses+for concatenating strings. - Tables (which are kinda like Arrays and Hashes in one) use a 1-based index.