can spring lua write text to files?

can spring lua write text to files?

Discuss Lua based Spring scripts (LuaUI widgets, mission scripts, gaia scripts, mod-rules scripts, scripted keybindings, etc...)

Moderator: Moderators

Post Reply
User avatar
knorke
Posts: 7971
Joined: 22 Feb 2006, 01:02

can spring lua write text to files?

Post 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?)
Tobi
Spring Developer
Posts: 4598
Joined: 01 Jun 2005, 11:36

Re: can spring lua write text to files?

Post 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
User avatar
knorke
Posts: 7971
Joined: 22 Feb 2006, 01:02

Re: can spring lua write text to files?

Post 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
User avatar
Beherith
Posts: 5145
Joined: 26 Oct 2007, 16:21

Re: can spring lua write text to files?

Post by Beherith »

Code: Select all

fd=	io.open(filename)
	if fd then 
		fileopened=true
	else 
		Echo("Opening " ..filename.. " failed")
		fileopened=false
	end
User avatar
knorke
Posts: 7971
Joined: 22 Feb 2006, 01:02

Re: can spring lua write text to files?

Post 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
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Re: can spring lua write text to files?

Post by Argh »

k = openfile("bla.txt","r")
print(k)
io.open can operate in read-only (IIRC, it does by default). See Lua Reference.
Post Reply

Return to “Lua Scripts”