Loading an entire file into a string?
-
- Posts: 1691
- Joined: Sun May 18, 2008 9:42 pm
Loading an entire file into a string?
I want to load the contents of an entire text file into an irr::core::stringc. I'm integrating LUA right now, and I want to be able to load scripts from inside of .zip files that have been added to the Irrlicht file system. So I need a way to load LUA scripts from Irrlicht.
That would be illogical captain...
My first full game:
http://www.kongregate.com/games/3DModel ... tor#tipjar
My first full game:
http://www.kongregate.com/games/3DModel ... tor#tipjar
-
- Posts: 1638
- Joined: Mon Apr 30, 2007 3:24 am
- Location: Montreal, CANADA
- Contact:
You could use this (taken from IRR RPG)
I'm using this to preload the script in the editor. Then newScript can be used with LUA.
Code: Select all
stringc newScript = "";
stringc filename = "../media/scripts/";
filename += scriptname;
std::string line;
ifstream fileScript (filename.c_str());
if (fileScript.is_open())
{
while (! fileScript.eof() )
{
getline (fileScript,line);
newScript += line.c_str();
newScript += '\n';
}
fileScript.close();
}
-
- Posts: 1691
- Joined: Sun May 18, 2008 9:42 pm
Yeah, but that uses std::ifstream, I need to use the Irrlicht file system so I can load from zip files.
That would be illogical captain...
My first full game:
http://www.kongregate.com/games/3DModel ... tor#tipjar
My first full game:
http://www.kongregate.com/games/3DModel ... tor#tipjar
Irrlicht already has a XML phaser. Simply create a script class extended from IAttributeExchangingObject, then write in the deserializeAttributes/ serializeAttributes functions. You can then add an out->addString ("Script", scriptChar);. or similar.
You can then ask the file stream to serialize / deserialize the Lua script.
It's important to not recode everything when you run into a problem.
You can then ask the file stream to serialize / deserialize the Lua script.
It's important to not recode everything when you run into a problem.