Config-UCL
view release on metacpan or search on metacpan
libucl-0.8.1/lua/lua_ucl.c view on Meta::CPAN
/* Copyright (c) 2014, Vsevolod Stakhov
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL AUTHOR BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @file lua ucl bindings
*/
#include "ucl.h"
#include "ucl_internal.h"
#include "lua_ucl.h"
#include <strings.h>
/***
* @module ucl
* This lua module allows to parse objects from strings and to store data into
* ucl objects. It uses `libucl` C library to parse and manipulate with ucl objects.
* @example
local ucl = require("ucl")
local parser = ucl.parser()
local res,err = parser:parse_string('{key=value}')
if not res then
print('parser error: ' .. err)
else
local obj = parser:get_object()
local got = ucl.to_format(obj, 'json')
endif
local table = {
str = 'value',
num = 100500,
null = ucl.null,
func = function ()
return 'huh'
end
}
print(ucl.to_format(table, 'ucl'))
-- Output:
--[[
num = 100500;
str = "value";
null = null;
func = "huh";
--]]
*/
#define PARSER_META "ucl.parser.meta"
#define EMITTER_META "ucl.emitter.meta"
#define NULL_META "ucl.null.meta"
#define OBJECT_META "ucl.object.meta"
#define UCL_OBJECT_TYPE_META "ucl.type.object"
#define UCL_ARRAY_TYPE_META "ucl.type.array"
#define UCL_IMPL_ARRAY_TYPE_META "ucl.type.impl_array"
static int ucl_object_lua_push_array (lua_State *L, const ucl_object_t *obj);
static int ucl_object_lua_push_scalar (lua_State *L, const ucl_object_t *obj, bool allow_array);
static ucl_object_t* ucl_object_lua_fromtable (lua_State *L, int idx, ucl_string_flags_t flags);
static ucl_object_t* ucl_object_lua_fromelt (lua_State *L, int idx, ucl_string_flags_t flags);
static void *ucl_null;
/**
* Push a single element of an object to lua
* @param L
* @param key
* @param obj
*/
static void
ucl_object_lua_push_element (lua_State *L, const char *key,
const ucl_object_t *obj)
{
lua_pushstring (L, key);
ucl_object_push_lua (L, obj, true);
lua_settable (L, -3);
}
( run in 0.942 second using v1.01-cache-2.11-cpan-437f7b0c052 )