lua-users home
lua-l archive

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

On Thu, Nov 27, 2008 at 2:57 PM, Sam Roberts <> wrote:
I didn't understand the original question, maybe you can clarify what
it is you are trying to do?

You are requiring something, and then want to replace one of the
functions in that module?

Just calling loadfile() alone doesn't actually run any lua code, it
just compiles a chunk, and returns an anonymous function, so there
isn't anything to override....

What are you trying to do?

OK I will try to explain. I am writing a Lua application that uses wxLua. In this GUI I want to make it simply run console *.lua files. So I just have the GUI application ask for the file to run. In the GUI app I use loadfile() to compile the Lua into a chunk and save it. Then when the user clicks a button I run the Lua chunk. Now to get the feedback that used to go to the console useing print() I overwrite the print function in the GUI code. The GUI print() function displays the running Lua chunks print() in a text control as a log. This all works great.

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.