In C++, I have a vector of sol::table stored:
std::vector<sol::table> vecInstLuaTable;
At some point in my code, I want to assign one of these tables to a global table called "me" :
XEROOM::EXPOSED::SetScopeT(CURRENTROOMPTR->vecInstLuaTable[index]);
XELUASTATE::RunFunction(func);
XEROOM::EXPOSED::ResetScope();
void SetScopeT(const sol::table& t) {
vecStackScope.push_back(lua["me"]);
lua["me"] = t;
}
void ResetScope() {
lua["me"] = vecStackScope.back();
vecStackScope.pop_back();
}
The functions SetScopeT() and ResetScope() apparently take quite the amount of time. I understand that lua-C++ interop is not a free ride, but I have 2 questions about it:
Apparently in SetScopeT(), using a const sol::table& parameter instead of a sol::table improves performance by a lot. Why though? Isn't sol::table a masqueraded reference by itself? Same goes by using sol::protected_function& and sol::protected_function elsewhere.
Is the method described above efficient or am I doing something unbelievably stupid for such a simple task? If so, what's the best (fastest) way to achieve it?