hbrtl_ext/napibridge reimplements the C++ fivenode TFNModule in Go: it calls
the addon's registered C callbacks (npmRequire/npmCall/npmMethods/npmEnd) over
cgo. FN_REQUIRE(module) gets a handle, enumerates its methods, and builds a PRG
object whose method closures proxy oObj:method(args) to Node; results decode as
scalar / native array|hash / nested object handle (e.g. Buffer). The capi shim
forwards tfn_register_callbacks -> napibridge.StoreCallbacks. Calls run on the
node main thread (sync handleRequest), so the direct tfn_npm_* path needs no
marshaling.
Verified end-to-end (node -> addon -> Go libfivenode -> PRG):
- builtin: oOs:hostname()/platform()/arch() -> real values; oOs:cpus() -> native
array, Len()=10.
- real npm: oQR:imageSync() on qr-image (which goja could NOT run) -> Buffer
handle -> :toString("utf8") -> valid 1138-byte SVG.
Full npm is now reachable in-process. P4 (async/Promise via worker + npmAwait)
remains for async methods like qrcode.toString.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
21 lines
851 B
Plaintext
21 lines
851 B
Plaintext
FUNCTION FN_HANDLE()
|
|
LOCAL oQR := FN_REQUIRE( "qr-image" )
|
|
LOCAL xRet, cSvg
|
|
IF ! HB_ISOBJECT( oQR )
|
|
RETURN hb_jsonEncode( { "status" => 500, "headers" => { => }, "body" => "require qr-image: " + FN_LASTERROR() } )
|
|
ENDIF
|
|
// qr-image.imageSync(text, {type:'svg'}) → Buffer → toString
|
|
xRet := oQR:imageSync( "https://solmade.kr", { "type" => "svg" } )
|
|
IF HB_ISOBJECT( xRet ) // Buffer 핸들로 옴 → toString
|
|
cSvg := xRet:toString( "utf8" )
|
|
xRet:__end__()
|
|
ELSE
|
|
cSvg := hb_CStr( xRet )
|
|
ENDIF
|
|
oQR:__end__()
|
|
RETURN hb_jsonEncode( { ;
|
|
"status" => 200, ;
|
|
"headers" => { "Content-Type" => "application/json" }, ;
|
|
"body" => hb_jsonEncode( { "msg" => "PRG -> npm qr-image (real Node) via N-API", "svg_len" => Len( cSvg ), "svg_head" => Left( cSvg, 30 ) } ) ;
|
|
} )
|