[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: How to overwrite a function that is late-loaded using loadfile()
- From: "pan shizhu" <pan.shizhu@...>
- Date: Fri, 28 Nov 2008 13:11:31 +0800
On Fri, Nov 28, 2008 at 12:55 PM, RJP Computing <email@example.com>
But here comes the part that I need help with. If the loaded file uses require() to use a module that I wrote that has a function called Prompt(). The modules name is Utils. All it does is display a message and then read from the console for the response from the user and return the users input. So I want to overwite this function to GUIify it. But I don't want this application to rely on this module that I wrote. So I want to just overwrite it like I did with print().
But making a table named 'Utils' and then adding a function in that namespace called Prompt() doesn't seem to do the trick. How can I make this work in the GUI without needing to rely on the actual module?
Hope this helps explain the problem a bit.
Where is the module 'Utils' ? if that is a module you can control, just change the source code.
Otherwise, you can simply require 'Utils' before load the file and then overwrite the function. After your overwrite you can load and run the file with your own version of Prompt.
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.
Pan, Shi Zhu