lua_setmetatable (L, -2);
}
+static inline enum ucl_parse_type
+lua_ucl_str_to_parse_type (const char *str)
+{
+ enum ucl_parse_type type = UCL_PARSE_UCL;
+
+ if (str != NULL) {
+ if (strcasecmp (str, "msgpack") == 0) {
+ type = UCL_PARSE_MSGPACK;
+ }
+ else if (strcasecmp (str, "sexp") == 0 ||
+ strcasecmp (str, "csexp") == 0) {
+ type = UCL_PARSE_CSEXP;
+ }
+ }
+
+ return type;
+}
+
/***
* @method parser:parse_file(name)
* Parse UCL object from file.
struct ucl_parser *parser;
const char *string;
size_t llen;
+ enum ucl_parse_type type = UCL_PARSE_UCL;
int ret = 2;
parser = lua_ucl_parser_get (L, 1);
string = luaL_checklstring (L, 2, &llen);
+ if (lua_type (L, 3) == LUA_TSTRING) {
+ type = lua_ucl_str_to_parse_type (lua_tostring (L, 3));
+ }
+
if (parser != NULL && string != NULL) {
- if (ucl_parser_add_chunk (parser, (const unsigned char *)string, llen)) {
+ if (ucl_parser_add_chunk_full (parser, (const unsigned char *)string,
+ llen, 0, UCL_DUPLICATE_APPEND, type)) {
lua_pushboolean (L, true);
ret = 1;
}
return 1;
}
+static inline enum ucl_emitter
+lua_ucl_str_to_emit_type (const char *strtype)
+{
+ enum ucl_emitter format = UCL_EMIT_JSON_COMPACT;
+
+ if (strcasecmp (strtype, "json") == 0) {
+ format = UCL_EMIT_JSON;
+ }
+ else if (strcasecmp (strtype, "json-compact") == 0) {
+ format = UCL_EMIT_JSON_COMPACT;
+ }
+ else if (strcasecmp (strtype, "yaml") == 0) {
+ format = UCL_EMIT_YAML;
+ }
+ else if (strcasecmp (strtype, "config") == 0 ||
+ strcasecmp (strtype, "ucl") == 0) {
+ format = UCL_EMIT_CONFIG;
+ }
+
+ return format;
+}
+
/***
* @method object:tostring(type)
* Unwraps opaque ucl object to string (json by default). Optionally you can
if (lua_type (L, 2) == LUA_TSTRING) {
const char *strtype = lua_tostring (L, 2);
- if (strcasecmp (strtype, "json") == 0) {
- format = UCL_EMIT_JSON;
- }
- else if (strcasecmp (strtype, "json-compact") == 0) {
- format = UCL_EMIT_JSON_COMPACT;
- }
- else if (strcasecmp (strtype, "yaml") == 0) {
- format = UCL_EMIT_YAML;
- }
- else if (strcasecmp (strtype, "config") == 0 ||
- strcasecmp (strtype, "ucl") == 0) {
- format = UCL_EMIT_CONFIG;
- }
+ format = lua_ucl_str_to_emit_type (strtype);
}
}
strcasecmp (strtype, "ucl") == 0) {
format = UCL_EMIT_CONFIG;
}
+ else if (strcasecmp (strtype, "msgpack") == 0) {
+ format = UCL_EMIT_MSGPACK;
+ }
}
}