viernes, 12 de junio de 2015

My first post on Lua

Lua is a programming language that always intrigued me but that I never spend time on trying to learn...

This has changed of course -;) As I have start reading Beginning Lua Programming...


So...what is Lua exactly? Well...it's is a powerful, fast, lightweight, embeddable scripting language.

A simple description for a simple language...and nope...I'm not implying simple as "useless" but rather as simple on its learning curve and its design...Lua is indeed pretty powerful and you will be more than surprised if you know where its being used...just search and get amazed -;)

The syntax pretty much reminds me of Python or Julia...so it's fairly easy to get used to it...

As an example...here is my Fibonacci numbers example...

Fibonacci.lua
function fib(num,a,b)
 local result = ""
 if a > 0 and num > 1 then
  result = result .. (a+b) .. " " .. fib(num-1,a+b,a)
 elseif a == 0 then
  result = a .. " " .. b .. " " .. (a+b) .. " " .. fib(num-1,a+b,b)
 end
 return result
end

io.write("Enter a number: ")
num = tonumber(io.read())
print(fib(num,0,1))


Here's a couple of tests -:)



Greetings,

Blag.
Development Culture.

No hay comentarios: