[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: How to overwrite a function that is late-loaded using loadfile()
- From: "Sam Roberts" <vieuxtech@...>
- Date: Fri, 28 Nov 2008 11:25:09 -0800
On Thu, Nov 27, 2008 at 9:11 PM, pan shizhu <firstname.lastname@example.org> 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
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.