io.write不能在嵌套的if块和for循环中工作。

有人能解释一下为什么我删除了 io.write(inshort.."\n") 这一行时,io.write 不起作用吗?

没有第二个 io.output 的定义。 是代码嵌套太多了,在某些状态下 io.output 是无效的吗?

我知道 doSomething 被正确调用了...

function findpos(arg0, arg1,argf)

    io.input(arg0)
    io.output("that.txt")
    posicounter =0
    posibuffer=""
    if not arg0 then return 99 end
    counter = 1
    while true do
        local line = io.read("*line")
        if line == nil then break end
        for k, searchstring in ipairs(arg1) do
            found = string.find(line, searchstring)
            if found ~=nil then
                inshort = string.sub(line, found)
                io.write(inshort.."\n")
                if(inshort==posibuffer) then
                posicounter=posicounter+1
                elseif posicounter >0 then
                    io.write("before")
                    node = doSomething()
                    io.write("after")
                    posicounter=0
                else
                    posicounter=0
                    posibuffer=inshort
                end
            end
            argf(timestamp, string.sub(line, 24))
            counter = counter +1
        end
  end
点赞
用户33252
用户33252

注意,您正在删除的行是唯一输出 \n 字符的行。您看到的问题很可能是因为您的环境中的 i/o 系统(操作系统、终端或 shell)在看到 \n 字符之前延迟输出。即,输出是行缓冲的。

2013-09-24 16:48:20