Merged default into Mesh

--HG--
branch : Mesh
This commit is contained in:
Alex Szpakowski
2013-09-29 04:58:26 -03:00
28 changed files with 364 additions and 182 deletions
+39 -10
View File
@@ -29,7 +29,30 @@
namespace
{
std::map<std::string, love::Module*> registry;
typedef std::map<std::string, love::Module*> ModuleRegistry;
// The registry must be dynamically managed, because some modules
// (the math module) are static globals that are not guaranteed to
// be destroyed before other static globals.
ModuleRegistry *registry = nullptr;
ModuleRegistry &registryInstance()
{
if (!registry)
registry = new ModuleRegistry;
return *registry;
}
void freeEmptyRegistry()
{
if (registry && registry->empty())
{
delete registry;
registry = nullptr;
}
}
} // anonymous namespace
namespace love
@@ -37,10 +60,10 @@ namespace love
Module::~Module()
{
std::map<std::string, Module*>::iterator it;
ModuleRegistry &registry = registryInstance();
// We can't use the overridden Module::getName() in this destructor.
for (it = registry.begin(); it != registry.end(); ++it)
for (auto it = registry.begin(); it != registry.end(); ++it)
{
if (it->second == this)
{
@@ -48,16 +71,20 @@ Module::~Module()
break;
}
}
freeEmptyRegistry();
}
void Module::registerInstance(Module *instance)
{
if (instance == NULL)
if (instance == nullptr)
throw Exception("Module instance is NULL");
std::string name(instance->getName());
std::map<std::string, Module*>::iterator it = registry.find(name);
ModuleRegistry &registry = registryInstance();
auto it = registry.find(name);
if (it != registry.end())
{
@@ -71,25 +98,27 @@ void Module::registerInstance(Module *instance)
Module *Module::getInstance(const std::string &name)
{
std::map<std::string, Module*>::const_iterator it = registry.find(name);
ModuleRegistry &registry = registryInstance();
auto it = registry.find(name);
if (registry.end() == it)
return NULL;
return nullptr;
return it->second;
}
Module *Module::findInstance(const std::string &name)
{
std::map<std::string, Module*>::const_iterator it;
ModuleRegistry &registry = registryInstance();
for (it = registry.begin(); it != registry.end(); ++it)
for (auto it = registry.begin(); it != registry.end(); ++it)
{
if (it->first.find(name) == 0)
return it->second;
}
return NULL;
return nullptr;
}
} // love
+1 -1
View File
@@ -26,7 +26,7 @@ namespace love
extern StringMap<Type, TYPE_MAX_ENUM> types;
love::Type extractudatatype(lua_State *L, int idx)
static love::Type extractudatatype(lua_State *L, int idx)
{
Type t = INVALID_ID;
if (!lua_isuserdata(L, idx))
+1 -11
View File
@@ -168,7 +168,7 @@ int luax_intflag(lua_State *L, int table_index, const char *key, int defaultValu
if (!lua_isnumber(L, -1))
retval = defaultValue;
else
retval = lua_tonumber(L, -1);
retval = (int) lua_tointeger(L, -1);
lua_pop(L, 1);
return retval;
@@ -533,16 +533,6 @@ int luax_pconvobj(lua_State *L, int idxs[], int n, const char *mod, const char *
return ret;
}
int luax_strtofile(lua_State *L, int idx)
{
return luax_convobj(L, idx, "filesystem", "newFile");
}
int luax_filetodata(lua_State *L, int idx)
{
return luax_convobj(L, idx, "filesystem", "read");
}
int luax_insist(lua_State *L, int idx, const char *k)
{
// Convert to absolute index if necessary.