lua-users home
lua-l archive

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


For require:
require uses the functions from the _G.package.loaders array to search
for and load files. By default, in the array, is a loader which
searches package.preload, a loader which tries to load DLLs / shared
objects, and a loader which tries to load files (scan loadlib.c to
find out which order they are in, and what they do exactly). The
loader returns either the main chunk of the file, or nil.
Therefore, you can do one of a few things:
a) Add your own loader to the begginning or end of package.loaders
b) Replace the Lua loader in package.loaders with a new one
c) Replace package.loaders with an array containing *only* your new loader
d) Set a field in package.preload for every file you've precompiled
e) Attach an __index metamethod to package.preload to catch files
being require'd and return the compiled version

For dofile, loadfile, etc.:
After opening the standard libraries (luaopen_base, luaL_openlibs,
etc.), replace the global dofile, loadfile, etc. functions with your
own versions, which load/run the precompiled files.

2008/8/19 Tom Miles <Tom@creative-assembly.co.uk>:
> Hi Guys,
>
> I'm currently working on porting my project over so that it uses
> pre-compiled versions of the scripts we have written.  This is fine in
> principal for scripts that are explicitly loaded from my program as I
> can just redirect all calls to load to a compiled form of the script
> requested, however, what I can't do (easily) is check for uses of
> require and dofile in the script which will load the uncompiled scripts
> requested.  Bearing in mind I have done very little in the way of
> patching the main lua system we use can anyone give me any idea of what
> I will need to do to get lua to check for the existance of a compiled
> file when require and dofile are called?
>
> Thanks in advance,
>
> Tom
>
>
>
> ----------------------------------------------------------------------------
>         DISCLAIMER
> This email is sent by The Creative Assembly Limited company No. 03425917, registered in England &Wales registered office 27 Great West Road, Middlesex, TW8 9BW, England. The contents of this e-mail and any attachments are confidential to the intended recipient and may also be legally privileged. Unless you are the named addressee (or authorised to receive for the addressee) of this email you may not copy, disclose or distribute it to anyone else. If you have received this email in error, please notify us immediately by e-mail on postmaster@creative-assembly.co.uk and then delete the email and any copies. The Creative Assembly Limited have made all reasonable efforts to ensure that this e-mail and any attached documents or software are free from software viruses, but it is the recipient's responsibility to confirm this.
>
>