Reimplement iterators using FFI

This patch replaces Lua/C bindings to iterator by FFI.
Optimize index functions for FFI iterator