Skip to content

Instantly share code, notes, and snippets.

@nokotan
Created February 8, 2021 07:05
Show Gist options
  • Save nokotan/a8088c3f0d77dbcfc0fb5e463ac2ae65 to your computer and use it in GitHub Desktop.
Save nokotan/a8088c3f0d77dbcfc0fb5e463ac2ae65 to your computer and use it in GitHub Desktop.
JS関数から構造体をかえしてみる
# 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