Exemplo n.º 1
0
bool loadModules()
{
    loadEmbeddedModules(L);

    ChangeDir cd;
    if (!cd.changeDir(L"modules"))
    {
        lua_register(L, "require", require_stub);
        return false;
    }

    tstring path(cd.getCurrentDir());
    path.append(L"\\modules\\?.dll");
    luaopen_package(L);
    lua_pushstring(L, "path");
    lua_pushstring(L, "");
    lua_settable(L, -3);
    lua_pushstring(L, "cpath");
    lua_pushstring(L, TW2A(path.c_str()));
    lua_settable(L, -3);
    lua_setglobal(L, "package");
    lua_pop(L, 1);

    std::vector<tstring> files;
    {
        WIN32_FIND_DATA fd;
        memset(&fd, 0, sizeof(WIN32_FIND_DATA));
        HANDLE file = FindFirstFile(L"*.*", &fd);
        if (file != INVALID_HANDLE_VALUE)
        {
            do
            {
                if (!(fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
                {
                    if (Module::isModule(fd.cFileName))
                        files.push_back(fd.cFileName);
                }
            } while (::FindNextFile(file, &fd));
            ::FindClose(file);
        }
    }

    for (int j = 0, je = files.size(); j < je; ++j)
    {
        TW2A w2a(files[j].c_str());
        if (luaL_dofile(L, w2a))
        {
            tstring error(L"Ошибка при загрузке модуля: '");
            error.append(files[j]);
            error.append(L"' - ");
            error.append(luaT_towstring(L, -1));
            pluginOut(error.c_str());
        }
    }
    return true;
}
Exemplo n.º 2
0
bool Plugin::isAlreadyLoaded(const wchar_t* filename)
{
    const wchar_t *e = wcsrchr(filename, L'.');
    if (!e) return false;
    tstring module_name(filename, e);
    tstring ext(e+1);
    if (isLoadedPlugin(module_name.c_str()))
    {
        swprintf(plugin_buffer(), L"Плагин %s не загружен, так как место _G['%s'] занято модулем или другим плагином.", filename, 
            module_name.c_str());
        pluginOut(plugin_buffer());
        return true;
    }
    return false;
}