diff options
author | Vsevolod Stakhov <vsevolod@rspamd.com> | 2024-08-14 12:27:40 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@rspamd.com> | 2024-08-14 12:27:40 +0100 |
commit | 42e82de2d4e0eb8f6a107dd344e3e6186411828b (patch) | |
tree | 685d3e89cbf9a59fe47e2ffafce5890770e7c791 /contrib/libucl | |
parent | 042490e8dc102635c02d2caeb195bddf83f58054 (diff) | |
download | rspamd-42e82de2d4e0eb8f6a107dd344e3e6186411828b.tar.gz rspamd-42e82de2d4e0eb8f6a107dd344e3e6186411828b.zip |
[Project] Add API method to push unwrapped UCL object
Diffstat (limited to 'contrib/libucl')
-rw-r--r-- | contrib/libucl/lua_ucl.c | 17 | ||||
-rw-r--r-- | contrib/libucl/lua_ucl.h | 9 |
2 files changed, 16 insertions, 10 deletions
diff --git a/contrib/libucl/lua_ucl.c b/contrib/libucl/lua_ucl.c index 79c658615..0bcbf025a 100644 --- a/contrib/libucl/lua_ucl.c +++ b/contrib/libucl/lua_ucl.c @@ -699,8 +699,7 @@ lua_ucl_object_get(lua_State *L, int index) return *((ucl_object_t **) luaL_checkudata(L, index, OBJECT_META)); } -static void -lua_ucl_push_opaque(lua_State *L, const ucl_object_t *obj) +void ucl_object_push_lua_unwrapped(lua_State *L, const ucl_object_t *obj) { ucl_object_t **pobj; @@ -986,7 +985,7 @@ lua_ucl_parser_get_object_wrapped(lua_State *L) obj = ucl_parser_get_object(parser); if (obj != NULL) { - lua_ucl_push_opaque(L, obj); + ucl_object_push_lua_unwrapped(L, obj); ucl_object_unref(obj); } else { @@ -1233,7 +1232,7 @@ lua_ucl_object_validate(lua_State *L) lua_pushnil(L); if (ext_refs) { - lua_ucl_push_opaque(L, ext_refs); + ucl_object_push_lua_unwrapped(L, ext_refs); ucl_object_unref(ext_refs); } } @@ -1242,7 +1241,7 @@ lua_ucl_object_validate(lua_State *L) lua_pushfstring(L, "validation error: %s", err.msg); if (ext_refs) { - lua_ucl_push_opaque(L, ext_refs); + ucl_object_push_lua_unwrapped(L, ext_refs); ucl_object_unref(ext_refs); } } @@ -1253,7 +1252,7 @@ lua_ucl_object_validate(lua_State *L) lua_pushfstring(L, "cannot find the requested path: %s", path); if (ext_refs) { - lua_ucl_push_opaque(L, ext_refs); + ucl_object_push_lua_unwrapped(L, ext_refs); ucl_object_unref(ext_refs); } } @@ -1314,7 +1313,7 @@ lua_ucl_index(lua_State *L) elt = ucl_object_lookup_len(obj, key, strlen(key)); if (elt) { - lua_ucl_push_opaque(L, elt); + ucl_object_push_lua_unwrapped(L, elt); } else { lua_pushnil(L); @@ -1336,7 +1335,7 @@ lua_ucl_index(lua_State *L) elt = ucl_array_find_index(obj, idx); if (elt) { - lua_ucl_push_opaque(L, elt); + ucl_object_push_lua_unwrapped(L, elt); } else { lua_pushnil(L); @@ -1468,7 +1467,7 @@ lua_ucl_object_iter(lua_State *L) lua_pushnumber(L, -1); } } - lua_ucl_push_opaque(L, cur); + ucl_object_push_lua_unwrapped(L, cur); return 2; } diff --git a/contrib/libucl/lua_ucl.h b/contrib/libucl/lua_ucl.h index 4a759e3b4..fe3d86dfd 100644 --- a/contrib/libucl/lua_ucl.h +++ b/contrib/libucl/lua_ucl.h @@ -1,5 +1,5 @@ /* - * Copyright 2023 Vsevolod Stakhov + * Copyright 2024 Vsevolod Stakhov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -91,6 +91,13 @@ UCL_EXTERN ucl_object_t *ucl_object_lua_import_escape(lua_State *L, int idx); */ UCL_EXTERN int ucl_object_push_lua(lua_State *L, const ucl_object_t *obj, bool allow_array); + +/** + * Push an object to lua as userdata object (handling one refcount) + * @param L + * @param obj + */ +UCL_EXTERN void ucl_object_push_lua_unwrapped(lua_State *L, const ucl_object_t *obj); /** * Push an object to lua replacing all ucl.null with `false` * @param L lua state |