The "key" is not the command string. Look at the code in TRoom, which is called from TLuaInterpretter via pHost->mpMap->rooms[id_from]->addSpecialExit( id_to, _dir ). TRoom checks if the room to id exists, and if so, it overwrites the value with other.replace(to,_cmd). I was wrong about our data structure, as it's actually a QMultiMap in the first place, but regardless, that part of the loop with insertMulti is never reached if a room exit is already defined. It has nothing to do with my getSpecialExit() function change, I reverted that and the problem results with getSpecialExitSwap() as well. This isn't a lua problem, it's a c++ problem.
Here's the relevant except from the docs:
QMap<Key, T>::iterator QMultiMap::replace ( const Key & key, const T & value )
Inserts a new item with the key key and a value of value.
If there is already an item with the key key, that item's value is replaced with value.
If there are multiple items with the key key, the most recently inserted item's value is replaced with value.
The code should be a variant of this:
while...
if (it.value() == _cmd)
other.replace( to, _cmd );
else
other.insertMulti( to, _cmd );
return;
My other posting above meant that in almost every case, special exits will be unique, but they don't have to be.