Skip to content

Instantly share code, notes, and snippets.

@mrwonko
Created May 25, 2012 19:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mrwonko/2790157 to your computer and use it in GitHub Desktop.
Save mrwonko/2790157 to your computer and use it in GitHub Desktop.
function pointer template
template<const std::vector<std::string> (*function)(const std::string&)> luabind::object StringVectorAsTable(const std::string& argument, lua_State* L)
{
luabind::object result = luabind::newtable(L);
std::vector<std::string> vec = function(argument);
std::vector<std::string>::iterator end = vec.end();
unsigned int index = 0;
for(std::vector<std::string>::iterator it = vec.begin(); it != end; ++it)
{
result[++index] = *it;
}
return result;
}
...
luabind::def("GetFilesInDirectory", &StringVectorAsTable<Helpers::GetFilesInDirectory>),
luabind::def("GetDirectoriesInDirectory", &StringVectorAsTable<Helpers::GetDirectoriesInDirectory>),
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment