All Projects → ftk → Quickjspp

ftk / Quickjspp

QuickJS C++ wrapper

Programming Languages

c
50402 projects - #5 most used programming language
cpp17
186 projects

Projects that are alternatives of or similar to Quickjspp

Termux
Node.js module for Termux-API
Stars: ✭ 87 (-17.14%)
Mutual labels:  wrapper
Php Mediainfo
PHP wrapper around the mediainfo command
Stars: ✭ 93 (-11.43%)
Mutual labels:  wrapper
Binancedotnet
Official C# Wrapper for the Binance exchange API, with REST and WebSocket endpoints
Stars: ✭ 102 (-2.86%)
Mutual labels:  wrapper
Nimue4
Nim language integration for Unreal Engine 4
Stars: ✭ 90 (-14.29%)
Mutual labels:  wrapper
Msiejavascriptengine
.NET wrapper for working with the JavaScript engines of Internet Explorer and Edge Legacy (JsRT versions of Chakra, ActiveScript version of Chakra and Classic JavaScript Engine). Project was based on the code of SassAndCoffee.JavaScript and Chakra Sample Hosts.
Stars: ✭ 92 (-12.38%)
Mutual labels:  javascript-engine
Pokepy
A Python wrapper for PokéAPI
Stars: ✭ 94 (-10.48%)
Mutual labels:  wrapper
Aiovk
vk.com API python wrapper for asyncio
Stars: ✭ 85 (-19.05%)
Mutual labels:  wrapper
Clam
Quickly turn command-line applications into RESTful webservices with a web-application front-end. You provide a specification of your command line application, its input, output and parameters, and CLAM wraps around your application to form a fully fledged RESTful webservice.
Stars: ✭ 103 (-1.9%)
Mutual labels:  wrapper
Discord.jl
The Julia Discord API Wrapper
Stars: ✭ 93 (-11.43%)
Mutual labels:  wrapper
Pokebase
Python 3 wrapper for Pokéapi v2
Stars: ✭ 99 (-5.71%)
Mutual labels:  wrapper
Apipeline
Feature-rich and pluggable offline-first API wrapper for all your javascript environements ! Easily wire-up your API and make your app work offline in minutes.
Stars: ✭ 92 (-12.38%)
Mutual labels:  wrapper
Spotify Web Api Js
A client-side JS wrapper for the Spotify Web API
Stars: ✭ 1,313 (+1150.48%)
Mutual labels:  wrapper
Binance.api.csharp.client
C#.NET client for Binance Exchange API.
Stars: ✭ 98 (-6.67%)
Mutual labels:  wrapper
Croaring Rs
Rust wrapper for CRoaring
Stars: ✭ 89 (-15.24%)
Mutual labels:  wrapper
Pynlp
A pythonic wrapper for Stanford CoreNLP.
Stars: ✭ 103 (-1.9%)
Mutual labels:  wrapper
Spotify Web Api Kotlin
Spotify Web API wrapper for Kotlin/JVM, Kotlin/Android, Kotlin/JS, and Kotlin/Native. Includes a Spotify Web Playback SDK wrapper for Kotlin/JS, and a spotify-auth wrapper for Kotlin/Android
Stars: ✭ 86 (-18.1%)
Mutual labels:  wrapper
Expressvpn Python
ExpressVPN - Python Wrapper (public IP auto fetch).
Stars: ✭ 94 (-10.48%)
Mutual labels:  wrapper
Faker Cli
cli wrapper for fakerjs
Stars: ✭ 104 (-0.95%)
Mutual labels:  wrapper
Coinbasepro Python
The unofficial Python client for the Coinbase Pro API
Stars: ✭ 1,386 (+1220%)
Mutual labels:  wrapper
Zebra database
A compact, lightweight and feature-rich PHP MySQLi database wrapper
Stars: ✭ 98 (-6.67%)
Mutual labels:  wrapper

QuickJSPP is QuickJS wrapper for C++. It allows you to easily embed Javascript engine into your program.

QuickJS is a small and embeddable Javascript engine. It supports the ES2020 specification including modules, asynchronous generators and proxies. More info: https://bellard.org/quickjs/

Example

#include "quickjspp.hpp"
#include <iostream>

class MyClass
{
public:
    MyClass() {}
    MyClass(std::vector<int>) {}

    double member_variable = 5.5;
    std::string member_function(const std::string& s) { return "Hello, " + s; }
};

void println(const std::string& str) { std::cout << str << std::endl; }

int main()
{
    qjs::Runtime runtime;
    qjs::Context context(runtime);
    try
    {
        // export classes as a module
        auto& module = context.addModule("MyModule");
        module.function<&println>("println");
        module.class_<MyClass>("MyClass")
                .constructor<>()
                .constructor<std::vector<int>>("MyClassA")
                .fun<&MyClass::member_variable>("member_variable")
                .fun<&MyClass::member_function>("member_function");
        // import module
        context.eval("import * as my from 'MyModule'; globalThis.my = my;", "<import>", JS_EVAL_TYPE_MODULE);
        // evaluate js code
        context.eval("let v1 = new my.MyClass();" "\n"
                     "v1.member_variable = 1;" "\n"
                     "let v2 = new my.MyClassA([1,2,3]);" "\n"
                     "function my_callback(str) {" "\n"
                     "  my.println(v2.member_function(str));" "\n"
                     "}" "\n"
        );

        // callback
        auto cb = (std::function<void(const std::string&)>) context.eval("my_callback");
        cb("world");
    }
    catch(qjs::exception)
    {
        auto exc = context.getException();
        std::cerr << (std::string) exc << std::endl;
        if((bool) exc["stack"])
            std::cerr << (std::string) exc["stack"] << std::endl;
        return 1;
    }
}

Installation

QuickJSPP is header-only - put quickjspp.hpp into your include search path. Compiler that supports C++17 or later is required. The program needs to be linked against QuickJS. Sample CMake project files are provided.

License

QuickJSPP is licensed under CC0. QuickJS is licensed under MIT.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].