You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

lua_ucl.h 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /*
  2. * Copyright 2023 Vsevolod Stakhov
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. /* Copyright (c) 2014, Vsevolod Stakhov
  17. * All rights reserved.
  18. *
  19. * Redistribution and use in source and binary forms, with or without
  20. * modification, are permitted provided that the following conditions are met:
  21. * * Redistributions of source code must retain the above copyright
  22. * notice, this list of conditions and the following disclaimer.
  23. * * Redistributions in binary form must reproduce the above copyright
  24. * notice, this list of conditions and the following disclaimer in the
  25. * documentation and/or other materials provided with the distribution.
  26. *
  27. * THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY
  28. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  29. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  30. * DISCLAIMED. IN NO EVENT SHALL AUTHOR BE LIABLE FOR ANY
  31. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  32. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  33. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  34. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  35. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  36. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  37. */
  38. #ifndef LUA_UCL_H_
  39. #define LUA_UCL_H_
  40. #ifdef HAVE_CONFIG_H
  41. #include "config.h"
  42. #endif
  43. #include "ucl.h"
  44. #ifdef __cplusplus
  45. extern "C" {
  46. #endif
  47. /* Include C++ guard as Lua headers miss one */
  48. #include <lua.h>
  49. #include <lauxlib.h>
  50. #include <lualib.h>
  51. /**
  52. * Closure structure for lua function storing inside UCL
  53. */
  54. struct ucl_lua_funcdata {
  55. lua_State *L;
  56. int idx;
  57. char *ret;
  58. };
  59. /**
  60. * Initialize lua UCL API
  61. */
  62. UCL_EXTERN int luaopen_ucl(lua_State *L);
  63. /**
  64. * Import UCL object from lua state
  65. * @param L lua state
  66. * @param idx index of object at the lua stack to convert to UCL
  67. * @return new UCL object or NULL, the caller should unref object after using
  68. */
  69. UCL_EXTERN ucl_object_t *ucl_object_lua_import(lua_State *L, int idx);
  70. /**
  71. * Import UCL object from lua state, escaping JSON strings
  72. * @param L lua state
  73. * @param idx index of object at the lua stack to convert to UCL
  74. * @return new UCL object or NULL, the caller should unref object after using
  75. */
  76. UCL_EXTERN ucl_object_t *ucl_object_lua_import_escape(lua_State *L, int idx);
  77. /**
  78. * Push an object to lua
  79. * @param L lua state
  80. * @param obj object to push
  81. * @param allow_array traverse over implicit arrays
  82. */
  83. UCL_EXTERN int ucl_object_push_lua(lua_State *L,
  84. const ucl_object_t *obj, bool allow_array);
  85. /**
  86. * Push an object to lua replacing all ucl.null with `false`
  87. * @param L lua state
  88. * @param obj object to push
  89. * @param allow_array traverse over implicit arrays
  90. */
  91. UCL_EXTERN int ucl_object_push_lua_filter_nil(lua_State *L,
  92. const ucl_object_t *obj,
  93. bool allow_array);
  94. UCL_EXTERN struct ucl_lua_funcdata *ucl_object_toclosure(const ucl_object_t *obj);
  95. #ifdef __cplusplus
  96. } /* extern "C" */
  97. #endif
  98. #endif /* LUA_UCL_H_ */