Question

I get this error:

luascript.cpp: In member function ‘bool LuaInterface::loadDirectory(const string&, Npc*, bool)’:
luascript.cpp:744:69: error: no matching function for call to ‘LuaInterface::loadDirectory(boost::filesystem3::path, Npc*&, bool&)’
luascript.cpp:744:69: note: candidate is:
luascript.cpp:736:6: note: bool LuaInterface::loadDirectory(const string&, Npc*, bool)
luascript.cpp:736:6: note:   no known conversion for argument 1 from ‘boost::filesystem3::path’ to ‘const string& {aka const std::basic_string<char>&}’

And this code:

    bool LuaInterface::loadDirectory(const std::string& dir, Npc* npc/* = NULL*/, bool recursively/* = false*/)
{
    StringVec files;
    for(boost::filesystem::directory_iterator it(dir), end; it != end; ++it)
    {
        std::string s = it->path().filename().string();
        if(boost::filesystem::is_directory(it->status()))
        {
            if(recursively && !loadDirectory(it->path() / s, npc, recursively))
            return false;
        }
        else if((s.size() > 4 ? s.substr(s.size() - 4) : "") == ".lua")
            files.push_back(s);
    }

    std::sort(files.begin(), files.end());
    for(StringVec::iterator it = files.begin(); it != files.end(); ++it)
    {
        if(!loadFile(dir + (*it), npc))
            return false;
    }

    return true;
}

I changed the first if to be cleaner as someone suggested here but they also told me to use the native() path accesors.

Was it helpful?

Solution

Then... why don't you? :)

if(recursively && !loadDirectory((it->path() / s).native(), npc, recursively))

By now it probably makes sense to

  • introduce a variable for it->path() / s
  • read the documentation for Boost Filesystem
    The code suggests you are trying traverse a filesystem tree recursively. Have you looked at boost::recursive_directory_iterator?
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top