Fix string filter generator.

This commit is contained in:
bakpakin 2016-03-05 16:06:56 -05:00
parent 3b4bd9920b
commit 27f881444a
2 changed files with 27 additions and 4 deletions

View File

@ -111,6 +111,28 @@ describe('tiny-ecs:', function()
end) end)
it("Can use string filters", function()
local f = tiny.filter('a|b|c')
assert.truthy(f(nil, {
a = true, b = true, c = true
}))
assert.truthy(f(nil, {
a = true
}))
assert.truthy(f(nil, {
b = true
}))
assert.truthy(f(nil, {
c = true
}))
assert.falsy(f(nil, {
x = true, y = true, z = true
}))
end)
end) end)
describe('World:', function() describe('World:', function()

View File

@ -92,6 +92,7 @@ local filterJoin
local filterBuildString local filterBuildString
do do
local loadstring = loadstring or load local loadstring = loadstring or load
local function getchr(c) local function getchr(c)
return "\\" .. c:byte() return "\\" .. c:byte()
@ -145,12 +146,12 @@ do
return table.concat(accum) return table.concat(accum)
end end
print(buildPart'a|b|(c&d)')
function filterBuildString(str) function filterBuildString(str)
local source = ('return function(_, e) return %s end end'):format(buildPart(str)) local source = ("return function(_, e) return %s end"):format(buildPart(str))
local loader, err = loadstring(source) local loader, err = loadstring(source)
if err then error(err) end if err then
error(err)
end
return loader() return loader()
end end