MCPcopy Create free account
hub / github.com/Serial-Studio/Serial-Studio / classifyTable

Method classifyTable

app/src/DataModel/Scripting/LuaScriptEngine.cpp:714–756  ·  view source on GitHub ↗

* @brief Dispatches the table at stack top to scalar/2D/mixed conversion paths. */

Source from the content-addressed store, hash-verified

712 * @brief Dispatches the table at stack top to scalar/2D/mixed conversion paths.
713 */
714QList<QStringList> DataModel::LuaScriptEngine::classifyTable(int len)
715{
716 QList<QStringList> results;
717
718 bool hasTable = false;
719 bool hasScalar = false;
720 for (int i = 1; i <= qMin(len, kMaxElements); ++i) {
721 lua_rawgeti(m_state, -1, i);
722 if (lua_istable(m_state, -1))
723 hasTable = true;
724 else
725 hasScalar = true;
726
727 lua_pop(m_state, 1);
728
729 if (hasTable && hasScalar)
730 break;
731 }
732
733 if (!hasTable) {
734 results.append(tableToStringList(-1));
735 lua_pop(m_state, 1);
736 return results;
737 }
738
739 if (hasTable && !hasScalar) {
740 results.reserve(len);
741 for (int i = 1; i <= qMin(len, kMaxElements); ++i) {
742 lua_rawgeti(m_state, -1, i);
743 if (lua_istable(m_state, -1))
744 results.append(tableToStringList(-1));
745 else [[unlikely]]
746 qWarning() << "[LuaScriptEngine] Row" << i << "is not a table, skipping";
747
748 lua_pop(m_state, 1);
749 }
750
751 lua_pop(m_state, 1);
752 return results;
753 }
754
755 return unzipMixedTable(len);
756}
757
758/**
759 * @brief Unzips a mixed scalar/vector table into a list of per-step frames.

Callers

nothing calls this directly

Calls 2

lua_rawgetiFunction · 0.85
appendMethod · 0.45

Tested by

no test coverage detected