Loops io.write won';t在嵌套的if块和for循环中工作
有人能解释一下为什么我删除该行时io.write不工作吗 io.write(短..“\n”) io.output没有第二个定义。 代码是否嵌套过多,并且io.output在某些状态下无效 我知道有些东西叫对了Loops io.write won';t在嵌套的if块和for循环中工作,loops,lua,nested,output,Loops,Lua,Nested,Output,有人能解释一下为什么我删除该行时io.write不工作吗 io.write(短..“\n”) io.output没有第二个定义。 代码是否嵌套过多,并且io.output在某些状态下无效 我知道有些东西叫对了 function findpos(arg0, arg1,argf) io.input(arg0) io.output("that.txt") posicounter =0 posibuffer="" if not arg0 then return
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
请注意,要删除的行是唯一输出
\n
字符的行。您看到的问题很可能是环境中的i/o系统(操作系统、终端或外壳)正在延迟输出,直到它看到\n
字符。也就是说,输出是行缓冲的。这里的“不工作”是什么意思?另外,请您正确缩进代码。这是哪个Lua版本?您确定io.input(arg0)
成功吗?能否提供doSomething()
的来源?或者它不适用于泛型函数?一些小提示:1。考虑使用<代码> IO。写入(简写为“\n”)< /代码>,而不是隐式CONTAT。2.你会考虑使用单独的文件句柄而不是包装到一些阴暗的LUA内部逻辑吗?我会尝试在这些笔记上,谢谢,这正是问题的一个旁注,你可以改变输出缓冲与<代码>文件:StvvBuf(模式[大小])< /代码>