From ea3881684a186081c56af7dd1167ae4c780a48b1 Mon Sep 17 00:00:00 2001 From: Pavel Labath Date: Sun, 12 Jun 2011 20:24:14 +0200 Subject: Add a function for converting from XResources to lua ones --- src/FbTk/LResource.cc | 16 ++++++++++++++++ src/FbTk/LResource.hh | 1 + src/FbTk/Resource.hh | 4 ++++ 3 files changed, 21 insertions(+) diff --git a/src/FbTk/LResource.cc b/src/FbTk/LResource.cc index 78511eb..2e2a7c7 100644 --- a/src/FbTk/LResource.cc +++ b/src/FbTk/LResource.cc @@ -82,6 +82,22 @@ void LResourceManager::initState(lua::state &l) { l.setfield(lua::REGISTRYINDEX, make_root); } +void LResourceManager::convert(ResourceManager &old, const std::string &new_file) { + lua::state l; + initState(l); + + LResourceManager new_rm(old.root(), l); + for(ResourceList::const_iterator i = old.begin(); i != old.end(); ++i) { + // adding the resource to new_rm will set it to default value + // we save the value to a temp variable so we can restore it later + const std::string &t = (*i)->getString(); + new_rm.addResource(**i); + (*i)->setFromString(t.c_str()); + } + + new_rm.save(new_file.c_str(), NULL); +} + LResourceManager::LResourceManager(const std::string &root, lua::state &l) : ResourceManager_base(root), m_l(&l) { l.checkstack(2); diff --git a/src/FbTk/LResource.hh b/src/FbTk/LResource.hh index 185a029..1125707 100644 --- a/src/FbTk/LResource.hh +++ b/src/FbTk/LResource.hh @@ -38,6 +38,7 @@ namespace FbTk { class LResourceManager: public ResourceManager_base { public: static void initState(lua::state &l); + static void convert(ResourceManager &old, const std::string &new_file); LResourceManager(const std::string &root, lua::state &l); virtual bool save(const char *filename, const char *); diff --git a/src/FbTk/Resource.hh b/src/FbTk/Resource.hh index 744178b..00f8769 100644 --- a/src/FbTk/Resource.hh +++ b/src/FbTk/Resource.hh @@ -123,6 +123,10 @@ public: template Resource &getResource(const std::string &resource); + const std::string &root() const { return m_root; } + ResourceList::const_iterator begin() { return m_resourcelist.begin(); } + ResourceList::const_iterator end() { return m_resourcelist.end(); } + protected: ResourceList m_resourcelist; const std::string m_root; -- cgit v0.11.2