aboutsummaryrefslogtreecommitdiff
path: root/src/FbTk/Luamm.hh
diff options
context:
space:
mode:
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