Last active
August 22, 2017 07:03
-
-
Save veryjos/3103953f8a7d02056562a83cef7ab110 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "main.hpp" | |
int main() { | |
const char* script = R"( | |
( | |
() => { | |
class Extended extends CppClass { | |
constructor() { | |
super(10, 10); | |
} | |
// Override SomeVirtualFunc with a JS method | |
SomeVirtualFunc() { | |
this.Print("Called SomeVirtualFunc overidden by Javascript"); | |
} | |
}; | |
return new Extended(); | |
} | |
)() | |
)"; | |
// ... ChakraCore initialization ... | |
// Initialize CurryChakra bindings | |
CC::InitializeBindings(); | |
// Run the script. | |
JsValueRef result; | |
JsRun(scriptSource, currentSourceContext++, fname, JsParseScriptAttributeNone, | |
&result); | |
// Get the returned class casted to CppClass | |
CppClass* testClass; | |
CC::Internal::BindingInitializer::JsToCpp(result, testClass); | |
// Call SomeVirtualFunc on on the type returned from JS | |
testClass->SomeVirtualFunc(); | |
// ... ChakraCore cleanup ... | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma once | |
#include <cstdio> | |
#include <string> | |
#include "MetaPlug.hpp" | |
Meta(CC::Bind, CC::Virtual) | |
class CppClass : public CC::JsBound { | |
public: | |
Meta(CC::Bind) | |
CppClass(float x, float y) : x(x), y(y){}; | |
Meta(CC::Bind) | |
virtual void SomeVirtualFunc() { | |
Print("Called SomeVirtualFunc from C++ base definition"); | |
}; | |
Meta(CC::Bind) | |
void Print(std::string printText) { | |
printf("%s\n", printText.c_str()); | |
}; | |
Meta(CC::Bind) | |
float x; | |
Meta(CC::Bind) | |
float y; | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Called SomeVirtualFunc overidden by Javascript |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment