Skip to content

Instantly share code, notes, and snippets.

@nikuuchi
Created October 22, 2014 09:34
Show Gist options
  • Select an option

  • Save nikuuchi/a7f86ada284a63867650 to your computer and use it in GitHub Desktop.

Select an option

Save nikuuchi/a7f86ada284a63867650 to your computer and use it in GitHub Desktop.
emscripten.hを使ってみた時のメモ
#include <stdio.h>
#include <stdlib.h>
#include <emscripten.h>
void onLoadCallback(const char *filename) {
FILE *fp;
char s[256];
if((fp = fopen(filename, "r")) == NULL) {
printf("file open error!!\n");
exit(1);
}
while (fgets(s, 256, fp) != NULL) {
printf("%s", s);
}
fclose(fp);
}
void onErrorCallback(const char *err) {
printf("%s", err);
}
int main() {
emscripten_async_wget("http://www.google.com", "file.txt", onLoadCallback, onErrorCallback);
return 0;
}
@nikuuchi
Copy link
Copy Markdown
Author

ブラウザ上でscriptタグ使って読み込むと使えることを確認
ただし、wgetで読み込むURLはsame origin policyの影響を受ける

コンパイル時のオプション

$ emcc -s ASYNCIFY=1 -s NO_EXIT_RUNTIME=1  emcc_wget.c

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment