jerryscript icon indicating copy to clipboard operation
jerryscript copied to clipboard

How call JavaScript function from C

Open hellozimo opened this issue 9 years ago • 4 comments

I want to call javascript function in *.js file from C
example hello.js, containing func1, func2, In C function, How do I call func1 in C files? In this case, how can i export all js functions to object for calling in C code?

hellozimo avatar Nov 28 '17 01:11 hellozimo

@zhaojuntao you can get your function objects with jerry_get_property, then you can call them with jerry_call_function

LaszloLango avatar Nov 28 '17 07:11 LaszloLango

@LaszloLango That means I just need to read the script source , then jerry_parse and jerry_run , finally i can use jerry_get_property to get js file` function objects, then call and execute it.

Is that right? THANKS

hellozimo avatar Nov 28 '17 08:11 hellozimo

@zhaojuntao yes

LaszloLango avatar Nov 28 '17 09:11 LaszloLango

@LaszloLango Thanks ! I have got it, code is passed.

hellozimo avatar Nov 28 '17 11:11 hellozimo