Lua 确定何时超出范围

我有一个名为preprocess的函数,它长这样:

  function image_utils.preprocess(meanfile, oneD_image_table)
      local img_mean = torch.load(meanfile).img_mean:transpose(3,1)
      return function()
           for t_class, img_path in pairs(oneD_image_table) do
              local im3 = image.load(img_path)
              local im4 = image.scale(im3,227,227,'bilinear')*25
              return im4 - image.scale(img_mean, 227, 227, 'bilinear')

      end
end

这是我如何调用它的:

 im_f = image_util.preprocess(meanfile, path_list)
 repeat
    im=im_f()
    batch[count]:copy(im)
    count = count + 1

 until count == batchSize

这个很有效。然而,我想检测当im_f没有任何迭代剩余时,并使用它来确定我何时停止循环。换句话说,像这样做:

  repeat
    im = im_f()
    count = count+1
    batch[count] = im
  until im == nil (或im是告诉我停止的一些标记值)

然而,我由于超出范围错误而无法使它工作。

简而言之,我想一直循环,直到im_f告诉我停止;而不是使用预定的数字告诉我何时停止。

点赞