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

Index out of range when I use require? #30

Closed muttgames closed 6 years ago

muttgames commented 6 years ago

This could be user error, but I'm having a hell of a time trying to get requires working.

Trying to build a file (main.lua) with a require is returning this:

Traceback (most recent call last): File "/Applications/picotool/p8tool", line 8, in <module> sys.exit(tool.main(sys.argv[1:])) File "/Applications/picotool/pico8/tool.py", line 592, in main return args.func(args) File "/Applications/picotool/pico8/build/build.py", line 258, in do_build lua_path=getattr(args, 'lua_path', None)) File "/Applications/picotool/pico8/build/build.py", line 155, in _evaluate_require reqd_lua.reparse(writer_cls=lua.LuaASTEchoWriter) File "/Applications/picotool/pico8/lua/lua.py", line 177, in reparse version=self.version) File "/Applications/picotool/pico8/lua/lua.py", line 131, in from_lines result.update_from_lines(lines) File "/Applications/picotool/pico8/lua/lua.py", line 140, in update_from_lines self._lexer.process_lines(lines) File "/Applications/picotool/pico8/lua/lexer.py", line 462, in process_lines for line in lines: File "/Applications/picotool/pico8/lua/lua.py", line 158, in to_lines for line in writer.to_lines(): File "/Applications/picotool/pico8/lua/lua.py", line 811, in to_lines for chunk in self.walk(): File "/Applications/picotool/pico8/lua/lua.py", line 246, in walk for t in self._walk(self._root): File "/Applications/picotool/pico8/lua/lua.py", line 798, in _walk for t in super()._walk(node): File "/Applications/picotool/pico8/lua/lua.py", line 227, in _walk for t in result: File "/Applications/picotool/pico8/lua/lua.py", line 403, in _walk_Chunk yield self._get_semis(node) File "/Applications/picotool/pico8/lua/lua.py", line 390, in _get_semis if self._tokens[self._pos].matches(lexer.TokSymbol(b';')): IndexError: list index out of range

Any help would be appreciated!

dansanderson commented 6 years ago

Hey heyparlor, sorry I didn't see this right away. The stack trace implies that this isn't specific to require() but is something specific to code separating statements with semicolons. Can you post a minimal example that exhibits this error? You might be able to put similar code in a cart and just run "p8tool listlua" on it to replicate. If necessary you can post the full code, or send it to me privately (contact@dansanderson.com). Thanks!

Arche-san commented 6 years ago

Hey ! Same problem here. I've run some tests and it seems this error happens when there is no new line at the end of the required file (which can be possible with some editors like vscode). I've joined a very small example to reproduce that : requireissue.zip Hope it can help you. :)

muttgames commented 6 years ago

Thanks for the help! I got away from pico for a little bit, but I'll dig in when I can and see if Arche-san's fix gets me sorted out.