[LUA] IO Functions

Afforess

The White Wizard
Joined
Jul 31, 2007
Messages
12,239
Location
Austin, Texas
Has anyone been able to successfully use any IO functions in Lua used by Civ5? I tried some simple code, like this

Code:
		SaveData = assert(io.open(text..".txt", "w"));
		SaveData:write("hello");
		SaveData:close();

But the FireTuner reports that there is a runtime error on the first line, that io is not a global value.

Either I am forgetting to include a standard library, or Civ5 has blocked io operations...
 
Has anyone been able to successfully use any IO functions in Lua used by Civ5? I tried some simple code, like this

Code:
		SaveData = assert(io.open(text..".txt", "w"));
		SaveData:write("hello");
		SaveData:close();

But the FireTuner reports that there is a runtime error on the first line, that io is not a global value.

Either I am forgetting to include a standard library, or Civ5 has blocked io operations...

obviously, Firaxis kicked it out. I guess it's due to safety consideration.
getfenv was kicked out too.
those functions or tables, such as _G, getfenv, io, only exist in Main State.
lua_state plays like a real sandbox. In python, it's quite hard to achieve it.
I always think Civ4's modding is not safe. A python mod can delete user's files secretly.
 
This is bad. Outputting to a log file is sometimes necessary when you've got lots of info that you need to check...
 
Firaxis seems to have blocked a bunch of Lua standard functions. I discovered, to my horror that string.concat doesn't work either. I had to write my own method for it.
 
I guess you meant table.concat.
Since there is no string.concat in lua.
I found table.contac is nil in Civ5 too.
I don't know why Firaxis blocked this function. This function seems harmless.
To concatenate strings, using ''.join(sequence) is better than in Python.
So I tried to use table.concat, and failed.
Maybe lua is different. ".." is better.
 
Yea, sorry, that's what I meant. I also learned the hard way that "table" is a terrible variable name in Lua...
 
string and type are also bad names.
But I found Firaxis used them as variable names.
Though it didn't bring problems.
Moreover, it seems some coder from Firaxis didn't understand lua's numeric for thoroughly.
I saw stupid code, for example:
Code:
local unitCount = plot:GetNumUnits();
for i = 0, unitCount - 1, 1
Code:
-- Loop through all units
local numUnits = plot:GetNumUnits();
for i = 0, numUnits do

Perhaps, they are c++ coder, python coder, but not lua coder.
 
This is bad. Outputting to a log file is sometimes necessary when you've got lots of info that you need to check...

You can use FireTuner as an output console, I believe I saw Kael mention this somewhere, I can't remember the exact command.
 
I wonder how FireTuner works for a mapscript. I mean, it's ment to work in WorldBuilder, or the game itself, but rather worldbuilder. So it must be run in parallel with the game or something. It requires connecting. Hell, it requires learning how to use it, and maybe it's not even able to provide me with what I want, namely a file output that I can then parse using appropriate tools.
The tools provided to us are not there to help, but to replace other tools we could use, which might happen to have been better. I really dislike it.
 
Top Bottom