Lines Matching +full:json +full:- +full:schema
47 local got = ucl.to_format(obj, 'json')
60 -- Output:
61 --[[
66 --]]
104 lua_settable (L, -3); in ucl_object_lua_push_element()
112 luaL_unref (fd->L, LUA_REGISTRYINDEX, fd->idx); in lua_ucl_userdata_dtor()
113 if (fd->ret != NULL) { in lua_ucl_userdata_dtor()
114 free (fd->ret); in lua_ucl_userdata_dtor()
125 lua_rawgeti (fd->L, LUA_REGISTRYINDEX, fd->idx); in lua_ucl_userdata_emitter()
127 lua_pcall (fd->L, 0, 1, 0); in lua_ucl_userdata_emitter()
128 out = lua_tostring (fd->L, -1); in lua_ucl_userdata_emitter()
132 if (fd->ret) { in lua_ucl_userdata_emitter()
133 free (fd->ret); in lua_ucl_userdata_emitter()
135 fd->ret = strdup (out); in lua_ucl_userdata_emitter()
138 lua_settop (fd->L, 0); in lua_ucl_userdata_emitter()
140 return fd->ret; in lua_ucl_userdata_emitter()
156 if ((flags & LUA_UCL_ALLOW_ARRAY) && obj->next != NULL) { in ucl_object_lua_push_object()
161 lua_createtable (L, 0, obj->len); in ucl_object_lua_push_object()
169 lua_setmetatable (L, -2); in ucl_object_lua_push_object()
187 if (obj->type == UCL_ARRAY) { in ucl_object_lua_push_array()
188 nelt = obj->len; in ucl_object_lua_push_array()
194 lua_rawseti (L, -2, i); in ucl_object_lua_push_array()
199 lua_setmetatable (L, -2); in ucl_object_lua_push_array()
213 lua_rawseti (L, -2, i); in ucl_object_lua_push_array()
218 lua_setmetatable (L, -2); in ucl_object_lua_push_array()
233 if ((flags & LUA_UCL_ALLOW_ARRAY) && obj->next != NULL) { in ucl_object_lua_push_scalar()
238 switch (obj->type) { in ucl_object_lua_push_scalar()
265 fd = (struct ucl_lua_funcdata *)obj->value.ud; in ucl_object_lua_push_scalar()
266 lua_rawgeti (L, LUA_REGISTRYINDEX, fd->idx); in ucl_object_lua_push_scalar()
279 switch (obj->type) { in ucl_object_push_lua_common()
294 * - *scalar* values are directly presented by lua objects
295 * - *userdata* values are converted to lua function objects using `LUA_REGISTRYINDEX`,
296 * this can be used to pass functions from lua to c and vice-versa
297 * - *arrays* are converted to lua tables with numeric indicies suitable for `ipairs` iterations
298 * - *objects* are converted to lua tables with string indicies
342 if (lua_type (L, -1) == LUA_TSTRING) { in ucl_object_lua_fromtable()
343 const char *classname = lua_tostring (L, -1); in ucl_object_lua_fromtable()
378 lua_pushvalue (L, -2); in ucl_object_lua_fromtable()
380 if (lua_type (L, -1) == LUA_TNUMBER) { in ucl_object_lua_fromtable()
381 double num = lua_tonumber (L, -1); in ucl_object_lua_fromtable()
438 lua_pushvalue (L, -2); in ucl_object_lua_fromtable()
439 k = lua_tolstring (L, -1, &keylen); in ucl_object_lua_fromtable()
440 obj = ucl_object_lua_fromelt (L, lua_gettop (L) - 1, flags); in ucl_object_lua_fromtable()
446 if (cur->keylen == 0) { in ucl_object_lua_fromtable()
447 cur->keylen = obj->keylen; in ucl_object_lua_fromtable()
448 cur->key = obj->key; in ucl_object_lua_fromtable()
509 if (lua_isfunction (L, -1)) { in ucl_object_lua_fromelt()
526 fd->L = L; in ucl_object_lua_fromelt()
527 fd->ret = NULL; in ucl_object_lua_fromelt()
528 fd->idx = luaL_ref (L, LUA_REGISTRYINDEX); in ucl_object_lua_fromelt()
571 * Extracts ucl object from lua variable at `idx` position escaping JSON strings
634 lua_setmetatable (L, -2); in lua_ucl_parser_init()
659 lua_setmetatable (L, -2); in lua_ucl_push_opaque()
695 -- Do something with object
779 lua_pushvalue (L, -2); in lua_ucl_parser_register_variables()
780 name = luaL_checkstring (L, -1); in lua_ucl_parser_register_variables()
781 value = luaL_checkstring (L, -2); in lua_ucl_parser_register_variables()
865 if (ucl_parser_add_chunk_full (parser, (const unsigned char *)t->start, in lua_ucl_parser_parse_text()
866 t->len, 0, UCL_DUPLICATE_APPEND, type)) { in lua_ucl_parser_parse_text()
937 * @method parser:validate(schema)
938 * Validates the top object in the parser against schema. Schema might be
939 * another object or a string that represents file to load schema from.
941 * @param {string/table} schema input schema
949 ucl_object_t *schema; in lua_ucl_parser_validate() local
955 if (parser && parser->top_obj) { in lua_ucl_parser_validate()
957 schema = ucl_object_lua_import (L, 2); in lua_ucl_parser_validate()
959 if (schema == NULL) { in lua_ucl_parser_validate()
961 lua_pushstring (L, "cannot load schema from lua table"); in lua_ucl_parser_validate()
972 lua_pushfstring (L, "cannot parse schema file \"%s\": " in lua_ucl_parser_validate()
979 schema = ucl_parser_get_object (schema_parser); in lua_ucl_parser_validate()
984 lua_pushstring (L, "invalid schema argument"); in lua_ucl_parser_validate()
989 if (!ucl_object_validate (schema, parser->top_obj, &err)) { in lua_ucl_parser_validate()
999 ucl_object_unref (schema); in lua_ucl_parser_validate()
1047 if (strcasecmp (strtype, "json") == 0) { in lua_ucl_str_to_emit_type()
1050 else if (strcasecmp (strtype, "json-compact") == 0) { in lua_ucl_str_to_emit_type()
1066 * Unwraps opaque ucl object to string (json by default). Optionally you can
1069 * - `json` - fine printed json
1070 * - `json-compact` - compacted json
1071 * - `config` - fine printed configuration
1072 * - `ucl` - same as `config`
1073 * - `yaml` - embedded yaml
1104 * @method object:validate(schema[, path[, ext_refs]])
1105 * Validates the given ucl object using schema object represented as another
1107 * specify the specific schema element to perform validation.
1109 * @param {ucl.object} schema schema object
1118 ucl_object_t *obj, *schema, *ext_refs = NULL; in lua_ucl_object_validate() local
1125 schema = lua_ucl_object_get (L, 2); in lua_ucl_object_validate()
1127 if (schema && obj && ucl_object_type (schema) == UCL_OBJECT) { in lua_ucl_object_validate()
1151 schema_elt = ucl_object_lookup_path_char (schema, path, '/'); in lua_ucl_object_validate()
1155 schema_elt = schema; in lua_ucl_object_validate()
1159 res = ucl_object_validate_root_ext (schema_elt, obj, schema, in lua_ucl_object_validate()
1191 lua_pushstring (L, "invalid object or schema"); in lua_ucl_object_validate()
1218 lua_pushvalue(L, -1); in lua_ucl_parser_mt()
1219 lua_setfield(L, -2, "__index"); in lua_ucl_parser_mt()
1222 lua_setfield (L, -2, "__gc"); in lua_ucl_parser_mt()
1225 lua_setfield (L, -2, "parse_file"); in lua_ucl_parser_mt()
1228 lua_setfield (L, -2, "parse_string"); in lua_ucl_parser_mt()
1231 lua_setfield (L, -2, "parse_text"); in lua_ucl_parser_mt()
1234 lua_setfield (L, -2, "register_variable"); in lua_ucl_parser_mt()
1237 lua_setfield (L, -2, "register_variables"); in lua_ucl_parser_mt()
1240 lua_setfield (L, -2, "get_object"); in lua_ucl_parser_mt()
1243 lua_setfield (L, -2, "get_object_wrapped"); in lua_ucl_parser_mt()
1246 lua_setfield (L, -2, "validate"); in lua_ucl_parser_mt()
1256 lua_pushvalue(L, -1); in lua_ucl_object_mt()
1257 lua_setfield(L, -2, "__index"); in lua_ucl_object_mt()
1260 lua_setfield (L, -2, "__gc"); in lua_ucl_object_mt()
1263 lua_setfield (L, -2, "__tostring"); in lua_ucl_object_mt()
1266 lua_setfield (L, -2, "tostring"); in lua_ucl_object_mt()
1269 lua_setfield (L, -2, "unwrap"); in lua_ucl_object_mt()
1272 lua_setfield (L, -2, "tolua"); in lua_ucl_object_mt()
1275 lua_setfield (L, -2, "validate"); in lua_ucl_object_mt()
1278 lua_setfield (L, -2, "class"); in lua_ucl_object_mt()
1289 lua_setfield (L, -2, "__tostring"); in lua_ucl_types_mt()
1292 lua_setfield (L, -2, "tostring"); in lua_ucl_types_mt()
1295 lua_setfield (L, -2, "class"); in lua_ucl_types_mt()
1302 lua_setfield (L, -2, "__tostring"); in lua_ucl_types_mt()
1305 lua_setfield (L, -2, "tostring"); in lua_ucl_types_mt()
1308 lua_setfield (L, -2, "class"); in lua_ucl_types_mt()
1315 lua_setfield (L, -2, "__tostring"); in lua_ucl_types_mt()
1318 lua_setfield (L, -2, "tostring"); in lua_ucl_types_mt()
1321 lua_setfield (L, -2, "class"); in lua_ucl_types_mt()
1371 * - `json` - fine printed json
1372 * - `json-compact` - compacted json
1373 * - `config` - fine printed configuration
1374 * - `ucl` - same as `config`
1375 * - `yaml` - embedded yaml
1393 -- Output:
1394 --[[
1399 --]]
1419 if (strcasecmp (strtype, "json") == 0) { in lua_ucl_to_format()
1422 else if (strcasecmp (strtype, "json-compact") == 0) { in lua_ucl_to_format()
1475 lua_setfield (L, -2, "__tostring"); in lua_ucl_null_mt()
1491 lua_setfield (L, -2, "__mode"); in luaopen_ucl()
1492 lua_pushvalue (L, -1); /* tbl, tbl */ in luaopen_ucl()
1493 lua_setmetatable (L, -2); /* tbl */ in luaopen_ucl()
1499 lua_setfield (L, -2, "parser"); in luaopen_ucl()
1502 lua_setfield (L, -2, "to_json"); in luaopen_ucl()
1505 lua_setfield (L, -2, "to_config"); in luaopen_ucl()
1508 lua_setfield (L, -2, "to_format"); in luaopen_ucl()
1512 lua_setmetatable (L, -2); in luaopen_ucl()
1514 lua_pushvalue (L, -1); in luaopen_ucl()
1517 lua_setfield (L, -2, "null"); in luaopen_ucl()
1525 if (obj == NULL || obj->type != UCL_USERDATA) { in ucl_object_toclosure()
1529 return (struct ucl_lua_funcdata*)obj->value.ud; in ucl_object_toclosure()