summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--eval.c4
-rw-r--r--lexer.h3
-rw-r--r--lib.c4
3 files changed, 6 insertions, 5 deletions
diff --git a/eval.c b/eval.c
index 8860078..c55cbb7 100644
--- a/eval.c
+++ b/eval.c
@@ -811,7 +811,7 @@ ut_invoke(struct ut_state *state, struct ut_opcode *op, struct json_object *scop
return NULL;
/* is native function */
- if (json_object_get_boolean(func)) {
+ if (decl->type == T_CFUNC) {
cfn = (ut_c_fn *)decl->operand[0];
return cfn ? cfn(state, op, argvals) : NULL;
@@ -866,7 +866,7 @@ ut_execute_call(struct ut_state *state, struct ut_opcode *op)
struct json_object *rv;
char *lhs;
- if (!decl || decl->type != T_FUNC) {
+ if (!decl || (decl->type != T_FUNC && decl->type != T_CFUNC)) {
lhs = ut_ref_to_str(op->operand[0]);
rv = ut_exception(state, op->operand[0],
"Type error: %s is not a function",
diff --git a/lexer.h b/lexer.h
index ff653bd..1ce52f7 100644
--- a/lexer.h
+++ b/lexer.h
@@ -20,7 +20,8 @@
#include "ast.h"
#define __T_MAX 69
-#define T_EXCEPTION (__T_MAX + 0)
+#define T_EXCEPTION (__T_MAX + 0)
+#define T_CFUNC (__T_MAX + 1)
extern const char *tokennames[__T_MAX];
diff --git a/lib.c b/lib.c
index 9bfa842..fdda6a0 100644
--- a/lib.c
+++ b/lib.c
@@ -1609,8 +1609,8 @@ func_to_string(struct json_object *v, struct printbuf *pb, int level, int flags)
static bool
add_function(struct ut_state *state, struct json_object *scope, const char *name, ut_c_fn *fn)
{
- struct ut_opcode *op = ut_new_op(state, T_FUNC,
- json_object_new_boolean(1), (struct ut_opcode *)fn, (void *)1);
+ struct ut_opcode *op = ut_new_op(state, T_CFUNC,
+ json_object_new_boolean(0), (struct ut_opcode *)fn, (void *)1);
json_object_set_serializer(op->val, func_to_string, op, NULL);