Ok so, this is more a sanity check than anything else.
Lets asume we have a struct called lua_State, now I need to create a uncertain amount of unique lua_State\'s.
Use a std::vector
to both store the created states and generate sequential identifiers (i.e. array indices). Unless I'm missing something, then you are grossly over-complicating your requirements.
std::vector<lua_State *> stateList;
// create a new Lua state and return it's ID number
int newLuaState()
{
stateList.push_back(luaL_newstate());
return stateList.size() - 1;
}
// retrieve a Lua state by its ID number
lua_State * getLuaState(int id)
{
assert(0 <= id && stateList.size() > id);
return stateList[id];
}
Why do you need a variable name for every index? Why is it not good enough to refer to, for example, luaMap[0]
and luaMap[1]
? I don't think there's really any way to do what you want. You need some sort of dynamic array, like a std::vector.
GiNaC does this, but the name has to be explicitly given to a variable
Can't you use std::map<std::string, lua_State*>
and use the script name as an index to the state?