lua-users home
lua-l archive

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


On Wed, Jul 13, 2011 at 8:22 PM, HyperHacker <hyperhacker@gmail.com> wrote:
> On Wed, Jul 13, 2011 at 16:42, Patrick Donnelly <batrick@batbytes.com> wrote:
>> Use debug.getinfo to see if your replacement print function is being called
>> from the first function on the call stack (the interpreter). It would look
>> like:
>>
>> if debug.getinfo(3) == nil then
>>   -- interpreter
>> else
>>   -- normal
>> end
>
> You might also play with the LUA_INIT environment variable. This is
> used by both the interpreter and the interactive prompt, but from
> there you can do things like define your own prettyprint() in a
> startup script, and just do print=prettyprint whenever you start the
> prompt. There are also command-line options you can use to similar
> effect.

Um, you just described what the OP is already doing. He wants his
print replacement function to distinguish between the interpreter
calling print and a script calling print. My response gave him a
solution...

-- 
- Patrick Donnelly