Call JavaScript function from C
See original GitHub issueHey,
It’s not pretty clear to me how I can call functions from JavaScript code within my C code.
For example I run this code
int main(int argc, char *argv[]) {
duk_context *ctx = duk_create_heap_default();
duk_eval_file(ctx, "test.js");
duk_destroy_heap(ctx);
return 0;
}
and inside my test.js is a function like
function GotCalledFromC()
{
// stuff
}
How would it work to call this function in C code ?
Thank you 😃
Issue Analytics
- State:
- Created 7 years ago
- Reactions:1
- Comments:8 (7 by maintainers)
Top Results From Across the Web
Calling a JavaScript function from C - Stack Overflow
To call JS from C, the general process is: Get QuickJS and esbuild; esbuild your desired library/script into an ESM format using CommonJS....
Read more >Calling a JS Function from C++ - Ultralight
Our goal is to call the JavaScript function ShowMessage() from C++. ; The easiest way to call ShowMessage() from C++ is by evaluating...
Read more >Calling JavaScript code from C/C++ using WebAssembly
void emscripten_run_script (const char\script*)is the most direct way of calling JavaScript from C/C++. It effectively runs the code using eval ...
Read more >How to call a JavaScript function from C++? - Tutorialspoint
To call a JavaScript function from C++, generate a js file, which calls the function. The web page will load the JS and...
Read more >Interacting with code — Emscripten 3.1.26-git (dev ...
Calling compiled C functions from JavaScript using ccall/cwrap¶. The easiest way to call compiled C functions from JavaScript is to use ccall() or...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
The function’s return value will then be left on top of the value stack.
@Memorix101 The getting started
processLine()
case should be similar, the pieces in the example are:The example uses
duk_pcall()
to avoid the uncaught error issue mentioned by @fatcerberus above.