parser, all: use lua_tointeger when appropriate

Also some refactoring going on in the stats department.