diff options
author | Pavel Labath <pavelo@centrum.sk> | 2011-06-14 15:02:07 (GMT) |
---|---|---|
committer | Pavel Labath <pavelo@centrum.sk> | 2011-06-15 23:07:49 (GMT) |
commit | 1230282ce6da7b0e543c9762181b60d14dafaa35 (patch) | |
tree | e256de98ba8fd5beed8610bc7fbd2099570596bf /src/FbTk/Luamm.hh | |
parent | 9189d1cc96f7c3cc4da95739c818e4179a4977d6 (diff) | |
download | fluxbox_pavel-1230282ce6da7b0e543c9762181b60d14dafaa35.zip fluxbox_pavel-1230282ce6da7b0e543c9762181b60d14dafaa35.tar.bz2 |
Lua exceptions can now outlive thier lua context
Diffstat (limited to 'src/FbTk/Luamm.hh')
-rw-r--r-- | src/FbTk/Luamm.hh | 14 |
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 | ||
36 | namespace lua { | 37 | namespace 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 |