aboutsummaryrefslogtreecommitdiff
path: root/src/FbTk/LResource.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/FbTk/LResource.cc')
-rw-r--r--src/FbTk/LResource.cc47
1 files changed, 22 insertions, 25 deletions
diff --git a/src/FbTk/LResource.cc b/src/FbTk/LResource.cc
index b91f0d8..6671b89 100644
--- a/src/FbTk/LResource.cc
+++ b/src/FbTk/LResource.cc
@@ -24,8 +24,8 @@
24 24
25#include "LResource.hh" 25#include "LResource.hh"
26 26
27#include "LuaUtil.hh"
27#include "Resource.hh" 28#include "Resource.hh"
28#include "Luamm.hh"
29 29
30extern const char LResourceHelper[]; 30extern const char LResourceHelper[];
31extern const unsigned int LResourceHelper_size; 31extern const unsigned int LResourceHelper_size;
@@ -61,30 +61,32 @@ namespace {
61 61
62 return 0; 62 return 0;
63 } 63 }
64}
65 64
66void LResourceManager::initState(lua::state &l) { 65 void initState(Lua &l) {
67 l.checkstack(6); 66 l.checkstack(6);
68 lua::stack_sentry s(l); 67 lua::stack_sentry s(l);
69 68
70 l.loadstring(LResourceHelper, LResourceHelper_size); 69 l.loadstring(LResourceHelper, LResourceHelper_size);
71 l.pushfunction(&readResource); 70 l.pushfunction(&readResource);
72 l.pushfunction(&writeResource); 71 l.pushfunction(&writeResource);
73 l.newtable(); {
74 l.newtable(); { 72 l.newtable(); {
75 l.pushvalue(-2); 73 l.newtable(); {
76 l.setfield(-2, "__metatable"); 74 l.pushvalue(-2);
77 } l.setfield(lua::REGISTRYINDEX, resource_metatable); 75 l.setfield(-2, "__metatable");
76 } l.setfield(lua::REGISTRYINDEX, resource_metatable);
77 }
78 l.call(3, 3);
79 l.setfield(lua::REGISTRYINDEX, dump_resources);
80 l.setfield(lua::REGISTRYINDEX, register_resource);
81 l.setfield(lua::REGISTRYINDEX, make_root);
78 } 82 }
79 l.call(3, 3); 83
80 l.setfield(lua::REGISTRYINDEX, dump_resources); 84 Lua::RegisterInitFunction register_init_state(&initState);
81 l.setfield(lua::REGISTRYINDEX, register_resource); 85
82 l.setfield(lua::REGISTRYINDEX, make_root); 86} // anonymous namespace
83}
84 87
85void LResourceManager::convert(ResourceManager &old, const std::string &new_file) { 88void LResourceManager::convert(ResourceManager &old, const std::string &new_file) {
86 lua::state l; 89 Lua l;
87 initState(l);
88 90
89 LResourceManager new_rm(old.root(), l); 91 LResourceManager new_rm(old.root(), l);
90 for(ResourceList::const_iterator i = old.begin(); i != old.end(); ++i) { 92 for(ResourceList::const_iterator i = old.begin(); i != old.end(); ++i) {
@@ -98,17 +100,12 @@ void LResourceManager::convert(ResourceManager &old, const std::string &new_file
98 new_rm.save(new_file.c_str(), NULL); 100 new_rm.save(new_file.c_str(), NULL);
99} 101}
100 102
101LResourceManager::LResourceManager(const std::string &root, lua::state &l) 103LResourceManager::LResourceManager(const std::string &root, Lua &l)
102 : ResourceManager_base(root), m_l(&l) { 104 : ResourceManager_base(root), m_l(&l) {
103 l.checkstack(2); 105 l.checkstack(2);
104 lua::stack_sentry s(l); 106 lua::stack_sentry s(l);
105 107
106 l.getfield(lua::REGISTRYINDEX, make_root); 108 l.getfield(lua::REGISTRYINDEX, make_root);
107 if(l.isnil(-1)) {
108 l.pop();
109 initState(l);
110 l.getfield(lua::REGISTRYINDEX, make_root);
111 }
112 l.pushstring(root); 109 l.pushstring(root);
113 l.call(1, 0); 110 l.call(1, 0);
114} 111}