Codigo Harbour
// ==================================================================
// Codigo Harbour
// ==================================================================
PROCEDURE Main()
LOCAL cJS, cStatus
LOCAL nJobs
// 1. Inicializar
cStatus := XD_JS_INIT()
? "JS_INIT:", cStatus
IF !("ini" $ cStatus)
Alert( "Salir" )
RETURN
ENDIF
XD_JS_SET( "nombre", "Juan" )
? "XD_JS_SET hecho"
? XD_JS_EVAL( 'print("Hola", nombre)' )
? XD_JS_EVAL( 'nombre' )
? XD_JS_GET( "nombre" )
? XD_JS_EVAL( "10 + 20" )
// 3. Usar JS_SET / JS_GET
XD_JS_SET( "x", 42 )
XD_JS_EVAL( 'print("x en JS =", x); y = x * 2;' )
? "y en Harbour =", XD_JS_GET( "y" )
// 2. Evaluar código JS (multilínea con concatenación)
cJS := 'print("Hola desde QuickJS!");' + hb_eol() + ;
'let x = 42;' + hb_eol() + ;
'print("x =", x);' + hb_eol() + ;
'function prueba() {' + hb_eol() + ;
' print("Ejecutando prueba()");' + hb_eol() + ;
' let res = harbour_call();' + hb_eol() + ;
' print("Respuesta de Harbour:", res);' + hb_eol() + ;
'}'
cStatus := XD_JS_EVAL( cJS )
? "XD_JS_EVAL:", cStatus
// 3. Llamar a la función JS
cStatus := XD_JS_CALL_FUNCTION("prueba")
? "XD_JS_CALL_FUNCTION:", cStatus
// 4. Probar Worker
cJS := 'if (typeof Worker !== "undefined") {' + hb_eol() + ;
' const w = new Worker(function() {' + hb_eol() + ;
' postMessage("Worker iniciado");' + hb_eol() + ;
' setTimeout(() => {' + hb_eol() + ;
' postMessage("Timeout en worker");' + hb_eol() + ;
' close(); // Cierra el worker' + hb_eol() + ;
' }, 100);' + hb_eol() + ;
' });' + hb_eol() + ;
' w.onmessage = function(e) { print("Worker:", e.data); };' + hb_eol() + ;
' // Opcional: guardar w en global para poder w.terminate() después' + hb_eol() + ;
' globalThis.activeWorker = w;' + hb_eol() + ;
'} else {' + hb_eol() + ;
' print("Worker no disponible");' + hb_eol() + ;
'}'
cStatus := XD_JS_EVAL( cJS )
? "XD_JS_EVAL (Worker):", cStatus
inkey( 1.0 )
// Terminar workers activos
XD_JS_EVAL( 'if (globalThis.activeWorker) { globalThis.activeWorker.terminate(); print("Worker terminado"); }' )
// 5. Procesar eventos pendientes
inkey( 1.0 )
DO WHILE (nJobs := XD_JS_EXECUTE_PENDING()) > 0
inkey(1.0)
ENDDO
// 6. Liberar
? XD_JS_FREE()
inkey( 0 )
WAIT
RETURN
Evidentemente la idea es no necesitar entorno grafico ( no usar webview por ejemplo )
Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo
El secreto de la felicidad no está en hacer lo que te gusta, sino en que te guste lo que haces