[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: catching Lua output
- From: Philipp Kraus <philipp.kraus@...>
- Date: Sun, 2 Dec 2012 22:11:44 +0100
Am 02.12.2012 um 21:59 schrieb Tangent 128:
> On 12/02/2012 03:18 PM, Philipp Kraus wrote:
>> Hello,
>>
>> how can I catch Lua print statements within my C code?
>> My Lua scripts run within a simulation on a different host and if the scripts runs a print statement I would like to catch the output and store it in a C variable for send the output back to the client.
>> I run a lua_call on the C code for running the Lua function.
>>
>> Thanks
>>
>> Phil
> You want to define your own print function, I think.
>
> After you've opened any standard libraries into the Lua state, set the
> global "print" value to your custom function.
>
> See lua_pushcfunction, lua_CFunction, and lua_setglobal in the docs.
>
> (This would not intercept write()s from the io library, but I am
> guessing that that isn't used by simulation actors.)
can I catch also the io.write calls? I will add also my own "simulation package"
with some different function, so I can add my own print call, but on usability I
would like to catch the out (if I can), because some user will use the io.write
and the output is lost, if there is no catching
Phil