Page 1 of 1

Extend lua print()

Posted: Fri Oct 06, 2023 2:34 pm
by Gerkiz
Hello,

I currently have the following setup:
A Factorio server that prints out to stdout via lua print and a backend server that reads the stdout, processes it and delivers the result back to the server either via a silent-command or rcon.
But to spare all the connected players and the unneccessary messages via print that really shouldn't reach them, I was wondering if the lua print could be extended with a parameter that would allow one to specify to what client to send this message to.


This would allow me to print messages only to the servers stdout that the backend can parse and would stop the unneccessary messages to all the connected clients.
This can also be used for other scenarios where you intend to only print information to the servers console but wouldn't want to print it to all the connected clients.

Thank you in advance,
/Gerkiz

Re: extend LuaGameScript::print()

Posted: Fri Oct 06, 2023 2:37 pm
by Bilka
What's the reason why you don't use write_file?

Re: extend LuaGameScript::print()

Posted: Fri Oct 06, 2023 2:41 pm
by Gerkiz
Bilka wrote:
Fri Oct 06, 2023 2:37 pm
What's the reason why you don't use write_file?
The reason is simple, the requests are so fast-paced and are often many request and that would "wear/tear?" the disk, so I thought instead of doing that I could do it via print since print does not save to disk.

Re: extend LuaGameScript::print()

Posted: Fri Oct 06, 2023 5:43 pm
by atomizer
Gerkiz wrote:
Fri Oct 06, 2023 2:41 pm
Bilka wrote:
Fri Oct 06, 2023 2:37 pm
What's the reason why you don't use write_file?
The reason is simple, the requests are so fast-paced and are often many request and that would "wear/tear?" the disk, so I thought instead of doing that I could do it via print since print does not save to disk.
You could try using a named pipe to avoid writing a real file.

Re: extend LuaGameScript::print()

Posted: Tue Oct 10, 2023 11:45 am
by Gerkiz
atomizer wrote:
Fri Oct 06, 2023 5:43 pm
Gerkiz wrote:
Fri Oct 06, 2023 2:41 pm
Bilka wrote:
Fri Oct 06, 2023 2:37 pm
What's the reason why you don't use write_file?
The reason is simple, the requests are so fast-paced and are often many request and that would "wear/tear?" the disk, so I thought instead of doing that I could do it via print since print does not save to disk.
You could try using a named pipe to avoid writing a real file.
I'll probably do just this. Thank you!

Re: extend LuaGameScript::print()

Posted: Tue Oct 10, 2023 11:52 am
by Gerkiz
To fill in on this, apparently I've totally looked up the wrong print function. I apologize for the misleading information.

I've previously mentioned that I would like for the LuaGameScript::print to be extended. But it's not correct one that I initially thought about.

This is the print function that I would like to get extended.
https://lua-api.factorio.com/latest/aux ... A2-print()