Created
February 8, 2021 07:05
-
-
Save nokotan/a8088c3f0d77dbcfc0fb5e463ac2ae65 to your computer and use it in GitHub Desktop.
JS関数から構造体をかえしてみる
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 <stdio.h> | |
# include <emscripten.h> | |
struct vec2 | |
{ | |
float x, y; | |
}; | |
extern "C" | |
{ | |
extern vec2 makeVec2() EM_IMPORT(makeVec2); | |
__attribute__((used, visibility("default"))) | |
const char* __em_js__makeVec2() | |
{ | |
return "(void* retPtr)<::>{ HEAPF32[(retPtr >> 2)] = 10; HEAPF32[(retPtr >> 2) + 1] = 20; }"; | |
} | |
} | |
int main() | |
{ | |
auto v = makeVec2(); | |
printf("%f, %f\n", v.x, v.y); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment