41 lines
769 B
Lua
41 lines
769 B
Lua
function file_lines_to_table(filename)
|
|
local file = {}
|
|
for line in io.lines(filename) do
|
|
table.insert(file, line)
|
|
end
|
|
return file
|
|
end
|
|
|
|
function file_characters_to_table(filename)
|
|
local file = {}
|
|
for line in io.lines(filename) do
|
|
local lineelements = {}
|
|
for I = 1, string.len(line) do
|
|
c = string.sub(line, I, I)
|
|
table.insert(lineelements, c)
|
|
end
|
|
table.insert(file, lineelements)
|
|
end
|
|
return file
|
|
end
|
|
|
|
function tablelength(T)
|
|
local count = 0
|
|
for _ in pairs(T) do
|
|
count = count + 1
|
|
end
|
|
return count
|
|
end
|
|
|
|
function print_table(t, indent)
|
|
indent = indent or ""
|
|
for k, v in pairs(t) do
|
|
if type(v) == "table" then
|
|
print(indent .. k .. ":")
|
|
print_table(v, indent .. " ")
|
|
else
|
|
print(indent .. k .. ": " .. tostring(v))
|
|
end
|
|
end
|
|
end
|