10Sstevel@tonic-gate/* Copyright (c) 2014, Vsevolod Stakhov
20Sstevel@tonic-gate * All rights reserved.
30Sstevel@tonic-gate *
40Sstevel@tonic-gate * Redistribution and use in source and binary forms, with or without
57492SZhigang.Lu@Sun.COM * modification, are permitted provided that the following conditions are met:
67492SZhigang.Lu@Sun.COM *       * Redistributions of source code must retain the above copyright
70Sstevel@tonic-gate *         notice, this list of conditions and the following disclaimer.
80Sstevel@tonic-gate *       * Redistributions in binary form must reproduce the above copyright
90Sstevel@tonic-gate *         notice, this list of conditions and the following disclaimer in the
100Sstevel@tonic-gate *         documentation and/or other materials provided with the distribution.
110Sstevel@tonic-gate *
120Sstevel@tonic-gate * THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY
130Sstevel@tonic-gate * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
140Sstevel@tonic-gate * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
150Sstevel@tonic-gate * DISCLAIMED. IN NO EVENT SHALL AUTHOR BE LIABLE FOR ANY
160Sstevel@tonic-gate * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
170Sstevel@tonic-gate * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
180Sstevel@tonic-gate * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
190Sstevel@tonic-gate * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
200Sstevel@tonic-gate * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
210Sstevel@tonic-gate * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
227492SZhigang.Lu@Sun.COM */
230Sstevel@tonic-gate#ifndef LUA_UCL_H_
240Sstevel@tonic-gate#define LUA_UCL_H_
250Sstevel@tonic-gate
260Sstevel@tonic-gate#ifdef HAVE_CONFIG_H
270Sstevel@tonic-gate#include "config.h"
280Sstevel@tonic-gate#endif
290Sstevel@tonic-gate
300Sstevel@tonic-gate#include <lua.h>
310Sstevel@tonic-gate#include <lauxlib.h>
320Sstevel@tonic-gate#include <lualib.h>
330Sstevel@tonic-gate#include "ucl.h"
340Sstevel@tonic-gate
350Sstevel@tonic-gate/**
360Sstevel@tonic-gate * Closure structure for lua function storing inside UCL
370Sstevel@tonic-gate */
380Sstevel@tonic-gatestruct ucl_lua_funcdata {
390Sstevel@tonic-gate	lua_State *L;
400Sstevel@tonic-gate	int idx;
410Sstevel@tonic-gate	char *ret;
420Sstevel@tonic-gate};
430Sstevel@tonic-gate
440Sstevel@tonic-gate/**
450Sstevel@tonic-gate * Initialize lua UCL API
460Sstevel@tonic-gate */
470Sstevel@tonic-gateUCL_EXTERN int luaopen_ucl (lua_State *L);
480Sstevel@tonic-gate
490Sstevel@tonic-gate/**
500Sstevel@tonic-gate * Import UCL object from lua state
510Sstevel@tonic-gate * @param L lua state
520Sstevel@tonic-gate * @param idx index of object at the lua stack to convert to UCL
530Sstevel@tonic-gate * @return new UCL object or NULL, the caller should unref object after using
540Sstevel@tonic-gate */
550Sstevel@tonic-gateUCL_EXTERN ucl_object_t* ucl_object_lua_import (lua_State *L, int idx);
560Sstevel@tonic-gate
570Sstevel@tonic-gate/**
580Sstevel@tonic-gate * Push an object to lua
590Sstevel@tonic-gate * @param L lua state
600Sstevel@tonic-gate * @param obj object to push
610Sstevel@tonic-gate * @param allow_array traverse over implicit arrays
620Sstevel@tonic-gate */
630Sstevel@tonic-gateUCL_EXTERN int ucl_object_push_lua (lua_State *L,
640Sstevel@tonic-gate		const ucl_object_t *obj, bool allow_array);
650Sstevel@tonic-gate
660Sstevel@tonic-gateUCL_EXTERN struct ucl_lua_funcdata* ucl_object_toclosure (
670Sstevel@tonic-gate		const ucl_object_t *obj);
68
69#endif /* LUA_UCL_H_ */
70