Page 1 of 1

can spring lua write text to files?

Posted: 10 Mar 2010, 12:05
by knorke
...other than infolog.txt?
and other than stdout which i cant find in windows xp (how do i direct it into a file?)

Re: can spring lua write text to files?

Posted: 10 Mar 2010, 12:07
by Tobi
Yes, LuaUI (and LuaUI only) can write to arbitrary (text) files in the Spring directory.

You should be able to redirect stdout by doing on a console:

Code: Select all

spring.exe > mystdout.txt

Re: can spring lua write text to files?

Posted: 10 Mar 2010, 12:19
by knorke
thanks, stdout works now. but spring already writes stuff into it so thats not so great.

How would LuaUI writing to text files work?
Only thing I about lua and file acess is http://springrts.com/wiki/Lua_VFS and it seems about reading modfiles :?

Basically I am just looking for something like
file=openfile("bla.txt")
Spring.Writefile (file, "dumdidumdidum")

edit
ah think i found it

Re: can spring lua write text to files?

Posted: 10 Mar 2010, 12:24
by Beherith

Code: Select all

fd=	io.open(filename)
	if fd then 
		fileopened=true
	else 
		Echo("Opening " ..filename.. " failed")
		fileopened=false
	end

Re: can spring lua write text to files?

Posted: 10 Mar 2010, 12:38
by knorke
thanks Beherith, but I would have still needed the write command :wink:

Anyway, got it working this way:
file = io.open ("file.txt","w")
file:write("blabla")
file:close()
I had also found this in google:
k = openfile("bla.txt","r")
print(k)
which didnt work.

the "w" is needed, otherwise it says error trying to index lala

Re: can spring lua write text to files?

Posted: 10 Mar 2010, 20:23
by Argh
k = openfile("bla.txt","r")
print(k)
io.open can operate in read-only (IIRC, it does by default). See Lua Reference.