From 1b2c38ad13065bcf786080a15dc07201e2416d77 Mon Sep 17 00:00:00 2001 From: Otto Moerbeek Date: Fri, 16 Aug 2019 13:30:41 +0200 Subject: [PATCH] First stab at Lua pdns_features table --- pdns/lua-base4.cc | 9 ++++++ .../docs/lua-scripting/features.rst | 16 ++++++++++ .../recursordist/docs/lua-scripting/index.rst | 2 ++ regression-tests.recursor-dnssec/test_Lua.py | 31 +++++++++++++++++++ 4 files changed, 58 insertions(+) create mode 100644 pdns/recursordist/docs/lua-scripting/features.rst diff --git a/pdns/lua-base4.cc b/pdns/lua-base4.cc index a91b624b8..d643d4a2f 100644 --- a/pdns/lua-base4.cc +++ b/pdns/lua-base4.cc @@ -42,6 +42,15 @@ BaseLua4::~BaseLua4() { } void BaseLua4::prepareContext() { d_lw = std::unique_ptr(new LuaContext); + // lua features available + d_lw->writeVariable("pdns_features", + vector > > { + // Add key-values pairs below. Make sure you add string values explicity converted to string. + // e.g. { "somekey", string("stringvalue") } + // Both int and double end up as a lua number type. + { "PR8001_devicename", true }, + }); + // dnsheader d_lw->registerFunction("getID", [](dnsheader& dh) { return ntohs(dh.id); }); d_lw->registerFunction("getCD", [](dnsheader& dh) { return dh.cd; }); diff --git a/pdns/recursordist/docs/lua-scripting/features.rst b/pdns/recursordist/docs/lua-scripting/features.rst new file mode 100644 index 000000000..2000bcd82 --- /dev/null +++ b/pdns/recursordist/docs/lua-scripting/features.rst @@ -0,0 +1,16 @@ +Checking available features +=========================== +.. versionadded:: 4.3.0 + +To check if a Lua features is available, consult the global +``pdns_features`` table. This table contains string keys with a values +of type boolean, string or number. If a key is absent the value will +evaluate to ``nil``, indicating the feature is not available. + +Currently, the following keys are defined: + +.. code-block:: Lua + + pdns_feature["PR8001_devicename"] = true + + diff --git a/pdns/recursordist/docs/lua-scripting/index.rst b/pdns/recursordist/docs/lua-scripting/index.rst index 12448fc8e..45f0ddc90 100644 --- a/pdns/recursordist/docs/lua-scripting/index.rst +++ b/pdns/recursordist/docs/lua-scripting/index.rst @@ -26,3 +26,5 @@ For extra performance, a Just In Time compiled version of Lua called `LuaJIT