<commit_before>#pragma once

#include <emscripten/bind.h>

#include "API/C.hh"
#include "API/Graph.hh"

using namespace emscripten;

namespace Javascript
{
	// NOTE : Emscripten can't bind char* prototypes, we need to use std::string ones instead.

	void createWindow(const std::string& title, int width, int height) { API::createWindow(title.c_str(), width, height); }

	void createView(const std::string& view) { API::createView(view.c_str()); }

	void createEntity(const std::string& type) { API::createEntity(type.c_str()); }

	void setAttribute(const std::string& name, const std::string& type, const std::string& value) { API::setAttribute(name.c_str(), type.c_str(), value.c_str()); }

	void registerScript(const std::string& name, const std::string& source) { API::registerScript(name.c_str(), source.c_str()); }

	void unregisterScript(const std::string& name) { API::unregisterScript(name.c_str()); }

	namespace Graph
	{
		Node::ID addNode(const std::string& label) { return API::Graph::addNode(label.c_str()); }

		void setNodeAttribute(Node::ID id, const std::string& name, const std::string& type, const std::string& value) { API::Graph::setNodeAttribute(id, name.c_str(), type.c_str(), value.c_str()); }

		void setEdgeAttribute(Link::ID id, const std::string& name, const std::string& type, const std::string& value) { API::Graph::setLinkAttribute(id, name.c_str(), type.c_str(), value.c_str()); }

		std::pair<Node::ID, Link::ID> addNeighbor(const std::string& label, Node::ID neighbor) { return API::Graph::addNeighbor(label.c_str(), neighbor); }
	}
}

EMSCRIPTEN_BINDINGS(my_module)
{
	function("create", &API::create);
	function("initialize", &API::initialize);
	function("createWindow", &Javascript::createWindow, allow_raw_pointers());
	function("createView", &Javascript::createView, allow_raw_pointers());
	function("start", &API::start);
	function("destroy", &API::destroy);
	// function("screenshot", &API::screenshot);

	// ----- Entities -----

	function("createEntity", &Javascript::createEntity, allow_raw_pointers());
	function("bindEntity", &API::bindEntity);
	// function("send");
	function("destroyEntity", &API::destroyEntity);
	
	// ----- Attributes -----

    function("setAttribute", &Javascript::setAttribute, allow_raw_pointers());
    // TODO : function("getAttribute");
    
	// ----- Scripts -----

	function("registerScript", &Javascript::registerScript, allow_raw_pointers());
	function("unregisterScript", &Javascript::unregisterScript, allow_raw_pointers());
	function("addJob", &Javascript::addJob, allow_raw_pointers());
	function("removeJob", &Javascript::removeJob);

	// ----- Commands -----

	// TODO : function("sendCommand");
	<commit_msg>Fixed web compilation<commit_after>#pragma once

#include <emscripten/bind.h>

#include "API/C.hh"
#include "API/Graph.hh"

using namespace emscripten;

namespace Javascript
{
	// NOTE : Emscripten can't bind char* prototypes, we need to use std::string ones instead.

	void createWindow(const std::string& title, int width, int height) { API::createWindow(title.c_str(), width, height); }

	void createView(const std::string& view) { API::createView(view.c_str()); }

	void createEntity(const std::string& type) { API::createEntity(type.c_str()); }

	void setAttribute(const std::string& name, const std::string& type, const std::string& value) { API::setAttribute(name.c_str(), type.c_str(), value.c_str()); }

	void registerScript(const std::string& name, const std::string& source) { API::registerScript(name.c_str(), source.c_str()); }

	void unregisterScript(const std::string& name) { API::unregisterScript(name.c_str()); }

	Job::ID addJob(const std::string& name, float period) { return API::addJob(name.c_str(), period); }

	namespace Graph
	{
		Node::ID addNode(const std::string& label) { return API::Graph::addNode(label.c_str()); }

		void setNodeAttribute(Node::ID id, const std::string& name, const std::string& type, const std::string& value) { API::Graph::setNodeAttribute(id, name.c_str(), type.c_str(), value.c_str()); }

		void setEdgeAttribute(Link::ID id, const std::string& name, const std::string& type, const std::string& value) { API::Graph::setLinkAttribute(id, name.c_str(), type.c_str(), value.c_str()); }

		std::pair<Node::ID, Link::ID> addNeighbor(const std::string& label, Node::ID neighbor) { return API::Graph::addNeighbor(label.c_str(), neighbor); }
	}
}

EMSCRIPTEN_BINDINGS(my_module)
{
	function("create", &API::create);
	function("initialize", &API::initialize);
	function("createWindow", &Javascript::createWindow, allow_raw_pointers());
	function("createView", &Javascript::createView, allow_raw_pointers());
	function("start", &API::start);
	function("destroy", &API::destroy);
	// function("screenshot", &API::screenshot);

	// ----- Entities -----

	function("createEntity", &Javascript::createEntity, allow_raw_pointers());
	function("bindEntity", &API::bindEntity);
	// function("send");
	function("destroyEntity", &API::destroyEntity);
	
	// ----- Attributes -----

    function("setAttribute", &Javascript::setAttribute, allow_raw_pointers());
    // TODO : function("getAttribute");
    
	// ----- Scripts -----

	function("registerScript", &Javascript::registerScript, allow_raw_pointers());
	function("unregisterScript", &Javascript::unregisterScript, allow_raw_pointers());
	function("addJob", &Javascript::addJob, allow_raw_pointers());
	function("removeJob", &API::removeJob);

	// ----- Commands -----

	// TODO : function("sendCommand");
	
{'fraction_non_alphanumeric': 0.18776179202331086, 'fraction_numerical': 0.0, 'mean_word_length': 6.1979030144167755, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3694073', 'n_tokens_mistral': 1762, 'n_tokens_neox': 1706, 'n_words': 353}