]> granicus.if.org Git - jq/commitdiff
error() function
authorStephen Dolan <mu@netsoc.tcd.ie>
Mon, 10 Dec 2012 22:30:09 +0000 (22:30 +0000)
committerStephen Dolan <mu@netsoc.tcd.ie>
Mon, 10 Dec 2012 22:30:09 +0000 (22:30 +0000)
builtin.c

index b572dfaf2d26e6b60941e90170b1117fcb68c606..f046e91a58adbf29b3da804197c78fcc253426c4 100644 (file)
--- a/builtin.c
+++ b/builtin.c
@@ -41,7 +41,6 @@ static jv type_error2(jv bad1, jv bad2, const char* msg) {
   return err;
 }
 
-
 static jv f_plus(jv input, jv a, jv b) {
   jv_free(input);
   if (jv_get_kind(a) == JV_KIND_NUMBER && jv_get_kind(b) == JV_KIND_NUMBER) {
@@ -297,6 +296,13 @@ static jv f_type(jv input) {
   return out;
 }
 
+static jv f_error(jv input, jv msg) {
+  jv_free(input);
+  msg = f_tostring(msg);
+  return jv_invalid_with_msg(msg);
+}
+
+
 static struct cfunction function_list[] = {
   {(cfunction_ptr)f_plus, "_plus", 3},
   {(cfunction_ptr)f_minus, "_minus", 3},
@@ -322,6 +328,7 @@ static struct cfunction function_list[] = {
   {(cfunction_ptr)f_max, "max", 1},
   {(cfunction_ptr)f_min_by_impl, "_min_by_impl", 2},
   {(cfunction_ptr)f_max_by_impl, "_max_by_impl", 2},
+  {(cfunction_ptr)f_error, "error", 2},
 };
 
 static struct symbol_table cbuiltins =