lua-users home
lua-l archive

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


On Thu, Nov 27, 2008 at 9:11 PM, pan shizhu <pan.shizhu@gmail.com> wrote:
> IMO There is no other way except require the module, since the file require
> the module and then call the module immediately. You cannot insert code in
> between the file without change the source. So you must require 'Utils'
> before run your file.

The above seems the simplest solution. I assume you don't like it
because if forces you to require"Utils" even if nobody ever uses it?

If that is a concern, replace the global require function with one
that calls the original, and them modifies the module
(if you wish) before returning it. This essentially allows you to
insert code in between the loaded codes require"Utils" and their use
of
Utils.Prompt().

You can also write your own loader function, and add it
package.loaders (perhaps name is wrong). There is a wiki page demoing
how to write your own package loader on the lua wiki.

Cheers,
Sam