A sequential and reverse file reading method for Lua _lua

Source: Internet
Author: User
--table feature-
-use table to generate positive and descending lists-

-use table to generate list

= Nil local
file = Io.open ("Table.lua", "R")--> Open

The pre = nil
--read this file in the list in row order in
File:lines () does current  
	= {next = Nil,value = line}
	pre = Pre or current
	list = list or pre
	Pre.next = current
	pre = current
end

File:close ()--Close file 
  --Output list
L = list while
l do
	print (l.value)
	L = L.next End

--The following is a method
of descending in line Print ("Below is in-line reverse output file: \ n") local
file = Io.open ("Table.lua", "R")--> open

the book list = nil--To empty the contents of the list for

Line in File:lines () does
	list = {next = List,value = line}
end

file:close ()--Close file
--output list
Loca L = List while
l doing
	print (l.value)
	L = L.next
End

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.