Git Product home page Git Product logo

lua-glob's Introduction

lua-glob

Build status

Require LPegLabel

Install: copy "glob/" directory to your project, or use luarocks luarocks install lua-glob --server=https://luarocks.org/dev

glob

local glob = require 'glob'

local pattern = {
    'src',
    '!*.dll',
}
local options = {
    ignoreCase = true
}
local parser = glob.glob(pattern, options)

parser 'Src/main.lua' --> true
parser 'Src/lpeg.dll' --> false

gitignore

match

local glob = require 'glob'

local pattern = {
    'src/*',
    '!*.dll',
}
local options = {
    ignoreCase = true
}
local parser = glob.gitignore(pattern, options)

parser 'Src/main.lua' --> true
parser 'Src/lpeg.dll' --> false

scan

Work space

main.lua
utility.lua
src
|---test.lua
|---bee.dll
|---lua.dll
local glob = require 'glob'
local fs = require 'bee.filesystem' -- just another filesystem


local pattern = {
    'src/*',
    '!*.dll',
}
local options = {
    ignoreCase = true
}
local interface = {
    type = function (path)
        if not fs.exists(fs.path(path)) then
            return nil
        end
        if fs.is_directory(fs.path(path)) then
            return 'directory'
        else
            return 'file'
        end
    end,
    list = function (path)
        if not fs.exists(fs.path(path)) then
            return nil
        end
        if not fs.is_directory(fs.path(path)) then
            return nil
        end
        local childs = {}
        for child in fs.path(path):list_directory() do
            childs[#childs+1] = child:string()
        end
        return childs
    end,
}

local parser = glob.gitignore(pattern, options, interface)
local files = parser:scan()
print(files[1]) --> main.lua
print(files[2]) --> utility.lua
print(files[3]) --> src\bee.dll
print(files[4]) --> src\lua.dll
print(files[5]) --> nil

lua-glob's People

Contributors

rinkaa avatar sumneko avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

rinkaa

lua-glob's Issues

通过Luarocks包管理器安装?

Luarocks上关于glob的库现在只有个挺旧的lua-glob-pattern,功能也不怎么好用。相比起来还是您这个repo方便许多。虽然现在直接clone下来使用完全没有问题,但是如果可以的话希望这个repo能够上传到Luarocks上,让这个repo更便于安装、也更方便被其他包依赖,造福更多的人……

一个范例rockspec文件:

-- lua-glob-dev-1.rockspec

rockspec_format = "3.0"
package = "lua-glob"
version = "dev-1"
source = {
   url = "git://github.com/sumneko/lua-glob",
   branch = "master",
}
description = {
   homepage = "https://github.com/sumneko/lua-glob",
   license = "MIT"
}
dependencies = {
   "lua >= 5.1",
   "lpeglabel ~> 1",
}
build = {
   type = "builtin",
   modules = {
      ["glob"] = "glob/init.lua",
      ["glob.glob"] = "glob/glob.lua",
      ["glob.gitignore"] = "glob/gitignore.lua",
      ["glob.matcher"] = "glob/matcher.lua",
   },
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.