Skip to content

Instantly share code, notes, and snippets.

@veryjos
Last active August 19, 2017 20:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save veryjos/e8dc755cbea575f527558c36da7652c2 to your computer and use it in GitHub Desktop.
Save veryjos/e8dc755cbea575f527558c36da7652c2 to your computer and use it in GitHub Desktop.
//-------------------------------------------------------------------------------------------------------
// Copyright (C) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//-------------------------------------------------------------------------------------------------------
#include "main.hpp"
#include "MetaPlug.hpp"
#include "ChakraCore.h"
int main()
{
// ... Initialize ChakraCore
// Initialize CurryChakra bindings
CC::InitializeBindings();
auto result = RunScript(R"(
(
() => {
let test = new TestClass(1.5, 2.5);
test.x += 12;
test.PrintSelf();
return test.x;
}
)()
)");
printf("Result -> %f\n", result->AsFloat());
// ... Cleanup ChakraCore
return 0;
}
#pragma once
#include <cstdio>
#include "MetaPlug.hpp"
Meta(CC::Bind) // V Pure mix-in parent doens't bloat instance size with a vtable and has no valid downcast
class TestClass : public CC::JsBound {
public:
Meta(CC::Bind)
TestClass(float x, float y) :
x(x), y(y) {};
Meta(CC::Bind)
void PrintSelf() {
printf("Native method PrintSelf() called\n");
printf("%f\n", x);
printf("%f\n", y);
};
Meta(CC::Bind)
float x;
Meta(CC::Bind)
float y;
};
Native method PrintSelf() called
13.500000
2.500000
Result -> 13.5
test: 1.000000
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment