lua-users home
lua-l archive

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


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.)

-Joseph