Search code examples
luascriptingfilepath

How can I open a textfile, relative to an executed Lua file?


I'm in the Lua console of the Bizhawk emulator. I want to edit Ram of a GBA game.

I have a directory with a Lua file and another folder, that has a text file in it. I managed to read text from it by using the absolute path but I want to make it work with the relative path.

I tried to use arg[0] to get the path of the file but it's nil. And this outputs me 'ain': debug.getinfo(1,"S").source:sub(2)


Solution

  • Alright, this worked for me: print( io.popen('cd'):read('*a') )

    Thank you for your help!