Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local tArgs = {...}
- if #tArgs ~= 1 then
- print("Usage: gkbuilder <filename>")
- return
- end
- function parse_gkbuild(filename)
- f = fs.open(filename, "r")
- current = f.read()
- --Leaves on the last digit which isn't a number
- function parse_num()
- local num_str = ""
- while tonumber(current) do
- num_str = num_str..current
- current = f.read()
- end
- return tonumber(num_str)
- end
- layers_total = parse_num()
- if layers_total == nil then
- print("The formatting of the file is incorrect! Did you forget the first number is the total number of layers?")
- end
- print(layers_total)
- map = {}
- for i=1, layers_total do
- layer = {}
- while current ~= ';' do
- current = f.read()
- table.insert(layer, parse_num())
- end
- layer_str = ""
- for j=1, #layer do
- layer_str = layer_str..tostring(layer[j])..","
- end
- print(layer_str)
- table.insert(map, layer)
- end
- print(#map)
- map_str = ""
- for i=1, #map do
- layer_str = ""
- for j=1, #map[i] do
- layer_str = layer_str..tostring(map[i][j])..","
- end
- layer_str = layer_str.."\n"
- print(layer_str)
- end
- return map
- end
- print(parse_gkbuild(tArgs[1]))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement