template<typename TFunctionType>
class LuaFunctionCaller;
+ /**
+ * Opaque type that identifies a Lua object
+ */
+ struct LuaObject {
+ LuaObject() = default;
+ LuaObject(lua_State* state, int index=-1) {
+ this->objectInRegistry = std::make_shared<LuaContext::ValueInRegistry>(state, index);
+ }
+ std::shared_ptr<LuaContext::ValueInRegistry> objectInRegistry;
+ };
+
/**
* Opaque type that identifies a Lua thread
*/
/**************************************************/
// specializations of the Pusher structure
+// opaque Lua references
+template<>
+struct LuaContext::Pusher<LuaContext::LuaObject> {
+ static const int minSize = 1;
+ static const int maxSize = 1;
+
+ static PushedObject push(lua_State* state, const LuaContext::LuaObject& value) noexcept {
+ if (value.objectInRegistry.get()) {
+ PushedObject obj = value.objectInRegistry->pop();
+ return obj;
+ } else {
+ lua_pushnil(state);
+ return PushedObject{state, 1};
+ }
+ }
+};
+
// boolean
template<>
struct LuaContext::Pusher<bool> {
/**************************************************/
// specializations of the Reader structures
+// opaque Lua references
+template<>
+struct LuaContext::Reader<LuaContext::LuaObject>
+{
+ static auto read(lua_State* state, int index)
+ -> boost::optional<LuaContext::LuaObject>
+ {
+ LuaContext::LuaObject obj(state, index);
+ return obj;
+ }
+};
+
// reading null
template<>
struct LuaContext::Reader<std::nullptr_t>
#include "rec-snmp.hh"
#include <unordered_set>
-#undef L
-#include "ext/luawrapper/include/LuaContext.hpp"
-
static int followCNAMERecords(vector<DNSRecord>& ret, const QType& qtype)
{
vector<DNSRecord> resolved;
return false; // don't block
}
-unsigned int RecursorLua4::gettag(const ComboAddress& remote, const Netmask& ednssubnet, const ComboAddress& local, const DNSName& qname, uint16_t qtype, std::vector<std::string>* policyTags, std::unordered_map<string,string>& data)
+unsigned int RecursorLua4::gettag(const ComboAddress& remote, const Netmask& ednssubnet, const ComboAddress& local, const DNSName& qname, uint16_t qtype, std::vector<std::string>* policyTags, LuaContext::LuaObject& data)
{
if(d_gettag) {
auto ret = d_gettag(remote, ednssubnet, local, qname, qtype);
}
}
}
- const auto& dataret = std::get<2>(ret);
+ const auto dataret = std::get<2>(ret);
if (dataret) {
data = *dataret;
}
class LuaContext;
+#if defined(HAVE_LUA)
+#undef L
+#include "ext/luawrapper/include/LuaContext.hpp"
+#define L theL()
+#endif
+
class RecursorLua4 : public boost::noncopyable
{
private:
string udpAnswer;
string udpCallback;
- std::unordered_map<string,string> data;
+ LuaContext::LuaObject data;
DNSName followupName;
};
- unsigned int gettag(const ComboAddress& remote, const Netmask& ednssubnet, const ComboAddress& local, const DNSName& qname, uint16_t qtype, std::vector<std::string>* policyTags, std::unordered_map<string,string>& data);
+ unsigned int gettag(const ComboAddress& remote, const Netmask& ednssubnet, const ComboAddress& local, const DNSName& qname, uint16_t qtype, std::vector<std::string>* policyTags, LuaContext::LuaObject& data);
bool prerpz(DNSQuestion& dq, int& ret);
bool preresolve(DNSQuestion& dq, int& ret);
d_postresolve);
}
- typedef std::function<std::tuple<unsigned int,boost::optional<std::unordered_map<int,string> >,boost::optional<std::unordered_map<string,string> > >(ComboAddress, Netmask, ComboAddress, DNSName,
+ typedef std::function<std::tuple<unsigned int,boost::optional<std::unordered_map<int,string> >,boost::optional<LuaContext::LuaObject> >(ComboAddress, Netmask, ComboAddress, DNSName,
uint16_t)> gettag_t;
gettag_t d_gettag; // public so you can query if we have this hooked
shared_ptr<TCPConnection> d_tcpConnection;
vector<pair<uint16_t, string> > d_ednsOpts;
std::vector<std::string> d_policyTags;
- std::unordered_map<string,string> d_data;
+ LuaContext::LuaObject d_data;
};
uint32_t qhash = 0;
bool needECS = false;
std::vector<std::string> policyTags;
- std::unordered_map<string,string> data;
+ LuaContext::LuaObject data;
#ifdef HAVE_PROTOBUF
boost::uuids::uuid uniqueId;
auto luaconfsLocal = g_luaconfs.getLocal();