C++ bindings for browser DOM api's
Find a file
2025-02-12 22:22:06 +01:00
samples/HelloWorld improved bindings 2025-02-12 22:22:06 +01:00
.gitignore improved bindings 2025-02-12 22:22:06 +01:00
Crafter.CppDOM.cppm improved bindings 2025-02-12 22:22:06 +01:00
Crafter.CppDOM.js improved bindings 2025-02-12 22:22:06 +01:00
hello.png Initial commit 2025-01-02 02:48:44 +01:00
LICENSE Initial commit 2025-01-02 02:48:44 +01:00
project.json improved bindings 2025-02-12 22:22:06 +01:00
README.md improved bindings 2025-02-12 22:22:06 +01:00

About

alt text

Crafter.Web is a C++ library that exposes the browser DOM api's to C++ WebAssembly.

How to use

It is highly recommended to use this with Crafter.WebBuild, but it is not strictly required if the same way of injecting the env is followed. The following instructions will be for Crafter.WebBuild.

Quickstart

create a project.json in an empty folder, open it in your preferred text editor. Create a basic project file, that describes your web project.

{
    "name": "sample-project",
    "configurations": [
        {
            "name": "debug",
            "standard": "c++26",
            "source_files": ["main"],
            "module_files": [],
            "build_dir": "./build",
            "output_dir": "./bin",
            "optimization_level": "0",
            "target": "wasm32-unknown-wasi",
            "type": "executable",
            "dependencies": [
                {
                    "path":"https://github.com/Catcrafts/Crafter.CppDOM.git",
                    "configuration":"debug"
                }
            ]
        }
    ]
}

Save and close the file, create a main.cpp

import Crafter.CppDOM;

int main(){
    void* body = Crafter::CppDOM::Bindings::GetElementById("body");
    Crafter::CppDOM::Bindings::SetInnerHTML(body, "Hello World!");
    Crafter::CppDOM::Bindings::FreeJs(body);
}

Save and close, then run crafter-webbuild serve -c debug. Now you can open the browser at http://localhost:8080/ and Hello World! will appear in the browser.

This sample can also be viewed in the Hello World sample