Last active
July 14, 2017 22:10
-
-
Save TheLarkInn/cf8283262f3d42477d1f516cc3c6d09e to your computer and use it in GitHub Desktop.
An example of how you could use C++ in JS with cpp-loader, and webpack's first class WASM support.
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
import("./abc.js").then(abc => abc.doIt()); |
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
import { duplicateText } from "./string.cpp"; | |
export function doIt() { | |
console.log(duplicateText(“Hello World”)); | |
} |
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
extern"C" const char* duplicateText(const char* text) { | |
int len = strlen(text); | |
char* newstr = new char[len*2 + 1]; | |
strcpy(newstr, text); | |
strcat(newstr, text); | |
return newstr; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment