Allow list bindings

This commit is contained in:
Henrique Santiago 2012-08-05 10:56:15 -03:00
parent 5abf8622e5
commit 18c882f1a0
2 changed files with 35 additions and 0 deletions

View File

@ -124,6 +124,13 @@ template<typename Ret, typename... Args>
typename std::enable_if<!std::is_void<Ret>::value, bool>::type typename std::enable_if<!std::is_void<Ret>::value, bool>::type
luavalue_cast(int index, std::function<Ret(Args...)>& func); luavalue_cast(int index, std::function<Ret(Args...)>& func);
// list
template<typename T>
int push_luavalue(const std::list<T>& list);
template<typename T>
bool luavalue_cast(int index, std::list<T>& list);
// vector // vector
template<typename T> template<typename T>
int push_luavalue(const std::vector<T>& vec); int push_luavalue(const std::vector<T>& vec);
@ -274,6 +281,33 @@ luavalue_cast(int index, std::function<Ret(Args...)>& func) {
return false; return false;
} }
template<typename T>
int push_luavalue(const std::list<T>& list) {
g_lua.newTable();
int i = 1;
for(const T& v : list) {
push_internal_luavalue(v);
g_lua.rawSeti(i);
i++;
}
return 1;
}
template<typename T>
bool luavalue_cast(int index, std::list<T>& list)
{
if(g_lua.isTable(index)) {
g_lua.pushNil();
while(g_lua.next(index < 0 ? index-1 : index)) {
T value;
if(luavalue_cast(-1, value))
list.push_back(value);
g_lua.pop();
}
return true;
}
return false;
}
template<typename T> template<typename T>
int push_luavalue(const std::vector<T>& vec) { int push_luavalue(const std::vector<T>& vec) {

View File

@ -151,6 +151,7 @@ void Application::registerLuaFunctions()
g_lua.bindSingletonFunction("g_resources", "getRealDir", &ResourceManager::getRealDir, &g_resources); g_lua.bindSingletonFunction("g_resources", "getRealDir", &ResourceManager::getRealDir, &g_resources);
g_lua.bindSingletonFunction("g_resources", "getWorkDir", &ResourceManager::getWorkDir, &g_resources); g_lua.bindSingletonFunction("g_resources", "getWorkDir", &ResourceManager::getWorkDir, &g_resources);
g_lua.bindSingletonFunction("g_resources", "getSearchPaths", &ResourceManager::getSearchPaths, &g_resources); g_lua.bindSingletonFunction("g_resources", "getSearchPaths", &ResourceManager::getSearchPaths, &g_resources);
g_lua.bindSingletonFunction("g_resources", "listDirectoryFiles", &ResourceManager::listDirectoryFiles, &g_resources);
// Module // Module
g_lua.registerClass<Module>(); g_lua.registerClass<Module>();