38320680cb
This CL demonstrates the following - Interface code written in TS - Having support for modular builds (e.g. making Paragraph optional) - Avoiding monolithic interface files - Using eslint to enforce style and avoid errors. - Working debug and release build (using example.html) Many of these files would be generated via a tool (that has not been written yet). go/ts-canvaskit Change-Id: Ibe9a214d5897b09920cef01f6e95302f3cf30d5c Reviewed-on: https://skia-review.googlesource.com/c/skia/+/392297 Reviewed-by: Jorge Betancourt <jmbetancourt@google.com> Reviewed-by: Leandro Lovisolo <lovisolo@google.com>
60 lines
1.5 KiB
C++
60 lines
1.5 KiB
C++
/*
|
|
* Copyright 2021 Google LLC
|
|
*
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
* found in the LICENSE file.
|
|
*/
|
|
#include <string>
|
|
|
|
#include "experimental/tskit/bindings/bindings.h"
|
|
|
|
class Something {
|
|
public:
|
|
Something(std::string n): fName(n) {}
|
|
|
|
const std::string getName() {
|
|
return fName;
|
|
}
|
|
|
|
void setName(std::string name) {
|
|
fName = name;
|
|
}
|
|
|
|
private:
|
|
std::string fName;
|
|
};
|
|
|
|
EMSCRIPTEN_BINDINGS(Core) {
|
|
TS_PRIVATE_EXPORT("_privateFunction(x: number, y: number): number")
|
|
function("_privateFunction", optional_override([](int x, int y)->size_t {
|
|
return x * y;
|
|
}));
|
|
|
|
/**
|
|
* This function does a public thing.
|
|
* @param input an ice cream flavor
|
|
*/
|
|
TS_EXPORT("publicFunction(input: string): void")
|
|
function("publicFunction", optional_override([](std::string s)->void {
|
|
printf("Hello %s\n", s.c_str());
|
|
}));
|
|
|
|
/**
|
|
* The Something class is quite something. See SkSomething.h for more.
|
|
*/
|
|
class_<Something>("Something")
|
|
/**
|
|
* Returns a Something with the provided name.
|
|
* @param name
|
|
*/
|
|
TS_EXPORT("new(name: string): Something")
|
|
.constructor<std::string>()
|
|
/**
|
|
* Returns the associated name.
|
|
*/
|
|
TS_EXPORT("Something::getName(): string")
|
|
.function("getName", &Something::getName)
|
|
TS_PRIVATE_EXPORT("Something::setName(name: string): void")
|
|
.function("_setName", &Something::setName);
|
|
}
|