Hey everyone,
I’m working on a C project that needs to handle complex JavaScript and DOM operations. Right now, I’m manually parsing HTML and JS, but it’s getting too complicated.
I’ve looked into a few options:
- SpiderMonkey: Great JS interpreter, but no DOM support.
- Headless browsers (PhantomJS, SlimerJS): Seem powerful but hard to embed in C.
My ideal solution would be a C-friendly JavaScript engine with DOM support. The project currently runs on Windows (MinGW), but the end goal is to port it to a Raspberry Pi.
Has anyone successfully integrated something like this into a C app? Any suggestions on libraries or approaches I might have missed?
Thanks for your help!
have u tried jerryscript? its tiny n works on raspberry pi. pair it with gumbo-parser for DOM stuff. might be wat ur lookin for. integrations a pain but itll do the job. good luck man!
I’ve been down this road before, and it’s definitely a challenging one. Have you considered using JavaScriptCore? It’s part of WebKit and offers a C API, which could be a good fit for your project. While it doesn’t come with built-in DOM support, you could pair it with a lightweight XML library like TinyXML or RapidXML for basic DOM operations.
For the Raspberry Pi port, JavaScriptCore might be a bit heavy, so you could look into QuickJS as an alternative. It’s designed to be easily embeddable and works well on resource-constrained systems.
Keep in mind that regardless of the engine you choose, you’ll need to implement the DOM API yourself, which is no small task. You might want to start with a minimal subset of DOM functions that are essential for your project and expand from there.
I’ve faced a similar challenge in one of my projects, and I can tell you it’s not an easy task. After a lot of trial and error, I found that using V8 with libxml2 worked well for me. V8 is Google’s open-source JavaScript engine, and it’s pretty fast and reliable. For DOM manipulation, libxml2 is a solid choice.
The integration process was a bit tricky, but once set up, it provided a good balance of performance and functionality. One thing to keep in mind is that this approach requires some careful memory management, especially when passing data between C and JavaScript.
For your Raspberry Pi port, you might want to look into duktape as well. It’s a lightweight JavaScript engine that’s designed for embedded systems. It doesn’t have built-in DOM support, but you could potentially pair it with a lightweight XML parser for basic DOM operations.
Whatever route you choose, be prepared for some challenging integration work. Good luck with your project!