Allow list bindings
This commit is contained in:
parent
5abf8622e5
commit
18c882f1a0
|
@ -124,6 +124,13 @@ template<typename Ret, typename... Args>
|
|||
typename std::enable_if<!std::is_void<Ret>::value, bool>::type
|
||||
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
|
||||
template<typename T>
|
||||
int push_luavalue(const std::vector<T>& vec);
|
||||
|
@ -274,6 +281,33 @@ luavalue_cast(int index, std::function<Ret(Args...)>& func) {
|
|||
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>
|
||||
int push_luavalue(const std::vector<T>& vec) {
|
||||
|
|
|
@ -151,6 +151,7 @@ void Application::registerLuaFunctions()
|
|||
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", "getSearchPaths", &ResourceManager::getSearchPaths, &g_resources);
|
||||
g_lua.bindSingletonFunction("g_resources", "listDirectoryFiles", &ResourceManager::listDirectoryFiles, &g_resources);
|
||||
|
||||
// Module
|
||||
g_lua.registerClass<Module>();
|
||||
|
|
Loading…
Reference in New Issue