Permalink
Browse files

lua/ironbee/predicate.lua: Remove lowercase utilities in favor of PUt…

…il, e.g., PUtil.Define instead of P.define. RNS-783
  • Loading branch information...
1 parent 053bef9 commit 09877a1c97fd6a7162cc892ec2333bd502caf0ff Christopher Alfeld committed Mar 5, 2014
Showing with 21 additions and 41 deletions.
  1. +1 −0 CHANGES.md
  2. +5 −28 lua/ironbee/config.lua
  3. +15 −13 lua/ironbee/predicate.lua
View
@@ -11,6 +11,7 @@ IronBee v0.10.0
**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 deprecated utility routines such as `P.define` are now removed. Use `PUtil.Define` instead. These issued deprecation warnings in 0.9.
**Util**
View
@@ -77,39 +77,16 @@ local DoInDSL = function(f, cp)
--
-- TODO Remove this when P/PUtil is split.
--
- _G['PUtil'] = { }
_G['P'] = { }
local p_mt = {
__index = Predicate
}
- setmetatable(_G['PUtil'], p_mt)
setmetatable(_G['P'], p_mt)
- for n,v in pairs(Predicate) do
- if (type(v) == "function") then
- local first_char = string.sub(n, 1, 1)
- -- Lowercase functions are utility, ucfirst() is sexpr.
- if first_char == string.lower(first_char) then
- -- 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['PUtil'] = { }
+ local putil_mt = {
+ __index = Predicate.Util
+ }
+ setmetatable(_G['PUtil'], putil_mt)
_G['IB'] = ib
_G['CP'] = cp
View
@@ -21,6 +21,8 @@ _M._COPYRIGHT = "Copyright (C) 2014 Qualys, Inc."
_M._DESCRIPTION = "IronBee Lua Predicate Frontend"
_M._VERSION = "1.0"
+_M.Util = {}
+
-- Template define directive name.
local PREDICATE_DEFINE = 'PredicateDefine'
@@ -131,7 +133,7 @@ function call_mt:new(name, ...)
local children = {}
for _,v in ipairs({...}) do
- table.insert(children, _M.from_lua(v))
+ table.insert(children, _M.Util.FromLua(v))
end
r.name = name
r.children = children
@@ -313,11 +315,11 @@ for i,n in ipairs(paramn) do
end
function _M.If(a, b, c)
- a = _M.from_lua(a)
- b = _M.from_lua(b)
- c = _M.from_lua(c)
+ a = _M.Util.FromLua(a)
+ b = _M.Util.FromLua(b)
+ 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_true then
return b
@@ -338,8 +340,8 @@ local sym = {
}
for n,s in pairs(sym) do
_M[n] = function (a, b)
- a = _M.from_lua(a)
- b = _M.from_lua(b)
+ a = _M.Util.FromLua(a)
+ b = _M.Util.FromLua(b)
if a.type ~= 'string' and b.type ~= 'string' then
error(n .. " requires at least one string literal argument.")
end
@@ -376,7 +378,7 @@ end
-- Utility
-function _M.from_lua(v)
+function _M.Util.FromLua(v)
if type(v) == 'string'then
return _M.String(v)
end
@@ -393,7 +395,7 @@ function _M.from_lua(v)
return v
end
-function _M.to_lua(v)
+function _M.Util.ToLua(v)
if v.type == nil then return nil, false end
if v.type == 'null' then return nil, true end
if v.type == 'call' then
@@ -411,7 +413,7 @@ function _M.to_lua(v)
return nil, false
end
-function _M.pp(s)
+function _M.Util.PP(s)
local indent = 0
local r = ''
local i = 1
@@ -448,20 +450,20 @@ function _M.pp(s)
end
-- Template Support
-function _M.declare(name, predicate_name)
+function _M.Util.Declare(name, predicate_name)
predicate_name = predicate_name or name
_M[name] = function (...)
return _M.C(predicate_name, ...)
end
return nil
end
-function _M.define(name, args, body)
+function _M.Util.Define(name, args, body)
if type(body) ~= 'string' then
body = body()
end
local args_string = table.concat(args, ' ')
- _M.declare(name)
+ _M.Util.Declare(name)
if IB == nil then
-- Not running in IronBee

0 comments on commit 09877a1

Please sign in to comment.