I am not very good at parsing files but have something I would like to accomplish. The following is a snippet of a .lua script that has some require statements. I would like to use Python to parse this .lua file and pull the 'require' statements out.
For example, here are the require statements:
require "common.acme_1"
require "common.acme_2"
require "acme_3"
require "common.core.acme_4"
From the example above I would then like to split the directory from the required file. In the example 'require "common.acme_1"' the directory would be common and the required file would be acme_1. I would then just add the .lua extention to acme_1. I need this information so I can validate if the file exists on the file system (which I know how to do) and then against luac (compiler) to make sure it is a valid lua file (which I also know how to do).
I simply need help pulling these require statements out using Python and splitting the directory name from the filename.
requirefail if the file doesn't exist? Remember thatrequiresearches a variety of sources for a matching module, which may include a range of file system locations. The moduleacme_3might also be from a file namedacme_3/init.luawith the standard settings. And that ignores the issue of modules compiled in to the executable or dynamically loaded compiled modules which have similar rules. Or, the extensibility of the module system provided throughpackage.loaders. In short, duplicating the behavior ofrequireis not trivial. - RBerteig