-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbindings.cpp
More file actions
38 lines (31 loc) · 1.2 KB
/
bindings.cpp
File metadata and controls
38 lines (31 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include <emscripten/bind.h>
#include "cards.h"
using namespace emscripten;
emscripten::val textToPackOfCardsJS(std::string text) {
std::array<int, 52> cards = textToPackOfCards(text);
return emscripten::val::array(cards.begin(), cards.end());
}
std::string packOfCardsToTextJS(emscripten::val jsArray) {
std::array<int, 52> cards;
for (int i = 0; i < 52; i++) {
cards[i] = jsArray[i].as<int>();
}
return packOfCardsToText(cards);
}
std::string packOfCardsToTextEncryptedJS(emscripten::val jsArray, std::string key) {
std::array<int, 52> cards;
for (int i = 0; i < 52; i++) {
cards[i] = jsArray[i].as<int>();
}
return packOfCardsToTextEncrypted(cards, key);
}
emscripten::val textToPackOfCardsEncryptedJS(std::string text, std::string key) {
std::array<int, 52> cards = textToPackOfCardsEncrypted(text, key);
return emscripten::val::array(cards.begin(), cards.end());
}
EMSCRIPTEN_BINDINGS(cardcode){
function("textToPackOfCards", &textToPackOfCardsJS);
function("packOfCardsToText", &packOfCardsToTextJS);
function("packOfCardsToTextEncrypted", &packOfCardsToTextEncryptedJS);
function("textToPackOfCardsEncrypted", &textToPackOfCardsEncryptedJS);
}