How to bind std::map to Lua with LuaBind
- by MahanGM
Is this possible in lua to achieve?
player.scripts["movement"].properties["stat"] = "stand"
print (player.scripts["movement"].properties["stat"])
I've done getter method in c++ with this approach:
luabind::object FakeScript::getProp()
{
luabind::object obj = luabind::newtable(L);
for(auto i = this->properties.begin(); i != this->properties.end(); i++)
{
obj[i->first] = i->second;
}
return obj;
}
But I'm stuck with setter. The first line in lua code which I'm trying to set value "stand" for key "stat" is not going to work and it keep redirecting me to the getter method. Setter method only works when I drop ["stat"] from properties.
I can do something like this for setter in my script:
player.scripts["movement"].properties = {stat = "stand"}
But this isn't what I want because I have to go through my real keys in c++ to determine which key is placed in setter argument table value.
This is my map in class:
std::map<std::string, std::string> properties;