Convert Figma logo to code with AI

cesanta logov7

Embedded JavaScript engine for C/C++

1,422
177
1,422
52

Top Related Projects

Ultra-lightweight JavaScript engine for the Internet of Things.

The Espruino JavaScript interpreter - Official Repo

MicroPython - a lean and efficient Python implementation for microcontrollers and constrained systems

Quick Overview

V7 is a lightweight JavaScript engine designed for embedded systems and Internet of Things (IoT) devices. It provides a compact implementation of ECMAScript 5.1 with some additional features, making it suitable for resource-constrained environments.

Pros

  • Small footprint, ideal for embedded systems and IoT devices
  • Easy integration with C/C++ projects
  • Supports a subset of ES5.1 with some ES6 features
  • Designed for memory-constrained environments

Cons

  • Limited feature set compared to full-fledged JavaScript engines
  • Not actively maintained (last commit in 2016)
  • Lacks support for modern JavaScript features
  • Limited documentation and community support

Code Examples

  1. Creating and using a V7 instance:
#include "v7.h"

int main() {
    struct v7 *v7 = v7_create();
    v7_val_t result;
    
    v7_exec(v7, &result, "2 + 2");
    printf("Result: %d\n", v7_get_int(v7, result));
    
    v7_destroy(v7);
    return 0;
}
  1. Defining and calling a JavaScript function:
#include "v7.h"

int main() {
    struct v7 *v7 = v7_create();
    v7_val_t result;
    
    v7_exec(v7, &result,
        "function greet(name) { return 'Hello, ' + name + '!'; }"
        "greet('World')");
    
    size_t len;
    const char *str = v7_get_string(v7, &result, &len);
    printf("%s\n", str);
    
    v7_destroy(v7);
    return 0;
}
  1. Exposing a C function to JavaScript:
#include "v7.h"

static v7_val_t sum(struct v7 *v7, v7_val_t this_obj, v7_val_t args) {
    double a = v7_get_double(v7, v7_array_get(v7, args, 0));
    double b = v7_get_double(v7, v7_array_get(v7, args, 1));
    return v7_mk_number(v7, a + b);
}

int main() {
    struct v7 *v7 = v7_create();
    v7_set_method(v7, v7_get_global(v7), "sum", &sum);
    
    v7_val_t result;
    v7_exec(v7, &result, "sum(3, 4)");
    printf("Result: %d\n", v7_get_int(v7, result));
    
    v7_destroy(v7);
    return 0;
}

Getting Started

To use V7 in your project:

  1. Clone the repository: git clone https://github.com/cesanta/v7.git
  2. Include the V7 source files in your project
  3. Include the v7.h header in your C/C++ code
  4. Create a V7 instance with v7_create()
  5. Use V7 functions to execute JavaScript code and interact with the engine
  6. Destroy the V7 instance with v7_destroy() when done

Example:

#include "v7.h"

int main() {
    struct v7 *v7 = v7_create();
    v7_val_t result;
    v7_exec(v7, &result, "console.log('Hello, V7!')");
    v7_destroy(v7);
    return 0;
}

Compile your program with the V7 source files and any necessary flags for your platform.

Competitor Comparisons

Ultra-lightweight JavaScript engine for the Internet of Things.

Pros of JerryScript

  • More actively maintained with frequent updates and contributions
  • Broader platform support, including various embedded systems and IoT devices
  • Comprehensive documentation and examples for easier integration

Cons of JerryScript

  • Larger memory footprint compared to V7
  • More complex build system and configuration process
  • Steeper learning curve for developers new to embedded JavaScript engines

Code Comparison

V7:

v7_val_t v7_mk_function(struct v7 *v7, v7_cfunction_t *func) {
  return v7_mk_cfunction(v7, func);
}

JerryScript:

jerry_value_t jerry_create_external_function(jerry_external_handler_t handler) {
  return jerry_create_external_function_with_data(handler, NULL);
}

Both engines provide similar functionality for creating JavaScript functions from C code, but JerryScript offers more flexibility with additional parameters and options.

The Espruino JavaScript interpreter - Official Repo

Pros of Espruino

  • More active development and larger community support
  • Designed specifically for microcontrollers, with optimized performance
  • Extensive documentation and examples for hardware integration

Cons of Espruino

  • Larger codebase and memory footprint
  • Less suitable for general-purpose embedded scripting
  • Steeper learning curve for developers not familiar with microcontroller programming

Code Comparison

Espruino:

var led = LED1;
setInterval(function() {
  led.toggle();
}, 500);

v7:

v7_val_t blink(struct v7 *v7) {
  gpio_toggle(LED_PIN);
  return v7_mk_undefined();
}
v7_set_method(v7, v7_get_global(v7), "blink", blink);

Summary

Espruino is tailored for microcontroller programming with JavaScript, offering extensive hardware support and documentation. v7 is a more lightweight, general-purpose embedded scripting engine. Espruino provides a more accessible API for hardware interaction, while v7 offers a smaller footprint and broader application scope. The choice between them depends on the specific project requirements, target hardware, and developer expertise.

MicroPython - a lean and efficient Python implementation for microcontrollers and constrained systems

Pros of MicroPython

  • More extensive standard library and built-in modules
  • Larger community and ecosystem with better documentation
  • Supports a wider range of microcontrollers and development boards

Cons of MicroPython

  • Larger memory footprint, requiring more resources on embedded devices
  • Slower execution speed for certain operations compared to V7

Code Comparison

MicroPython:

import machine
import time

led = machine.Pin(2, machine.Pin.OUT)
while True:
    led.value(not led.value())
    time.sleep(0.5)

V7:

#include "v7.h"
#include "gpio.h"

void blink(struct v7 *v7) {
  gpio_toggle(2);
  v7_exec(v7, "setTimeout(blink, 500);");
}

The MicroPython code is more readable and Pythonic, while the V7 code is more C-like and requires lower-level programming knowledge. MicroPython provides a higher-level abstraction, making it easier for beginners to work with embedded systems. V7, on the other hand, offers more direct control over hardware and potentially better performance for resource-constrained devices.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

V7: Embedded JavaScript engine

NOTE: this project is deprecated in favor of https://github.com/cesanta/mjs

License

V7 is the smallest JavaScript engine written in C. V7 features are:

  • Cross-platform: works on anything, starting from Arduino to MS Windows
  • Small size. Compiled static size is in 40k - 120k range, RAM footprint on initialization is about 800 bytes with freeze feature, 15k without freeze feature
  • Simple and intuitive C/C++ API. It is easy to export existing C/C++ functions into JavaScript environment
  • Standard: V7 implements JavaScript 5.1
  • Usable out-of-the-box: V7 provides an auxiliary library with Hardware (SPI, UART, etc), File, Crypto, Network API
  • Source code is both ISO C and ISO C++ compliant
  • Very easy to integrate: simply copy two files: v7.h and v7.c into your project

V7 makes it possible to program Internet of Things (IoT) embedded devices in JavaScript. V7 is a part of the full stack Mongoose OS Platform.

Examples & Documentation

Contributions

To submit contributions, sign Cesanta CLA and send GitHub pull request. You retain the copyright on your contributions.

Licensing

V7 is released under commercial and GNU GPL v.2 open source licenses.

Commercial Projects: Once your project becomes commercialised GPLv2 licensing dictates that you need to either open your source fully or purchase a commercial license. Cesanta offer full, royalty-free commercial licenses without any GPL restrictions. If your needs require a custom license, we’d be happy to work on a solution with you. [Contact us for pricing.] (https://www.cesanta.com/contact)

Prototyping: While your project is still in prototyping stage and not for sale, you can use V7’s open source code without license restrictions.