14bf54857SBaptiste Daroussin /* Copyright (c) 2014, Vsevolod Stakhov 24bf54857SBaptiste Daroussin * All rights reserved. 34bf54857SBaptiste Daroussin * 44bf54857SBaptiste Daroussin * Redistribution and use in source and binary forms, with or without 54bf54857SBaptiste Daroussin * modification, are permitted provided that the following conditions are met: 64bf54857SBaptiste Daroussin * * Redistributions of source code must retain the above copyright 74bf54857SBaptiste Daroussin * notice, this list of conditions and the following disclaimer. 84bf54857SBaptiste Daroussin * * Redistributions in binary form must reproduce the above copyright 94bf54857SBaptiste Daroussin * notice, this list of conditions and the following disclaimer in the 104bf54857SBaptiste Daroussin * documentation and/or other materials provided with the distribution. 114bf54857SBaptiste Daroussin * 124bf54857SBaptiste Daroussin * THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY 134bf54857SBaptiste Daroussin * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 144bf54857SBaptiste Daroussin * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 154bf54857SBaptiste Daroussin * DISCLAIMED. IN NO EVENT SHALL AUTHOR BE LIABLE FOR ANY 164bf54857SBaptiste Daroussin * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 174bf54857SBaptiste Daroussin * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 184bf54857SBaptiste Daroussin * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 194bf54857SBaptiste Daroussin * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 204bf54857SBaptiste Daroussin * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 214bf54857SBaptiste Daroussin * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 224bf54857SBaptiste Daroussin */ 234bf54857SBaptiste Daroussin #ifndef LUA_UCL_H_ 244bf54857SBaptiste Daroussin #define LUA_UCL_H_ 254bf54857SBaptiste Daroussin 264bf54857SBaptiste Daroussin #ifdef HAVE_CONFIG_H 274bf54857SBaptiste Daroussin #include "config.h" 284bf54857SBaptiste Daroussin #endif 294bf54857SBaptiste Daroussin 304bf54857SBaptiste Daroussin #include <lua.h> 314bf54857SBaptiste Daroussin #include <lauxlib.h> 324bf54857SBaptiste Daroussin #include <lualib.h> 334bf54857SBaptiste Daroussin #include "ucl.h" 344bf54857SBaptiste Daroussin 354bf54857SBaptiste Daroussin /** 364bf54857SBaptiste Daroussin * Closure structure for lua function storing inside UCL 374bf54857SBaptiste Daroussin */ 384bf54857SBaptiste Daroussin struct ucl_lua_funcdata { 394bf54857SBaptiste Daroussin lua_State *L; 404bf54857SBaptiste Daroussin int idx; 414bf54857SBaptiste Daroussin char *ret; 424bf54857SBaptiste Daroussin }; 434bf54857SBaptiste Daroussin 444bf54857SBaptiste Daroussin /** 454bf54857SBaptiste Daroussin * Initialize lua UCL API 464bf54857SBaptiste Daroussin */ 474bf54857SBaptiste Daroussin UCL_EXTERN int luaopen_ucl (lua_State *L); 484bf54857SBaptiste Daroussin 494bf54857SBaptiste Daroussin /** 504bf54857SBaptiste Daroussin * Import UCL object from lua state 514bf54857SBaptiste Daroussin * @param L lua state 524bf54857SBaptiste Daroussin * @param idx index of object at the lua stack to convert to UCL 534bf54857SBaptiste Daroussin * @return new UCL object or NULL, the caller should unref object after using 544bf54857SBaptiste Daroussin */ 554bf54857SBaptiste Daroussin UCL_EXTERN ucl_object_t* ucl_object_lua_import (lua_State *L, int idx); 564bf54857SBaptiste Daroussin 574bf54857SBaptiste Daroussin /** 58*a0409676SBaptiste Daroussin * Import UCL object from lua state, escaping JSON strings 59*a0409676SBaptiste Daroussin * @param L lua state 60*a0409676SBaptiste Daroussin * @param idx index of object at the lua stack to convert to UCL 61*a0409676SBaptiste Daroussin * @return new UCL object or NULL, the caller should unref object after using 62*a0409676SBaptiste Daroussin */ 63*a0409676SBaptiste Daroussin UCL_EXTERN ucl_object_t* ucl_object_lua_import_escape (lua_State *L, int idx); 64*a0409676SBaptiste Daroussin 65*a0409676SBaptiste Daroussin /** 664bf54857SBaptiste Daroussin * Push an object to lua 674bf54857SBaptiste Daroussin * @param L lua state 684bf54857SBaptiste Daroussin * @param obj object to push 694bf54857SBaptiste Daroussin * @param allow_array traverse over implicit arrays 704bf54857SBaptiste Daroussin */ 714bf54857SBaptiste Daroussin UCL_EXTERN int ucl_object_push_lua (lua_State *L, 724bf54857SBaptiste Daroussin const ucl_object_t *obj, bool allow_array); 73*a0409676SBaptiste Daroussin /** 74*a0409676SBaptiste Daroussin * Push an object to lua replacing all ucl.null with `false` 75*a0409676SBaptiste Daroussin * @param L lua state 76*a0409676SBaptiste Daroussin * @param obj object to push 77*a0409676SBaptiste Daroussin * @param allow_array traverse over implicit arrays 78*a0409676SBaptiste Daroussin */ 79*a0409676SBaptiste Daroussin UCL_EXTERN int ucl_object_push_lua_filter_nil (lua_State *L, 80*a0409676SBaptiste Daroussin const ucl_object_t *obj, 81*a0409676SBaptiste Daroussin bool allow_array); 824bf54857SBaptiste Daroussin 83*a0409676SBaptiste Daroussin UCL_EXTERN struct ucl_lua_funcdata* ucl_object_toclosure (const ucl_object_t *obj); 844bf54857SBaptiste Daroussin 854bf54857SBaptiste Daroussin #endif /* LUA_UCL_H_ */ 86