lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Let me start by apologizing if this question has already been asked answered. I searched the forum and found no satisfactory answer. I am very new to LUA so please keep replys as simple as possible :).

What I want to do is create a config file in LUA that contains values that I then read into member variables of a c++ class. For example:

Enemy =
{
  Name = Monster,
  Hitpoints = 100
}

The way I would like this to work is something like:

lua_getglobal(pLuaState, "Enemy.Hitpoints");

if (lua_isnumber(pLuaState, -1))
{
  m_iHitpoints = (int)lua_tointeger(pLuaState, -1);
}

This doesn't work since it's a table. What annoyes me is that both gettable and getfield takes an index when I want to use the keys for readability.

Is there no easy way to do this? Something like lua_getfield(pLuaState, Enemy, Hitpoints); would be really nice. And what about tables in tables?

_________________________________________________________________
FREE pop-up blocking with the new MSN Toolbar - get it now! http://toolbar.msn.click-url.com/go/onm00200415ave/direct/01/