Skip to content

Commit

Permalink
lua/ironbee/predicate.lua: Remove lowercase utilities in favor of PUt…
Browse files Browse the repository at this point in the history
…il, e.g., PUtil.Define instead of P.define. RNS-783
  • Loading branch information
Christopher Alfeld committed Mar 5, 2014
1 parent 053bef9 commit 09877a1
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 41 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Expand Up @@ -11,6 +11,7 @@ IronBee v0.10.0
**Predicate** **Predicate**


- The Lua shortcuts for operators and transformations have been removed. Use `P.Operator` and `P.Transformation` instead. These issued deprecation warnings in 0.9. - The Lua shortcuts for operators and transformations have been removed. Use `P.Operator` and `P.Transformation` instead. These issued deprecation warnings in 0.9.
- The Lua deprecated utility routines such as `P.define` are now removed. Use `PUtil.Define` instead. These issued deprecation warnings in 0.9.


**Util** **Util**


Expand Down
33 changes: 5 additions & 28 deletions lua/ironbee/config.lua
Expand Up @@ -77,39 +77,16 @@ local DoInDSL = function(f, cp)
-- --
-- TODO Remove this when P/PUtil is split. -- TODO Remove this when P/PUtil is split.
-- --
_G['PUtil'] = { }
_G['P'] = { } _G['P'] = { }
local p_mt = { local p_mt = {
__index = Predicate __index = Predicate
} }
setmetatable(_G['PUtil'], p_mt)
setmetatable(_G['P'], p_mt) setmetatable(_G['P'], p_mt)
for n,v in pairs(Predicate) do _G['PUtil'] = { }
if (type(v) == "function") then local putil_mt = {
local first_char = string.sub(n, 1, 1) __index = Predicate.Util
-- Lowercase functions are utility, ucfirst() is sexpr. }
if first_char == string.lower(first_char) then setmetatable(_G['PUtil'], putil_mt)
-- Deprecate lowercase function in P (should use PUtil).
_G['P'][n] = function(...)
ib:logWarn("P." .. n .. "(...) is deprecated - use PUtil." .. n:sub(1,1):upper()..n:sub(2) .. "(...) instead.")
return v(...)
end
-- Deprecate lowercase version in PUtil.
_G['PUtil'][n] = function(...)
ib:logWarn("PUtil." .. n .. "(...) is deprecated - use PUtil." .. n:sub(1,1):upper()..n:sub(2) .. "(...) instead.")
return v(...)
end
-- Add a ucfirst() version to PUtil (what should be used going forward).
_G['PUtil'][n:sub(1,1):upper()..n:sub(2)] = v
else
-- Deprecate ucfirst() function in PUtil (should use P)
_G['PUtil'][n] = function(...)
ib:logWarn("PUtil." .. n .. "(...) is deprecated - use P." .. n .. "(...) instead.")
return v(...)
end
end
end
end
_G['IB'] = ib _G['IB'] = ib
_G['CP'] = cp _G['CP'] = cp
Expand Down
28 changes: 15 additions & 13 deletions lua/ironbee/predicate.lua
Expand Up @@ -21,6 +21,8 @@ _M._COPYRIGHT = "Copyright (C) 2014 Qualys, Inc."
_M._DESCRIPTION = "IronBee Lua Predicate Frontend" _M._DESCRIPTION = "IronBee Lua Predicate Frontend"
_M._VERSION = "1.0" _M._VERSION = "1.0"


_M.Util = {}

-- Template define directive name. -- Template define directive name.
local PREDICATE_DEFINE = 'PredicateDefine' local PREDICATE_DEFINE = 'PredicateDefine'


Expand Down Expand Up @@ -131,7 +133,7 @@ function call_mt:new(name, ...)
local children = {} local children = {}


for _,v in ipairs({...}) do for _,v in ipairs({...}) do
table.insert(children, _M.from_lua(v)) table.insert(children, _M.Util.FromLua(v))
end end
r.name = name r.name = name
r.children = children r.children = children
Expand Down Expand Up @@ -313,11 +315,11 @@ for i,n in ipairs(paramn) do
end end


function _M.If(a, b, c) function _M.If(a, b, c)
a = _M.from_lua(a) a = _M.Util.FromLua(a)
b = _M.from_lua(b) b = _M.Util.FromLua(b)
c = _M.from_lua(c) c = _M.Util.FromLua(c)


local is_true, is_converted = _M.to_lua(a) local is_true, is_converted = _M.Util.ToLua(a)
if is_converted then if is_converted then
if is_true then if is_true then
return b return b
Expand All @@ -338,8 +340,8 @@ local sym = {
} }
for n,s in pairs(sym) do for n,s in pairs(sym) do
_M[n] = function (a, b) _M[n] = function (a, b)
a = _M.from_lua(a) a = _M.Util.FromLua(a)
b = _M.from_lua(b) b = _M.Util.FromLua(b)
if a.type ~= 'string' and b.type ~= 'string' then if a.type ~= 'string' and b.type ~= 'string' then
error(n .. " requires at least one string literal argument.") error(n .. " requires at least one string literal argument.")
end end
Expand Down Expand Up @@ -376,7 +378,7 @@ end


-- Utility -- Utility


function _M.from_lua(v) function _M.Util.FromLua(v)
if type(v) == 'string'then if type(v) == 'string'then
return _M.String(v) return _M.String(v)
end end
Expand All @@ -393,7 +395,7 @@ function _M.from_lua(v)
return v return v
end end


function _M.to_lua(v) function _M.Util.ToLua(v)
if v.type == nil then return nil, false end if v.type == nil then return nil, false end
if v.type == 'null' then return nil, true end if v.type == 'null' then return nil, true end
if v.type == 'call' then if v.type == 'call' then
Expand All @@ -411,7 +413,7 @@ function _M.to_lua(v)
return nil, false return nil, false
end end


function _M.pp(s) function _M.Util.PP(s)
local indent = 0 local indent = 0
local r = '' local r = ''
local i = 1 local i = 1
Expand Down Expand Up @@ -448,20 +450,20 @@ function _M.pp(s)
end end


-- Template Support -- Template Support
function _M.declare(name, predicate_name) function _M.Util.Declare(name, predicate_name)
predicate_name = predicate_name or name predicate_name = predicate_name or name
_M[name] = function (...) _M[name] = function (...)
return _M.C(predicate_name, ...) return _M.C(predicate_name, ...)
end end
return nil return nil
end end


function _M.define(name, args, body) function _M.Util.Define(name, args, body)
if type(body) ~= 'string' then if type(body) ~= 'string' then
body = body() body = body()
end end
local args_string = table.concat(args, ' ') local args_string = table.concat(args, ' ')
_M.declare(name) _M.Util.Declare(name)


if IB == nil then if IB == nil then
-- Not running in IronBee -- Not running in IronBee
Expand Down

0 comments on commit 09877a1

Please sign in to comment.