MCPcopy Create free account
hub / github.com/TeXworks/texworks / execute

Method execute

plugins-src/TWLuaPlugin/LuaScript.cpp:42–75  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

40namespace Scripting {
41
42bool LuaScript::execute(ScriptAPIInterface * tw) const
43{
44 lua_State * L = m_LuaPlugin->getLuaState();
45
46 if (!L)
47 return false;
48
49 // register the TW interface for use in lua
50 if (!LuaScript::pushQObject(L, tw->self(), false)) {
51 tw->SetResult(tr("Could not register TW"));
52 return false;
53 }
54 lua_setglobal(L, "TW");
55
56 int status = luaL_loadfile(L, qPrintable(m_Filename));
57 if (status != 0) {
58 tw->SetResult(getLuaStackValue(L, -1, false).toString());
59 lua_pop(L, 1);
60 return false;
61 }
62
63 // call the script
64 status = lua_pcall(L, 0, LUA_MULTRET, 0);
65 if (status != 0) {
66 tw->SetResult(getLuaStackValue(L, -1, false).toString());
67 lua_pop(L, 1);
68 return false;
69 }
70
71 lua_pushnil(L);
72 lua_setglobal(L, "TW");
73
74 return true;
75}
76
77/*static*/
78int LuaScript::pushQObject(lua_State * L, QObject * obj, const bool throwError /* = true */)

Callers

nothing calls this directly

Calls 2

selfMethod · 0.45
SetResultMethod · 0.45

Tested by

no test coverage detected