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);
-static ucl_object_t* ucl_object_lua_fromelt (lua_State *L, int idx);
+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;
* @param idx
*/
static ucl_object_t *
-ucl_object_lua_fromtable (lua_State *L, int idx)
+ucl_object_lua_fromtable (lua_State *L, int idx, ucl_string_flags_t flags)
{
ucl_object_t *obj, *top = NULL;
size_t keylen;
for (i = 1; i <= max; i ++) {
lua_pushinteger (L, i);
lua_gettable (L, idx);
- obj = ucl_object_lua_fromelt (L, lua_gettop (L));
+ obj = ucl_object_lua_fromelt (L, lua_gettop (L), flags);
if (obj != NULL) {
ucl_array_append (top, obj);
}
while (lua_next (L, idx) != 0) {
/* copy key to avoid modifications */
k = lua_tolstring (L, -2, &keylen);
- obj = ucl_object_lua_fromelt (L, lua_gettop (L));
+ obj = ucl_object_lua_fromelt (L, lua_gettop (L), flags);
if (obj != NULL) {
ucl_object_insert_key (top, obj, k, keylen, true);
* @param idx
*/
static ucl_object_t *
-ucl_object_lua_fromelt (lua_State *L, int idx)
+ucl_object_lua_fromelt (lua_State *L, int idx, ucl_string_flags_t flags)
{
int type;
double num;
ucl_object_t *obj = NULL;
struct ucl_lua_funcdata *fd;
+ const char *str;
+ size_t sz;
type = lua_type (L, idx);
switch (type) {
case LUA_TSTRING:
- obj = ucl_object_fromstring_common (lua_tostring (L, idx), 0, 0);
+ str = lua_tolstring (L, idx, &sz);
+
+ if (str) {
+ obj = ucl_object_fromstring_common (str, sz, flags);
+ }
+ else {
+ obj = ucl_object_typed_new (UCL_NULL);
+ }
break;
case LUA_TNUMBER:
num = lua_tonumber (L, idx);
lua_insert (L, 1); /* func, gen, obj */
lua_insert (L, 2); /* func, obj, gen */
lua_call(L, 2, 1);
- obj = ucl_object_lua_fromelt (L, 1);
+ obj = ucl_object_lua_fromelt (L, 1, flags);
}
lua_pop (L, 2);
}
else {
if (type == LUA_TTABLE) {
- obj = ucl_object_lua_fromtable (L, idx);
+ obj = ucl_object_lua_fromtable (L, idx, flags);
}
else if (type == LUA_TFUNCTION) {
fd = malloc (sizeof (*fd));
t = lua_type (L, idx);
switch (t) {
case LUA_TTABLE:
- obj = ucl_object_lua_fromtable (L, idx);
+ obj = ucl_object_lua_fromtable (L, idx, 0);
+ break;
+ default:
+ obj = ucl_object_lua_fromelt (L, idx, 0);
+ break;
+ }
+
+ return obj;
+}
+
+/**
+ * @function ucl_object_lua_import_escape(L, idx)
+ * Extracts ucl object from lua variable at `idx` position escaping JSON strings
+ * @see ucl_object_push_lua for conversion definitions
+ * @param {lua_state} L lua state machine pointer
+ * @param {int} idx index where the source variable is placed
+ * @return {ucl_object_t} new ucl object extracted from lua variable. Reference count of this object is 1,
+ * this object thus needs to be unref'ed after usage.
+ */
+ucl_object_t *
+ucl_object_lua_import_escape (lua_State *L, int idx)
+{
+ ucl_object_t *obj;
+ int t;
+
+ t = lua_type (L, idx);
+ switch (t) {
+ case LUA_TTABLE:
+ obj = ucl_object_lua_fromtable (L, idx, UCL_STRING_ESCAPE);
break;
default:
- obj = ucl_object_lua_fromelt (L, idx);
+ obj = ucl_object_lua_fromelt (L, idx, UCL_STRING_ESCAPE);
break;
}