From 1ceebeb5c78c4a7f4a3b94a893a8fcba3d99a1d4 Mon Sep 17 00:00:00 2001 From: Pabloader Date: Thu, 21 May 2026 20:34:32 +0000 Subject: [PATCH] Try returns --- build/plugins/wasmPlugin.ts | 4 ++-- src/games/playground/awoo.cpp | 10 ++++++++-- src/games/playground/index.tsx | 5 ++++- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/build/plugins/wasmPlugin.ts b/build/plugins/wasmPlugin.ts index 4541215..45db69a 100644 --- a/build/plugins/wasmPlugin.ts +++ b/build/plugins/wasmPlugin.ts @@ -328,8 +328,6 @@ const wasmPlugin = ({ production }: WasmLoaderConfig = {}): BunPlugin => { '-I', include, ]; - const std = args.path.endsWith('.cpp') ? STD_CPP : STD_C; - const inputObjPath = path.resolve(distDir, inputBasename + '.o'); const libCObjDir = path.resolve(distDir, 'lib.c'); const libCppObjDir = path.resolve(distDir, 'lib.cpp'); @@ -341,6 +339,8 @@ const wasmPlugin = ({ production }: WasmLoaderConfig = {}): BunPlugin => { Array.fromAsync(libCppGlob.scan()), ]); + const std = args.path.endsWith('.cpp') ? STD_CPP : STD_C; + const [, libCObjs, libCppObjs] = await Promise.all([ (async () => { const compilationFlags = [...flags, ...std]; diff --git a/src/games/playground/awoo.cpp b/src/games/playground/awoo.cpp index f3cc8c3..a92ff29 100644 --- a/src/games/playground/awoo.cpp +++ b/src/games/playground/awoo.cpp @@ -1,9 +1,11 @@ #include +#include #include #include #include #include #include +#include #include class bit { @@ -86,6 +88,10 @@ JS_EXPORT void awoo() { std::cout << "rand = " << rand() << "\narc4 = " << arc4random() << std::endl; } -JS_EXPORT_AS(something) void anything(void (*cb)()) { - cb(); +auto autofunc(auto a) requires std::is_integral_v { + return a + 1; } + +JS_EXPORT_AS(something) auto anything(uint8_t (*cb)()) { + return autofunc(cb()); +} \ No newline at end of file diff --git a/src/games/playground/index.tsx b/src/games/playground/index.tsx index ca97c4b..941dce3 100644 --- a/src/games/playground/index.tsx +++ b/src/games/playground/index.tsx @@ -3,5 +3,8 @@ import awoo from './awoo.cpp'; export default function main() { console.log(awoo) awoo.awoo(); - awoo.something(() => console.log('called')); + console.log(awoo.something(() => { + console.log('called'); + return 42; + })); } \ No newline at end of file