Welcome! Log In Create A New Profile

Advanced

[njs] njs_vm_function() interface to get a function by name.

July 14, 2016 12:52PM
details: http://hg.nginx.org/njs/rev/74246210aa9d
branches:
changeset: 121:74246210aa9d
user: Igor Sysoev <igor@sysoev.ru>
date: Thu Jul 14 19:24:51 2016 +0300
description:
njs_vm_function() interface to get a function by name.

diffstat:

njs/njs_variable.c | 24 ++++++++++++++++++++++++
njs/njscript.h | 1 +
2 files changed, 25 insertions(+), 0 deletions(-)

diffs (45 lines):

diff -r 07d2be75a7db -r 74246210aa9d njs/njs_variable.c
--- a/njs/njs_variable.c Wed Jul 13 13:56:12 2016 +0300
+++ b/njs/njs_variable.c Thu Jul 14 19:24:51 2016 +0300
@@ -119,6 +119,30 @@ njs_parser_variable(njs_vm_t *vm, njs_pa
}


+njs_function_t *
+njs_vm_function(njs_vm_t *vm, nxt_str_t *name)
+{
+ njs_value_t *value;
+ njs_variable_t *var;
+ nxt_lvlhsh_query_t lhq;
+
+ lhq.key_hash = nxt_djb_hash(name->data, name->len);
+ lhq.key = *name;
+ lhq.proto = &njs_variables_hash_proto;
+
+ if (nxt_slow_path(nxt_lvlhsh_find(&vm->variables_hash, &lhq) != NXT_OK)) {
+ return NULL;
+ }
+
+ var = lhq.value;
+
+ value = (njs_value_t *) ((u_char *) vm->scopes[NJS_SCOPE_GLOBAL]
+ + njs_offset(var->index));
+
+ return value->data.u.function;
+}
+
+
static njs_variable_t *
njs_variable_alloc(njs_vm_t *vm, njs_parser_t *parser, nxt_str_t *name)
{
diff -r 07d2be75a7db -r 74246210aa9d njs/njscript.h
--- a/njs/njscript.h Wed Jul 13 13:56:12 2016 +0300
+++ b/njs/njscript.h Thu Jul 14 19:24:51 2016 +0300
@@ -91,6 +91,7 @@ NXT_EXPORT nxt_int_t njs_vm_call(njs_vm_
njs_opaque_value_t *args, nxt_uint_t nargs);
NXT_EXPORT nxt_int_t njs_vm_run(njs_vm_t *vm);

+NXT_EXPORT njs_function_t *njs_vm_function(njs_vm_t *vm, nxt_str_t *name);
NXT_EXPORT njs_ret_t njs_vm_return_string(njs_vm_t *vm, u_char *start,
size_t size);
NXT_EXPORT nxt_int_t njs_vm_retval(njs_vm_t *vm, nxt_str_t *retval);

_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

[njs] njs_vm_function() interface to get a function by name.

Igor Sysoev 695 July 14, 2016 12:52PM



Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 245
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready