lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Hi,
sorry, the whole thread was a bit "tl;dr" for me as of now, but on a
chance that I might be helpful, here comes a link to a small script:
  https://github.com/akavel/scissors/blob/1ee510dea70b796635a50e88a6488ad154bed89b/tools/bundle/scan_dependencies.lua

The script does dumb simple text scan, searching for all `require
"foobar"` occurences (note: not 'dofile') with vanilla `gmatch()`
[see: findDependencies.lua], then iterates over `package.path` trying
to find an existing file [see: findPackage.lua], then repeats
recursively.
May or may not be of any use to you. For my needs, this works
perfectly as of now.

Quick notes:
- "scan_dependencies.lua" is a simple command-line script wrapping
`findDependencies` (and contains some "usage" message);
- doesn't parse Lua, and won't skip Lua comments - this also means it
can be fooled by malformed strings in comments;
- not protected against dependency cycles;
- won't catch `require(fname)` where fname is a dynamically generated string;
- side note: "bundle.lua" wraps all the above, glueing a script with
all its dependencies into a single blob script file. Sure, this all is
probably very similar to srlua
(http://www.tecgraf.puc-rio.br/~lhf/ftp/lua/#srlua) by LHF.
Reinventing the wheel? I "scratched my itch" and felt happier, sue me
;) (on second thoughts, maybe better don't.)

greetings
Mateusz Czapliński

On Sat, May 14, 2011 at 4:25 PM, marbux <marbux@gmail.com> wrote:
> Hi, all,
>
> Before risking possible reinvention of the wheel, I ask whether anyone
> knows of an existing snippet to return a list of file paths for all
> files executed by a script and its chunk files using dofile? This is
> for an app that embeds standard Lua, no add-on libraries.
>
> Problem Context:
>
> My use case is actually slightly different but closely analogous so if
> code already exists as described above, it should be easy to modify to
> my purpose. The app is an outliner. We've supported external Lua
> scripts in text files for some time, but are now getting our feet wet
> with support for embedded scripts.
>
> We've developed a program API that is a counterpart to Lua's dofile,
> which you might think of as "do-node", where the API executes the code
> embedded in an outline node identifiable by a 22-character UID. That
> UID in an embedded script running on our app corresponds to the path
> of a Lua chunk file executed using dofile.
>
> I have been tasked with developing utility scripts to aid users who
> work with embedded scripts. Embedded scripting of the outliner is
> going great, exceeding our original hopes. (We've had to create only
> three new APIs so far for the purpose.) In relevant regard, one huge
> advantage for our embedded scripts has been that we can stack a very
> large number (limited only by practicality and system resources) of
> scripts in a single document and break them down into very granular
> modules/chunks stored in separate nodes for code recycling purposes
> (and execute them via, inter alia, an abbreviation expansion trigger,
> with the abbreviation derived from the node title.)
>
> One big advantage is that a script can call only the modules needed;
> we need not create and use a library file of multiple functions most
> of which will not be needed for a particular script's execution. Only
> the functions needed for the particular script are called by
> "do-node".
>
> But with greater granularity comes a dramatic increase in the number
> of code modules summoned with "do-node" by a given script and its
> submodules/chunks.
>
> The Problem:
>
> Which brings me to the problem I need to solve in an automated
> fashion, export and import of all node modules executed by a given
> script to embed the script and all of its submodules/nodes in a
> different document. In other words, I need to remove a script-sharing
> barrier.
>
> This Missive's Goals:
>
> Thus far, either I have not been smart enough to frame a web search
> query to pop a Lua snippet that returns a list of files executed by
> dofile, or there isn't one out there. So I ask whether: [i] anyone
> knows of one; and if not [ii] anyone can suggest search terms that
> might aid in my search; or [iii] anyone has a suggestion on a method
> to create create such a snippet?
>
> Thanks in advance,
>
>  Paul E. "Marbux" Merrell
>
> ---
> NoteCase Pro
> The Massively Multi-Platform Outliner
> <http://notecasepro.com/>
>
>