From 51122d8689f6fbb1061ee0b19f885ad8851dfd50 Mon Sep 17 00:00:00 2001 From: deva Date: Fri, 13 Aug 2010 10:07:22 +0000 Subject: Clear lua when reopening a macro window. --- client/lua.cc | 18 +++++++++++++----- client/lua.h | 2 ++ client/macrowindow.cc | 22 +++++----------------- client/macrowindow.h | 2 -- 4 files changed, 20 insertions(+), 24 deletions(-) diff --git a/client/lua.cc b/client/lua.cc index 7dbdf75..3dd5381 100644 --- a/client/lua.cc +++ b/client/lua.cc @@ -75,6 +75,19 @@ LUA::LUA(Widget **rootwidget) { this->rootwidget = rootwidget; + L = NULL; + clear(); +} + +LUA::~LUA() +{ + lua_close(L); +} + +void LUA::clear() +{ + if(L) lua_close(L); + L = luaL_newstate(); if(L == NULL) { error("Could not create LUA state."); @@ -91,11 +104,6 @@ LUA::LUA(Widget **rootwidget) register_widget(L); } -LUA::~LUA() -{ - lua_close(L); -} - QString LUA::runParser(QString program) { if(L == NULL) { diff --git a/client/lua.h b/client/lua.h index d10aeb2..d94bd15 100644 --- a/client/lua.h +++ b/client/lua.h @@ -47,6 +47,8 @@ public: Widget *getWidget(QString name); + void clear(); + private: lua_State *L; Widget **rootwidget; diff --git a/client/macrowindow.cc b/client/macrowindow.cc index 649f323..5a6760e 100644 --- a/client/macrowindow.cc +++ b/client/macrowindow.cc @@ -47,7 +47,7 @@ MacroWindow::MacroWindow(NetCom &n, QDomNode &xml_doc, QString templ, : Collapser(), netcom(n) { mainwidget = NULL; - this->lua = new LUA(&mainwidget); + lua = new LUA(&mainwidget); waschanged = false; @@ -65,7 +65,6 @@ MacroWindow::MacroWindow(NetCom &n, QDomNode &xml_doc, QString templ, MacroWindow::~MacroWindow() { clear(); - delete lua; } void MacroWindow::update(QDomNode &node) @@ -101,7 +100,7 @@ void MacroWindow::initMacro(QDomNode &node) } else if(xml_elem.tagName() == "script") { if(xml_elem.attribute("language", "lua") == "lua") { - this->lua->runScript(xml_elem.text(), NULL, "preload"); + lua->runScript(xml_elem.text(), NULL, "preload"); } } else if(xml_elem.tagName() == "widgets") { @@ -118,15 +117,6 @@ void MacroWindow::initMacro(QDomNode &node) mainwidget = window; mainwidget->setValues(); - /* - QDomNodeList children = node.childNodes(); - - // Insert their values (this must be done last for scripts to work properly) - for (int i=0; ideleteLater(); + if(mainwidget) delete mainwidget; mainwidget = NULL; - setExpandedWidget(NULL); + lua->clear(); - luaprograms.clear(); + setExpandedWidget(NULL); } diff --git a/client/macrowindow.h b/client/macrowindow.h index 3bc02f2..02370dd 100644 --- a/client/macrowindow.h +++ b/client/macrowindow.h @@ -44,8 +44,6 @@ public: bool collapsed = true, bool compact = false); ~MacroWindow(); - QVector< QString > luaprograms; - LUA *lua; void update(QDomNode &xml_doc); -- cgit v1.2.3