aboutsummaryrefslogtreecommitdiff
path: root/src/FbTk/Luamm.hh
diff options
context:
space:
mode:
authorPavel Labath <pavelo@centrum.sk>2011-06-14 15:02:07 (GMT)
committerPavel Labath <pavelo@centrum.sk>2011-11-01 09:52:46 (GMT)
commitf7c7b7ae7281a0f0742a2958d272c2260bcf2b76 (patch)
treef1b8417f22b4be628637f6574e2745f594a2e6e4 /src/FbTk/Luamm.hh
parent093b30702304e72a2b73c0041a63c7c125af7314 (diff)
downloadfluxbox_paul-f7c7b7ae7281a0f0742a2958d272c2260bcf2b76.zip
fluxbox_paul-f7c7b7ae7281a0f0742a2958d272c2260bcf2b76.tar.bz2
Lua exceptions can now outlive thier lua context
Diffstat (limited to 'src/FbTk/Luamm.hh')
-rw-r--r--src/FbTk/Luamm.hh14
1 files changed, 13 insertions, 1 deletions
diff --git a/src/FbTk/Luamm.hh b/src/FbTk/Luamm.hh
index f2084e7..1ba9cbe 100644
--- a/src/FbTk/Luamm.hh
+++ b/src/FbTk/Luamm.hh
@@ -31,6 +31,7 @@
31#include <lua.h> 31#include <lua.h>
32#include <lualib.h> 32#include <lualib.h>
33 33
34#include "RefCount.hh"
34#include "Slot.hh" 35#include "Slot.hh"
35 36
36namespace lua { 37namespace lua {
@@ -84,6 +85,7 @@ namespace lua {
84 */ 85 */
85 class exception: public std::runtime_error { 86 class exception: public std::runtime_error {
86 state *L; 87 state *L;
88 FbTk::RefCount<const bool> L_valid;
87 int key; 89 int key;
88 90
89 static std::string get_error_msg(state *L); 91 static std::string get_error_msg(state *L);
@@ -152,9 +154,19 @@ namespace lua {
152 bool safe_compare(lua_CFunction trampoline, int index1, int index2); 154 bool safe_compare(lua_CFunction trampoline, int index1, int index2);
153 void do_pushclosure(int n); 155 void do_pushclosure(int n);
154 156
157 /**
158 * The pointed-to value is true if this object still exists. We need this because the
159 * exceptions have to know if they may reference it to remove the saved lua exception. If
160 * this object is destroyed then the exception was already collected by the garbage
161 * colletor and referencing this would generate a segfault.
162 */
163 FbTk::RefCount<bool> valid;
164
155 public: 165 public:
156 state(); 166 state();
157 ~state() { lua_close(cobj); } 167 ~state() { *valid = false; lua_close(cobj); }
168
169 FbTk::RefCount<const bool> get_valid() const { return valid; }
158 170
159 /* 171 /*
160 * Lua functions come in three flavours 172 * Lua functions come in three flavours