-/*-
- * Copyright 2021 Vsevolod Stakhov
+/*
+ * Copyright 2023 Vsevolod Stakhov
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
template<typename T>
struct smart_ptr_hash {
using is_transparent = void; /* We want to find values in a set of shared_ptr by reference */
+ using is_avalanching = void;
auto operator()(const std::shared_ptr<T> &a) const
{
return std::hash<T>()(*a);
struct smart_str_hash {
using is_transparent = void;
- using is_avalanching = typename ankerl::unordered_dense::hash<std::string_view>::is_avalanching;
+ using is_avalanching = void;
auto operator()(const std::string &a) const
{
return ankerl::unordered_dense::hash<std::string>()(a);
lua_remove(L, err_pos);
/* Now we should have a table with results */
- if (!lua_istable(L, -1)) {
- msg_warn("require of %s.%s failed: not a table but %s", modname,
- funcname, lua_typename(L, lua_type(L, -1)));
+ if (funcname) {
+ if (!lua_istable(L, -1)) {
+ msg_warn("require of %s.%s failed: not a table but %s", modname,
+ funcname, lua_typename(L, lua_type(L, -1)));
- lua_pop(L, 1);
+ lua_pop(L, 1);
- return FALSE;
- }
+ return FALSE;
+ }
- table_pos = lua_gettop(L);
- lua_pushstring(L, funcname);
- lua_gettable(L, -2);
+ table_pos = lua_gettop(L);
+ lua_pushstring(L, funcname);
+ lua_gettable(L, -2);
+
+ if (lua_type(L, -1) == LUA_TFUNCTION) {
+ /* Remove table, preserve just a function */
+ lua_remove(L, table_pos);
+
+ return TRUE;
+ }
+ else {
+ msg_warn("require of %s.%s failed: not a function but %s", modname,
+ funcname, lua_typename(L, lua_type(L, -1)));
+ }
- if (lua_type(L, -1) == LUA_TFUNCTION) {
- /* Remove table, preserve just a function */
- lua_remove(L, table_pos);
+ lua_pop(L, 2);
+ return FALSE;
+ }
+ else if (lua_isfunction(L, -1)) {
return TRUE;
}
else {
- msg_warn("require of %s.%s failed: not a function but %s", modname,
- funcname, lua_typename(L, lua_type(L, -1)));
- }
-
- lua_pop(L, 2);
+ msg_warn("require of %s failed: not a function but %s", modname,
+ lua_typename(L, lua_type(L, -1)));
+ lua_pop(L, 1);
- return FALSE;
+ return FALSE;
+ }
}
gint rspamd_lua_function_ref_from_str(lua_State *L, const gchar *str, gsize slen,