lua_objlen returns the length of the object; it does not push anything on the stack.
Even if he pushed something on the stack, your lua_tointeger call uses the table index, not that lua_objlen would be pushed on the stack (if he pushed something, first of all, t).
Do you want size_t len = lua_objlen(L,1); for lua 5.1.
Or size_t len = lua_rawlen(L,1); for lua 5.2.
source share