Is it efficient to use Lua to store game data ?

Is it efficient to use Lua to store game data ?
0.0 0


Hi guys,

I’m new to lua and I’m wondering, is it efficient to use lua to store game data (such as monster’s description, spells).

My problem is,
when I try to create a monster object every second, I have to run the lua file and get the data repeatedly,
which I think may be not efficient.

Before I try to use lua, I use XML to store data.
At the beginning of gameplay, I read the “monster.xml” file once, and keep it in the memory, and every time I need to create a monster, I just refer to it.
Is this XML approach more efficient than the lua one ? Or are there other better solutions?

Thanks !


I use XML and load data at the beginning of the game.

For example, I have a monster XML file and a MonsterData class that contains stuff regarding monsters.

class MonsterData {
   int _monsterID;
   const char * _monsterName;

   MonsterData( int pID, const char * pName ) {
      _monsterID = pID;
      _monsterName = pName;

   int getID() {
      return _monsterID;

   const char * getName() {
      return _monsterName; 

I retrieve data from XML then place the data into a MonsterData object which is then stored into a std::string object.

void GameData::loadMonsterData() {
   // Note: This is not tested but should give you the idea.

   // Read XML file using libXML
   XMLReader * xmlReader = XMLReader::create( "MonsterData.xml" );

   // Create new MonsterData object and place on a vector.
   MonsterData monsterData = MonsterData( xmlReader.getIntAt( 0 ), xmlReader.getConstCharAt( 1 ) );
   GameData::monsterDataVector.push_back( monsterData );

   // Destroy temporary objects.
   delete xmlReader;
   xmlReader = NULL;

Then I access them when I create a new Monster object through GameData::sharedDataManager -> getMonsterDataAt;