catching stderror & stdout

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

catching stderror & stdout

Pablo Saldo
How can I catch the outputs from stderror and stdout in Lua? I mean
redirecting them to a variable or such a thing.



  (o,o)  Pablo Saldo  -  [hidden email]
  {`"'}  FUNDACAO UNIVERSIDADE FEDERAL DO RIO GRANDE
  -"-"-  ENGENHARIA DE COMPUTACAO

Reply | Threaded
Open this post in threaded view
|

Re: catching stderror & stdout

Luiz Henrique de Figueiredo
>From [hidden email] Tue Jul 20 01:02:31 1999
>From: Pablo Saldo <[hidden email]>

>How can I catch the outputs from stderror and stdout in Lua? I mean
>redirecting them to a variable or such a thing.

You might redefine 'write' to save all output into a variable.
Something like

  OUT=""

  function write(...)
	  foreachi(arg, function (i,v) OUT=OUT..v end 
  end

Not the fastest code in the world, but it works.
For a faster solution, you could store in OUT a table of strings.
Otherwise, I guess you'd have to change liolib.c.
--lhf

Reply | Threaded
Open this post in threaded view
|

Re: catching stderror & stdout

Roberto Ierusalimschy
> You might redefine 'write' to save all output into a variable.

And for stderr, you redefine '_ALERT'.

-- Roberto

Reply | Threaded
Open this post in threaded view
|

Re: catching stderror & stdout

Pablo Saldo
>And for stderr, you redefine '_ALERT'.

Sorry, but I can't find references to _ALERT. 
Where is it in the code?

  (o,o)  Pablo Saldo  -  [hidden email]
  {`"'}  FUNDACAO UNIVERSIDADE FEDERAL DO RIO GRANDE
  -"-"-  ENGENHARIA DE COMPUTACAO

Reply | Threaded
Open this post in threaded view
|

Re: catching stderror & stdout

Luiz Henrique de Figueiredo
In reply to this post by Pablo Saldo
>From [hidden email] Wed Jul 21 01:05:20 1999
>From: Pablo Saldo <[hidden email]>

>Sorry, but I can't find references to _ALERT. 
>Where is it in the code?

_ALERT was introduced in 3.2.
See section 4.9 of the reference manual ("Error Handling").
The default implementation of _ALERT is in lbuiltin.c.
--lhf

Reply | Threaded
Open this post in threaded view
|

lua_cstack_reset?

Russell Y. Webb
In some application one knows for certain that the lua-C stack should be 
clear.  For instance, when lua only runs in response to and event of some 
sort you can clear the stacks before sending the event to lua.

I guess guess the best thing to do is actually manage the stack with 
lua_beginblock and lua_endblock statements, but is there anything wrong 
with using lua_cstack_reset in such cases?

in lua 3.1 something like this seemed to work:
void lua_reset(){
   // zero the cstack
   lua_state->Cstack.base=0;
   lua_state->Cstack.lua2C=0;
}