fruits={"Banana","Orange"}print(fruits[1])-- Banana-- Removing elementsfruits[3]="Apple"table.remove(fruits)-- Appleprint(fruits[3])-- niltable.remove(fruits,1)-- Bananaprint(fruits[1])-- Orangeprint(#fruits)-- 1-- Inserting elementstable.insert(fruits,"Mango")table.insert(fruits,2,"Papaya")print(fruits[2])-- Papayaprint(#fruits)-- 3table.concat(fruits," and ")-- Orange and Papaya and Mangotable.sort(fruits)forkey,valueinipairs(fruits)doprint(key,value)end--[[
1 Mango
2 Orange
3 Papaya
]]
Files
Implicit
-- Writingfile=io.open("test.txt","w")io.output(file)io.write("This creates a file and writes this line at the top!")io.close(file)-- true-- Readingfile=io.open("test.txt","r")io.input(file)print(io.read())-- This creates a file and writes this line at the top!io.close(file)-- true-- Appendingfile=io.open("test.txt","a")io.output(file)io.write("Appending to the test file!")io.close(file)-- true
Explicit
-- Writingfile=io.open("test.txt","w")file:write("This creates a file and writes this line at the top!")file:close()-- true-- Readingfile=io.open("test.txt","r")file:read()-- This creates a file and writes this line at the top!file:close()-- true-- Appendingfile=io.open("test.txt","a")file:write("Appending to the test file!")file:close()-- true
Top comments (0)
Subscribe
For further actions, you may consider blocking this person and/or reporting abuse
Top comments (0)