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

Method createState

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

* @brief Creates a fresh Lua state with safe libraries and watchdog hook. */

Source from the content-addressed store, hash-verified

148 * @brief Creates a fresh Lua state with safe libraries and watchdog hook.
149 */
150void DataModel::LuaScriptEngine::createState()
151{
152 Q_ASSERT(m_state == nullptr);
153
154 m_state = luaL_newstate();
155 Q_ASSERT(m_state != nullptr);
156
157 lua_atpanic(m_state, luaPanicHandler);
158
159 openSafeLibs(m_state);
160
161 DataModel::installLuaConsole(m_state);
162
163 DataModel::installLuaCompat(m_state);
164
165 DataModel::NotificationCenter::installScriptApi(m_state);
166
167 DataModel::FrameBuilder::instance().injectTableApiLua(m_state);
168
169 DataModel::DeviceWriteApi::installLua(m_state, m_sourceId);
170
171 DataModel::ActionFireApi::installLua(m_state);
172
173 DataModel::DashboardApi::installLua(m_state);
174
175 DataModel::ScriptApiCall::installLua(m_state, m_sourceId);
176
177 lua_pushlightuserdata(m_state, this);
178 lua_setfield(m_state, LUA_REGISTRYINDEX, "__ss_engine__");
179
180 lua_sethook(m_state, watchdogHook, LUA_MASKCOUNT, kHookInstructionCount);
181
182 m_deadline = QDeadlineTimer(QDeadlineTimer::Forever);
183 m_loaded = false;
184 m_disabled = false;
185 m_parseRef = LUA_NOREF;
186 m_consecutiveTimeouts = 0;
187}
188
189/**
190 * @brief Closes the Lua state and resets internal flags.

Callers

nothing calls this directly

Calls 6

luaL_newstateFunction · 0.85
lua_pushlightuserdataFunction · 0.85
lua_setfieldFunction · 0.85
lua_sethookFunction · 0.85
injectTableApiLuaMethod · 0.80
openSafeLibsFunction · 0.70

Tested by

no test coverage detected