Skip to content

Instantly share code, notes, and snippets.

@TheLarkInn
Last active July 14, 2017 22:10
Show Gist options
  • Save TheLarkInn/cf8283262f3d42477d1f516cc3c6d09e to your computer and use it in GitHub Desktop.
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.
import("./abc.js").then(abc => abc.doIt());
import { duplicateText } from "./string.cpp";
export function doIt() {
console.log(duplicateText(“Hello World”));
}
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