From 5f19e5870007d57034adea5f124e3c87413a1aaf Mon Sep 17 00:00:00 2001 From: Jo-Philipp Wich Date: Tue, 6 Oct 2020 15:49:27 +0200 Subject: ast, eval: track current file name across function invocations Signed-off-by: Jo-Philipp Wich --- eval.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'eval.c') diff --git a/eval.c b/eval.c index e9c797b..881766b 100644 --- a/eval.c +++ b/eval.c @@ -1004,6 +1004,7 @@ ut_invoke(struct ut_state *state, uint32_t off, struct json_object *this, struct json_object *rv = NULL; struct ut_function *fn; struct ut_scope *sc; + char *filename; size_t arridx; ut_c_fn *cfn; @@ -1022,7 +1023,10 @@ ut_invoke(struct ut_state *state, uint32_t off, struct json_object *this, fn->scope->ctx = json_object_get(this ? this : state->ctx); sc = state->scope; + filename = state->filename; + state->scope = ut_acquire_scope(fn->scope); + state->filename = fn->filename; if (fn->args) for (arridx = 0; arridx < json_object_array_length(fn->args); arridx++) @@ -1055,10 +1059,13 @@ ut_invoke(struct ut_state *state, uint32_t off, struct json_object *this, json_object_put(fn->scope->ctx); fn->scope->ctx = NULL; - /* ... and reset the function scope */ + /* ... and reset the function scope... */ ut_release_scope(fn->scope); fn->scope = NULL; + /* ... and the file name context */ + state->filename = filename; + return rv; } -- cgit v1.2.3