aboutsummaryrefslogtreecommitdiff
path: root/src/FbTk/LuaUtil.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/FbTk/LuaUtil.cc')
-rw-r--r--src/FbTk/LuaUtil.cc23
1 files changed, 20 insertions, 3 deletions
diff --git a/src/FbTk/LuaUtil.cc b/src/FbTk/LuaUtil.cc
index 700ef1a..8f382e8 100644
--- a/src/FbTk/LuaUtil.cc
+++ b/src/FbTk/LuaUtil.cc
@@ -57,9 +57,26 @@ namespace {
57 return 0; 57 return 0;
58 } 58 }
59 59
60 struct AutoVector: public std::vector<Lua::InitFunction *> {
61 ~AutoVector() {
62 for(iterator it = begin(); it != end(); ++it)
63 delete *it;
64 }
65 };
66 typedef AutoVector InitFunctions;
67
68 InitFunctions *s_init_functions;
60} // anonymous namespace 69} // anonymous namespace
61 70
62Lua::InitFunctions Lua::s_init_functions; 71void Lua::doRegisterInitFunction(std::auto_ptr<InitFunction> fn) {
72 struct InitHelper {
73 InitHelper() { s_init_functions = new InitFunctions; }
74 ~InitHelper() { delete s_init_functions; }
75 };
76 static InitHelper helper;
77
78 s_init_functions->push_back(fn.release());
79}
63 80
64Lua::Lua() { 81Lua::Lua() {
65 checkstack(1); 82 checkstack(1);
@@ -73,8 +90,8 @@ Lua::Lua() {
73 90
74 makeReadOnly(lua::GLOBALSINDEX, true); 91 makeReadOnly(lua::GLOBALSINDEX, true);
75 92
76 InitFunctions::const_iterator it_end = s_init_functions.end(); 93 InitFunctions::const_iterator it_end = s_init_functions->end();
77 for(InitFunctions::const_iterator it = s_init_functions.begin(); it != it_end; ++it) 94 for(InitFunctions::const_iterator it = s_init_functions->begin(); it != it_end; ++it)
78 (**it)(*this); 95 (**it)(*this);
79} 96}
80 97