lua file io


Questions, Explanations, Howtos

Halls Hopper

Posts: 57

Joined: Friday, 3rd January 2014, 22:52

Post Saturday, 13th December 2014, 19:24

lua file io

Hi,

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:
  Code:
local file = io.open("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?
That's a silly name!

Halls Hopper

Posts: 57

Joined: Friday, 3rd January 2014, 22:52

Post Friday, 19th December 2014, 20:31

Re: lua file io

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:
Image

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.

...at 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.
That's a silly name!

Return to Coding

Who is online

Users browsing this forum: No registered users and 1 guest

Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.