#!/usr/bin/env lua local function read_level(id) local file = io.open(id..".jtmm2") if not file then return nil else local content = {width = nil, height = nil, tiles = {}} local line_nb = 0 for line in file:lines() do line_nb = line_nb + 1 if line_nb < 3 then if content.width then content.height = tonumber(line) else content.width = tonumber(line) end else table.insert(content.tiles, line) end end file:close() return content end end local function create_structure_c(id) local content = read_level(id) if content then -- tiles io.write("const unsigned char tiles_", id, "[] = {") for i, v in ipairs(content.tiles) do io.write(v, ", ") end io.write("};\n"); -- structure io.write("const Level level_", id, " = {\n") io.write("\t.width = ", content.width, ",\n") io.write("\t.height = ", content.height, ",\n") io.write("\t.tiles = &tiles_", id, "\n") io.write("};\n") end end create_structure_c(0)