Page 1 of 1

lua file io

PostPosted: Saturday, 13th December 2014, 19:24
by Slap and stab

As my lua magic gets more complex, the need of some logging tool rises. I don't want to use crawl.mpr as it gets quite spammy, so my next option are files.
I tried to use lua's standard approach, but io is null:
local file ="party.log", "a")

Then I found a strange file.write method in crawl's sources, and it sounds like just what I need, but it requires a file handle as a parameter, and I don't really have that.

How can I append a string to a file in crawl's lua?

Re: lua file io

PostPosted: Friday, 19th December 2014, 20:31
by Slap and stab
I found "a" way, but it's the most ugliest thing in the world... and it does not actually work... will keep researching, bun not too optimistic
Windows only
1) run crawl from cmd: crawl > crawl.log
2) call print "Hello, World" from lua
Observe that the string appeared in the console window, whereas the log file stays 0 bytes:

I'm a bit puzzled. Even if I try to redirect cmd's output to a file, no luck. It just does not redirect crawl's printed messages. least, printing to a separate window is a tad better that printing directly to crawl.mpr. Maybe I'll find a way to read from that window from a c++ program and then parse it, but I'd rather find a better way.