dansanderson / picotool

Tools and Python libraries for manipulating Pico-8 game files. http://www.lexaloffle.com/pico-8.php
MIT License
367 stars 46 forks source link

p8tool listrawlua fails with AttributeError: 'list' object has no attribute 'split' #59

Closed hsandt closed 4 years ago

hsandt commented 5 years ago

Using p8tool listrawlua or a normal .p8 cartridge (that would work with listlua) will output:

Traceback (most recent call last): File "/usr/local/bin/p8tool", line 8, in sys.exit(tool.main(sys.argv[1:])) File "picotool-repo/pico8/tool.py", line 592, in main return args.func(args) File "picotool-repo/pico8/tool.py", line 195, in listrawlua lua_lines = raw_lua.split(b'\n') AttributeError: 'list' object has no attribute 'split'

from the source code of def listrawlua(args) in tool.py, raw_lua is defined as either:

data = game.Game.get_raw_data_from_p8png_file(fh, fname) raw_lua = data.code

data = game.Game.get_raw_data_from_p8_file(fh, fname) raw_lua = data.section_lines['lua']

I'm working with a .p8 so it must go through the second case, but data.section_lines seems to contain a list of lines, not a string. The seemingly obvious fix is to use the list of lines directly: lua_lines = raw_lua (or just use raw_lua, but name is less clear)

However, that adds a newline after every line in the output. To get rid of this, remove '\n' in those lines:

util.write('{}: {}\n'.format(i, _as_friendly_string(l)))
util.write(_as_friendly_string(l) + '\n')

However, that may break the .p8.png case! I haven't tested that yet. Maybe get_raw_data_from_p8_file needs to be adapted to remove the '\n', or get_raw_data_from_p8png_file to add them, it remains to be seen.

hsandt commented 4 years ago

Fixed by e8e2a8a75d3d0d138c3f68f00718f7b89a97b214