`fnode capi <entry.prg> -o libfivenode.dylib` generates all PRG as library funcs + a cgo shim exporting the N-API C ABI, and builds buildmode=c-shared. hb_bridge_handle_request stashes the request (read by PRG via FN_NAPI_REQ, registered with HB_FUNC) and runs the PRG FN_HANDLE via capiVM.Run, returning its JSON. capiEnsure calls RegisterLibModules so HB_FUNC/--rtl symbols install into the VM (vm.Run drains libModules but not dynamicFuncs). Verified: node → addon → Go libfivenode → PRG parses the request and runs string/hash/JSON ops (Upper/Len/HB_ISHASH/hb_jsonDecode/Encode), round-trips a 200 response. Supersedes the P1 hand-written cmd/libfivenode (removed). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
17 lines
533 B
Plaintext
17 lines
533 B
Plaintext
FUNCTION FN_HANDLE()
|
|
LOCAL hReq := hb_jsonDecode( FN_NAPI_REQ() )
|
|
LOCAL cPath := ""
|
|
IF HB_ISHASH( hReq )
|
|
cPath := hb_CStr( hb_HGetDef( hReq, "path", "" ) )
|
|
ENDIF
|
|
RETURN hb_jsonEncode( { ;
|
|
"status" => 200, ;
|
|
"headers" => { "Content-Type" => "application/json; charset=utf-8" }, ;
|
|
"body" => hb_jsonEncode( { ;
|
|
"msg" => "PRG ran in Go libfivenode via N-API", ;
|
|
"path" => cPath, ;
|
|
"upper" => Upper( cPath ), ;
|
|
"len" => Len( cPath ) ;
|
|
} ) ;
|
|
} )
|