tHE BRIGHT SIDE OF THE MOON
A Lua lang intro
(FOR RUBYSTS)
WHO AM I ?
Sebastián Moreno
R&D @ inConcert
@kernelp4nic

Lua is a powerful, fast, lightweight, embeddable scripting language.
Lua was created in 1993 by Roberto Ierusalimschy, Luiz Henrique de Figueiredo, and Waldemar Celes, members of the Computer Graphics Technology Group (Tecgraf) at the Pontifical Catholic University of Rio de Janeiro, in Brazil.
Why lua?
Why Lua is so special?
Lua is Robust
Lua is Portable & Embeddable
Lua is Fast
If you need more speed, try LuaJIT http://luajit.org/
Lua is Small as hell.
Source code and docs takes 246K compressed and 960K uncompressed. The source contains around 20000 lines of C.
That makes it perfect
to fit inside other projects
Russian power

NGINX + LUA
lua_package_path '/foo/bar/?.lua;/blah/?.lua;;';
lua_package_cpath '/bar/baz/?.so;/blah/blah/?.so;;';
server {
location / {
lua_need_request_body on;
client_max_body_size 100k;
client_body_buffer_size 100k;
access_by_lua '
-- check the client IP address is in our black list
if ngx.var.remote_addr == "132.5.72.3" then
ngx.exit(ngx.HTTP_FORBIDDEN)
end
-- check if the request body contains bad words
if ngx.var.request_body and
string.match(ngx.var.request_body, "fsck")
then
return ngx.redirect("/terms_of_use.html")
end
-- tests passed
';
# proxy_pass/fastcgi_pass/etc settings
}
}
REDIS 2.6

Redis - eVAL & EVALSHA & Script load
redis 127.0.0.1:6379> SCRIPT LOAD "return 'hello meetup'" => "cc834f607fb5249665c1f99c4daa71903768c575" redis 127.0.0.1:6379> EVALSHA cc834f607fb5249665c1f99c4daa71903768c575 0=> "hello meetup"
redis 127.0.0.1:6379> eval "return redis.call('set','foo','bar')" 0 OKredis 127.0.0.1:6379> keys * 1) "foo"redis 127.0.0.1:6379> eval "return redis.call('get','foo')" 0 "bar"
REDIS - Available libraries
-
base lib
- table lib
- string lib
- math lib
- debug lib
- cjson lib
- cmsgpack lib
World Of Warcraft
League of Legends
Minecraft
Every company may have a use for it!
Lua @ inConcert
- LuaNode (Async IO for Lua)
- redis-luanode (Redis client for LuaNode)
-
Route66 (simple URL routing for LuaNode)
- TwitterProxy (Written in LuaNode)
- LuaCassandra
- inConcert Web Handler (HTTP 1.1 server that runs Lua)
- JSON4Lua
- FeelingsDetector (Detects feelings inside text)
-
luaoauth (Oauth library)
- Nozzle (Write filters and chain them together into pipeline)
- Extensible Middleware Scripts (InteractionRouter)
- Every REST API around
A basic luanode example
local http = require('luanode.http')
http.createServer(function(self, request, response)
response:writeHead(200, {["Content-Type"] = "text/plain"})
response:finish("Hello Ruby Meetup!")
end):listen(8080)
console.log('Server running at http://127.0.0.1:8080/')
process:loop()

There is a debugger too, if you need it ;-)
Code me maybe?
You can apply Lua philosophy to your actual code.
You don't need to drop your current lang,you just need to find the perfect time to use a tool.
References
Further reading
- http://www.lua.org/pil/ (Programming in Lua - Second & Third Edition) (Book)
- http://queue.acm.org/detail.cfm?id=1983083 (Passing a Language through the Eye of a Needle) (Paper)
- Nginx HTTP Server (Book)
- https://github.com/karlseguin/the-little-redis-book (Book, Cap 5)
Thanks!
The Bright Side Of The Moon (rb)
By kernelp4nic
The Bright Side Of The Moon (rb)
A lua lang intro for rubysts
- 1,167