-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathpico2lua.lua
More file actions
executable file
·47 lines (36 loc) · 830 Bytes
/
pico2lua.lua
File metadata and controls
executable file
·47 lines (36 loc) · 830 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/lua
if not arg[1] then
print("Usage:\tpico2lua.lua [FILE]")
print("Prints out the lua code in a file pico-8 format file to stdout.")
print("e.g.: ./pico2lua.lua cart.p8 > code.lua")
else
local file
if arg[1] == '-' then
file = io.stdin
else
file = io.open(arg[1])
end
local found_lua = false
local section_header = false
while true do
local line = file:read("*line")
if line == nil then break end
for section,_ in string.gmatch(line,"__(%a+)__") do
section_header = true
if section == "lua" then
found_lua = true
break
else
found_lua = false
break
end
end
if found_lua then
if section_header then
section_header = false
else
io.write(line.."\n")
end
end
end
end