I have this piece of code: http://codepad.org/tLMkCXOq
Too bad I can't make it work properly in Lua 5.2+...