2016-11-27 4 views
1

파일의 모든 줄을 표 안에 저장해야하지만 특정 지점에서 읽기 시작해야합니다.특정 줄에서 파일 읽기 시작

class Foo as 
attribute max : number 
def static show as 
count : number 
begin 
io.print(count) 
return count 
end 
attribute min : number 
end 
program 
var x : number 
var foo : Foo 
x = 20 
foo = new Foo 
foo.show(x) 
end 

내가 프로그램에서 읽기 시작하고 테이블에 프로그램 아래에 모든 것을 저장해야 다음은 파일의 예입니다.

for line in io.lines(file) do 
    table.insert(program.body, line); 
end; 

그러나 이것은 (물론) 전체 파일을 통해 루프 :

내가 이런 짓을했는지. 프로그램에서 까지 루프해야합니다.

답변

0
local inside 
for line in io.lines(file) do 
    inside = inside or line:match"^program" 
    table.insert(program.body, inside and line); 
end; 
+0

"내부"변수에서 어떤 일이 발생했는지 설명해 주시겠습니까? 감사. :) –

+0

'inside'는 "program"으로 시작하는 줄 앞에서'nil'이고 그 줄 다음에는'nil'이 아닙니다. [ "and"in Lua] (https://www.lua.org/pil/3.3.html) –