diff --git a/CLAUDE.md b/CLAUDE.md index 6c051043..b4763cb3 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -126,7 +126,7 @@ meson test -C build_dbg ### Debugging - Use debug build: `make debug` - Tracy profiler support when enabled -- Console logging available via `console.log()`, `console.error()`, etc. +- Console logging available via `log.console()`, `log.error()`, etc. - Log files written to `.prosperon/log.txt` # Project Structure Notes @@ -234,7 +234,7 @@ When sending a message with a callback, respond by sending to the message itself ```javascript // Sender side: send(actor, {type: 'status'}, response => { - console.log(response); // Handle the response + log.console(response); // Handle the response }); // Receiver side: diff --git a/benchmarks/nota.js b/benchmarks/nota.js index 8bd4f730..63570441 100644 --- a/benchmarks/nota.js +++ b/benchmarks/nota.js @@ -49,28 +49,28 @@ function getStats(arr) { } // Pretty print results -console.log("\n=== Performance Test Results (100 iterations) ==="); -console.log("\nJSON Decoding (ms):"); +log.console("\n=== Performance Test Results (100 iterations) ==="); +log.console("\nJSON Decoding (ms):"); const jsonDecStats = getStats(jsonDecodeTimes); -console.log(`Average: ${jsonDecStats.avg.toFixed(2)} ms`); -console.log(`Min: ${jsonDecStats.min.toFixed(2)} ms`); -console.log(`Max: ${jsonDecStats.max.toFixed(2)} ms`); +log.console(`Average: ${jsonDecStats.avg.toFixed(2)} ms`); +log.console(`Min: ${jsonDecStats.min.toFixed(2)} ms`); +log.console(`Max: ${jsonDecStats.max.toFixed(2)} ms`); -console.log("\nJSON Encoding (ms):"); +log.console("\nJSON Encoding (ms):"); const jsonEncStats = getStats(jsonEncodeTimes); -console.log(`Average: ${jsonEncStats.avg.toFixed(2)} ms`); -console.log(`Min: ${jsonEncStats.min.toFixed(2)} ms`); -console.log(`Max: ${jsonEncStats.max.toFixed(2)} ms`); +log.console(`Average: ${jsonEncStats.avg.toFixed(2)} ms`); +log.console(`Min: ${jsonEncStats.min.toFixed(2)} ms`); +log.console(`Max: ${jsonEncStats.max.toFixed(2)} ms`); -console.log("\nNOTA Encoding (ms):"); +log.console("\nNOTA Encoding (ms):"); const notaEncStats = getStats(notaEncodeTimes); -console.log(`Average: ${notaEncStats.avg.toFixed(2)} ms`); -console.log(`Min: ${notaEncStats.min.toFixed(2)} ms`); -console.log(`Max: ${notaEncStats.max.toFixed(2)} ms`); +log.console(`Average: ${notaEncStats.avg.toFixed(2)} ms`); +log.console(`Min: ${notaEncStats.min.toFixed(2)} ms`); +log.console(`Max: ${notaEncStats.max.toFixed(2)} ms`); -console.log("\nNOTA Decoding (ms):"); +log.console("\nNOTA Decoding (ms):"); const notaDecStats = getStats(notaDecodeTimes); -console.log(`Average: ${notaDecStats.avg.toFixed(2)} ms`); -console.log(`Min: ${notaDecStats.min.toFixed(2)} ms`); -console.log(`Max: ${notaDecStats.max.toFixed(2)} ms`); +log.console(`Average: ${notaDecStats.avg.toFixed(2)} ms`); +log.console(`Min: ${notaDecStats.min.toFixed(2)} ms`); +log.console(`Max: ${notaDecStats.max.toFixed(2)} ms`); diff --git a/benchmarks/wota.js b/benchmarks/wota.js index d96c5086..823d0c4f 100644 --- a/benchmarks/wota.js +++ b/benchmarks/wota.js @@ -75,8 +75,8 @@ const benchmarks = [ ]; // Print a header -console.log("Wota Encode/Decode Benchmark"); -console.log("============================\n"); +log.console("Wota Encode/Decode Benchmark"); +log.console("============================\n"); // We'll run each benchmark scenario in turn. for (let bench of benchmarks) { @@ -96,11 +96,11 @@ for (let bench of benchmarks) { let elapsedSec = measureTime(runAllData, bench.iterations); let opsPerSec = (totalIterations / elapsedSec).toFixed(1); - console.log(`${bench.name}:`); - console.log(` Iterations: ${bench.iterations} × ${bench.data.length} data items = ${totalIterations}`); - console.log(` Elapsed: ${elapsedSec.toFixed(3)} s`); - console.log(` Throughput: ${opsPerSec} encode+decode ops/sec\n`); + log.console(`${bench.name}:`); + log.console(` Iterations: ${bench.iterations} × ${bench.data.length} data items = ${totalIterations}`); + log.console(` Elapsed: ${elapsedSec.toFixed(3)} s`); + log.console(` Throughput: ${opsPerSec} encode+decode ops/sec\n`); } // All done -console.log("Benchmark completed.\n"); +log.console("Benchmark completed.\n"); diff --git a/benchmarks/wota_nota_json.js b/benchmarks/wota_nota_json.js index d13694ef..9376826b 100644 --- a/benchmarks/wota_nota_json.js +++ b/benchmarks/wota_nota_json.js @@ -160,12 +160,12 @@ function runBenchmarkForLibrary(lib, bench) { // 5. Main driver: run across all benchmarks, for each library. //////////////////////////////////////////////////////////////////////////////// -console.log("Benchmark: Wota vs Nota vs JSON"); -console.log("================================\n"); +log.console("Benchmark: Wota vs Nota vs JSON"); +log.console("================================\n"); for (let bench of benchmarks) { - console.log(`SCENARIO: ${bench.name}`); - console.log(` Data length: ${bench.data.length} | Iterations: ${bench.iterations}\n`); + log.console(`SCENARIO: ${bench.name}`); + log.console(` Data length: ${bench.data.length} | Iterations: ${bench.iterations}\n`); for (let lib of libraries) { let { encodeTime, decodeTime, totalSize } = runBenchmarkForLibrary(lib, bench); @@ -175,15 +175,15 @@ for (let bench of benchmarks) { let encOpsPerSec = (totalOps / encodeTime).toFixed(1); let decOpsPerSec = (totalOps / decodeTime).toFixed(1); - console.log(` ${lib.name}:`); - console.log(` Encode time: ${encodeTime.toFixed(3)}s => ${encOpsPerSec} encodes/sec [${(encodeTime/bench.iterations)*1000000000} ns/try]`); - console.log(` Decode time: ${decodeTime.toFixed(3)}s => ${decOpsPerSec} decodes/sec [${(decodeTime/bench.iterations)*1000000000}/try]`); - console.log(` Total size: ${totalSize} bytes (or code units for JSON)`); - console.log(""); + log.console(` ${lib.name}:`); + log.console(` Encode time: ${encodeTime.toFixed(3)}s => ${encOpsPerSec} encodes/sec [${(encodeTime/bench.iterations)*1000000000} ns/try]`); + log.console(` Decode time: ${decodeTime.toFixed(3)}s => ${decOpsPerSec} decodes/sec [${(decodeTime/bench.iterations)*1000000000}/try]`); + log.console(` Total size: ${totalSize} bytes (or code units for JSON)`); + log.console(""); } - console.log("---------------------------------------------------------\n"); + log.console("---------------------------------------------------------\n"); } -console.log("Benchmark complete.\n"); +log.console("Benchmark complete.\n"); os.exit() diff --git a/docs/actors.md b/docs/actors.md index 01517cf0..5b1aac57 100644 --- a/docs/actors.md +++ b/docs/actors.md @@ -47,7 +47,7 @@ Certain functions are intrinsic to the program and cannot be overridden. They’ - **Example**: ```js this.delay(_ => { - console.log("3 seconds later!") + log.console("3 seconds later!") }, 3) ``` diff --git a/docs/api/modules/doc.md b/docs/api/modules/doc.md index 78944bca..4b068b3e 100644 --- a/docs/api/modules/doc.md +++ b/docs/api/modules/doc.md @@ -7,7 +7,7 @@ Docstrings are set to the symbol `prosperon.DOC` ```js // Suppose we have a module that returns a function -function greet(name) { console.log("Hello, " + name) } +function greet(name) { log.console("Hello, " + name) } // We can attach a docstring greet.doc = ` @@ -21,7 +21,7 @@ return greet ```js // Another way is to add a docstring object to an object var greet = { -hello() { console.log('hello!') } +hello() { log.console('hello!') } } greet[prosperon.DOC] = {} diff --git a/docs/tutorial.md b/docs/tutorial.md index 65486e2c..74abc2be 100644 --- a/docs/tutorial.md +++ b/docs/tutorial.md @@ -49,7 +49,7 @@ return { This will cause prosperon to launch a 500x500 window with the title 'Hello World'. In your ```main.js```, write the following: ``` -console.log("Hello world") +log.console("Hello world") this.delay(_ => { this.kill(); diff --git a/examples/chess/main.js b/examples/chess/main.js index f4c6e261..762601be 100644 --- a/examples/chess/main.js +++ b/examples/chess/main.js @@ -12,9 +12,7 @@ myblob.write_bit(0) myblob.__proto__.toString = function() { return `[${this.length} bit blob]` } -console.log(myblob.toString()) -console.log(myblob) -console.log(myblob.length) +log.console(myblob.toString(), myblob, myblob.length) var input = use('input') @@ -63,7 +61,7 @@ function updateTitle() { break; } - console.log(title) + log.console(title) } // Initialize title @@ -125,16 +123,16 @@ function handleMouseButtonUp(e) { } if (mover.tryMove(grid.at(selectPos)[0], c)) { - console.log("Made move from", selectPos, "to", c); + log.console("Made move from", selectPos, "to", c); // Send move to opponent - console.log("Sending move to opponent:", opponent); + log.console("Sending move to opponent:", opponent); send(opponent, { type: 'move', from: selectPos, to: c }); isMyTurn = false; // It's now opponent's turn - console.log("Move sent, now opponent's turn"); + log.console("Move sent, now opponent's turn"); selectPos = null; updateTitle(); } @@ -305,11 +303,11 @@ function startServer() { updateTitle(); $_.portal(e => { - console.log("Portal received contact message"); + log.console("Portal received contact message"); // Reply with this actor to establish connection - console.log (json.encode($_)) + log.console (json.encode($_)) send(e, $_); - console.log("Portal replied with server actor"); + log.console("Portal replied with server actor"); }, 5678); } @@ -318,10 +316,10 @@ function joinServer() { updateTitle(); function contact_fn(actor, reason) { - console.log("CONTACTED!", actor ? "SUCCESS" : "FAILED", reason); + log.console("CONTACTED!", actor ? "SUCCESS" : "FAILED", reason); if (actor) { opponent = actor; - console.log("Connection established with server, sending join request"); + log.console("Connection established with server, sending join request"); // Send a greet message with our actor object send(opponent, { @@ -329,7 +327,7 @@ function joinServer() { client_actor: $_ }); } else { - console.log(`Failed to connect: ${json.encode(reason)}`); + log.console(`Failed to connect: ${json.encode(reason)}`); gameState = 'waiting'; updateTitle(); } @@ -349,33 +347,33 @@ $_.receiver(e => { else if (e.kind == 'draw') send(e, draw()) else if (e.type === 'game_start' || e.type === 'move' || e.type === 'greet') - console.log("Receiver got message:", e.type, e); + log.console("Receiver got message:", e.type, e); if (e.type === 'quit') os.exit() if (e.type === 'greet') { - console.log("Server received greet from client"); + log.console("Server received greet from client"); // Store the client's actor object for ongoing communication opponent = e.client_actor; - console.log("Stored client actor:", json.encode(opponent)); + log.console("Stored client actor:", json.encode(opponent)); gameState = 'connected'; updateTitle(); // Send game_start to the client - console.log("Sending game_start to client"); + log.console("Sending game_start to client"); send(opponent, { type: 'game_start', your_color: 'black' }); - console.log("game_start message sent to client"); + log.console("game_start message sent to client"); } else if (e.type === 'game_start') { - console.log("Game starting, I am:", e.your_color); + log.console("Game starting, I am:", e.your_color); myColor = e.your_color; isMyTurn = (myColor === 'white'); gameState = 'connected'; updateTitle(); } else if (e.type === 'move') { - console.log("Received move from opponent:", e.from, "to", e.to); + log.console("Received move from opponent:", e.from, "to", e.to); // Apply opponent's move var fromCell = grid.at(e.from); if (fromCell.length) { @@ -383,12 +381,12 @@ $_.receiver(e => { if (mover.tryMove(piece, e.to)) { isMyTurn = true; // It's now our turn updateTitle(); - console.log("Applied opponent move, now my turn"); + log.console("Applied opponent move, now my turn"); } else { - console.log("Failed to apply opponent move"); + log.console("Failed to apply opponent move"); } } else { - console.log("No piece found at from position"); + log.console("No piece found at from position"); } } else if (e.type === 'mouse_move') { // Update opponent's mouse position diff --git a/examples/http_download_actor.js b/examples/http_download_actor.js index b5e07f5b..f85370d0 100644 --- a/examples/http_download_actor.js +++ b/examples/http_download_actor.js @@ -101,7 +101,7 @@ $_.receiver(function(msg) { break; case 'status': - console.log(`got status request. current is ${json.encode(get_status())}`) + log.console(`got status request. current is ${json.encode(get_status())}`) send(msg, { type: 'status_response', ...get_status() diff --git a/examples/nat.js b/examples/nat.js index a8779321..9f244f8e 100644 --- a/examples/nat.js +++ b/examples/nat.js @@ -8,13 +8,13 @@ var waiting_client = null; var match_id = 0; $_.portal(e => { - console.log("NAT server: received connection request"); + log.console("NAT server: received connection request"); if (!is_actor(e.actor)) send(e, {reason: "Must provide the actor you want to connect."}); if (waiting_client) { - console.log(`sending out messages! to ${json.encode(e.actor)} and ${json.encode(waiting_client.actor)}`) + log.console(`sending out messages! to ${json.encode(e.actor)} and ${json.encode(waiting_client.actor)}`) send(waiting_client, e.actor) send(e, waiting_client.actor) @@ -25,5 +25,5 @@ $_.portal(e => { waiting_client = e - console.log(`actor ${json.encode(e.actor)} is waiting ...`) + log.console(`actor ${json.encode(e.actor)} is waiting ...`) }, 4000); diff --git a/examples/nat_client.js b/examples/nat_client.js index 00434e5c..6cf2b9b2 100644 --- a/examples/nat_client.js +++ b/examples/nat_client.js @@ -1,11 +1,11 @@ -console.log(`nat client starting`) +log.console(`nat client starting`) $_.contact((actor, reason) => { if (actor) { - console.log(`trying to message ${json.encode(actor)}`) + log.console(`trying to message ${json.encode(actor)}`) send(actor, {type:"greet"}) } else { - console.log(json.encode(reason)) + log.console(json.encode(reason)) } }, { address: "108.210.60.32", // NAT server's public IP @@ -16,7 +16,7 @@ $_.contact((actor, reason) => { $_.receiver(e => { switch(e.type) { case 'greet': - console.log(`hello!`) + log.console(`hello!`) break } }) \ No newline at end of file diff --git a/examples/steam_example.js b/examples/steam_example.js index 0aec025d..e5679388 100644 --- a/examples/steam_example.js +++ b/examples/steam_example.js @@ -23,23 +23,23 @@ var stats_loaded = false; // Initialize Steam function init_steam() { if (!steam) { - console.log("Steam module not available"); + log.console("Steam module not available"); return false; } - console.log("Initializing Steam..."); + log.console("Initializing Steam..."); steam_available = steam.steam_init(); if (steam_available) { - console.log("Steam initialized successfully"); + log.console("Steam initialized successfully"); // Request current stats/achievements if (steam.stats.stats_request()) { - console.log("Stats requested"); + log.console("Stats requested"); stats_loaded = true; } } else { - console.log("Failed to initialize Steam"); + log.console("Failed to initialize Steam"); } return steam_available; @@ -59,13 +59,13 @@ function unlock_achievement(achievement_name) { // Check if already unlocked var unlocked = steam.achievement.achievement_get(achievement_name); if (unlocked) { - console.log("Achievement already unlocked:", achievement_name); + log.console("Achievement already unlocked:", achievement_name); return true; } // Unlock it if (steam.achievement.achievement_set(achievement_name)) { - console.log("Achievement unlocked:", achievement_name); + log.console("Achievement unlocked:", achievement_name); // Store stats to make it permanent steam.stats.stats_store(); @@ -87,7 +87,7 @@ function update_stat(stat_name, value, is_float) { } if (success) { - console.log("Stat updated:", stat_name, "=", value); + log.console("Stat updated:", stat_name, "=", value); steam.stats.stats_store(); } @@ -115,7 +115,7 @@ function start_game() { total_score = get_stat(STATS.TOTAL_SCORE, false); current_score = 0; - console.log("Starting game #" + (games_played + 1)); + log.console("Starting game #" + (games_played + 1)); } function end_game(score) { @@ -167,7 +167,7 @@ function load_from_cloud() { function cleanup_steam() { if (steam_available) { steam.steam_shutdown(); - console.log("Steam shut down"); + log.console("Steam shut down"); } } diff --git a/scripts/core/_sdl_video.js b/scripts/core/_sdl_video.js index de05aaab..b710e082 100644 --- a/scripts/core/_sdl_video.js +++ b/scripts/core/_sdl_video.js @@ -108,7 +108,7 @@ $_.receiver(function(msg) { } } catch (e) { response = {error: e.toString()}; - console.error(e) + log.error(e) } send(msg, response); @@ -436,11 +436,11 @@ function handle_renderer(msg) { var tex; // Direct surface data - console.log(json.encode(msg.data)) + log.console(json.encode(msg.data)) var surf = new surface(msg.data) - console.log("GOT DATA") - console.log(json.encode(msg.data)) + log.console("GOT DATA") + log.console(json.encode(msg.data)) if (!surf) throw new Error("Must provide surface_id or surface data") @@ -528,7 +528,7 @@ function handle_texture(msg) { }); } else { - console.log(json.encode(msg.data)) + log.console(json.encode(msg.data)) return {error: "Must provide either surface_id or width/height"}; } diff --git a/scripts/core/engine.js b/scripts/core/engine.js index aa6b1bb7..e8faec99 100644 --- a/scripts/core/engine.js +++ b/scripts/core/engine.js @@ -1,9 +1,70 @@ (function engine() { prosperon.DOC = Symbol('+documentation+') // Symbol for documentation references -globalThis.log = new Proxy({}, { +function caller_data(depth = 0) +{ + var file = "nofile" + var line = 0 + + var caller = new Error().stack.split("\n")[1+depth] + if (caller) { + var md = caller.match(/\((.*)\:/) + var m = md ? md[1] : "SCRIPT" + if (m) file = m + md = caller.match(/\:(\d*)\)/) + m = md ? md[1] : 0 + if (m) line = m + } + + return {file,line} +} + +function console_rec(line, file, msg) { + return `[${prosperon.id.slice(0,5)}] [${file}:${line}]: ${msg}\n` + + var now = time.now() + + var id = prosperon.name ? prosperon.name : prosperon.id + id = id.substring(0,6) + + return `[${id}] [${time.text(now, "mb d yyyy h:nn:ss")}] ${file}:${line}: ${msg}\n` +} + +var console_mod = prosperon.hidden.console + +var logs = {} +logs.console = function(msg) +{ + var caller = caller_data(4) + console_mod.print(console_rec(caller.line, caller.file, msg)) +} + +logs.error = function(e) +{ + if (!e) + e = new Error() + + if (e instanceof Error) + pprint(`${e.name} : ${e.message} +${e.stack}`, 4) + else { + var stack = new Error() + pprint(`${e} +${stack.stack}`,4) + } +} + +logs.panic = function(msg) +{ + pprint(e, 5) + os.quit() +} + +function noop() {} +globalThis.log = new Proxy(logs, { get(target,prop,receiver) { - return function() {} + if (target[prop]) + return (...args) => args.forEach(arg => target[prop](arg)) } }) @@ -11,7 +72,7 @@ globalThis.log = new Proxy({}, { var hidden = prosperon.hidden var actor_mod = hidden.actor var wota = hidden.wota -var console_mod = hidden.console + var use_embed = hidden.use_embed var use_dyn = hidden.use_dyn var enet = hidden.enet @@ -25,8 +86,6 @@ var js = use_embed('js') var io = use_embed('io') -globalThis.console = console_mod - var RESPATH = 'scripts/modules/resources.js' var canonical = io.realdir(RESPATH) + 'resources.js' var content = io.slurp(RESPATH) @@ -40,10 +99,10 @@ function print_api(obj) { for (var prop in obj) { if (!obj.hasOwnProperty(prop)) continue var val = obj[prop] - console.log(prop) + log.console(prop) if (typeof val === 'function') { var m = val.toString().match(/\(([^)]*)\)/) - if (m) console.log(' function: ' + prop + '(' + m[1].trim() + ')') + if (m) log.console(' function: ' + prop + '(' + m[1].trim() + ')') } } } @@ -55,84 +114,6 @@ prosperon.PATH = [ var res_cache = {} -function console_rec(category, priority, line, file, msg) { - return `[${prosperon.id.slice(0,5)}] [${file}:${line}: [${category} ${priority}]: ${msg}\n` - - var now = time.now() - - var id = prosperon.name ? prosperon.name : prosperon.id - id = id.substring(0,6) - - return `[${id}] [${time.text(now, "mb d yyyy h:nn:ss")}] ${file}:${line}: [${category} ${priority}]: ${msg}\n` -} - -function pprint(msg, lvl = 0) { - var file = "nofile" - var line = 0 - - var caller = new Error().stack.split("\n")[2] - if (caller) { - var md = caller.match(/\((.*)\:/) - var m = md ? md[1] : "SCRIPT" - if (m) file = m - md = caller.match(/\:(\d*)\)/) - m = md ? md[1] : 0 - if (m) line = m - } - var fmt = console_rec("script", lvl, line, file, msg) - console.print(fmt) -} - -function format_args(...args) { - return args.map(arg => { - if (typeof arg === 'object' && arg !== null) { - try { - return json.encode(arg) - } catch (e) { - return String(arg) - } - } - return String(arg) - }).join(' ') -} - -console.spam = function spam(...args) { - pprint(format_args(...args), 0) -} -console.debug = function debug(...args) { - pprint(format_args(...args), 1) -} -console.info = function info(...args) { - pprint(format_args(...args), 2) -} -console.warn = function warn(...args) { - pprint(format_args(...args), 3) -} -console.log = function log(...args) { - pprint(format_args(...args), 2) -} -console.error = function error(e) { - if (!e) - e = new Error() - - if (e instanceof Error) - pprint(`${e.name} : ${e.message} -${e.stack}`, 4) - else { - var stack = new Error() - pprint(`${e} -${stack.stack}`,4) - } -} -console.panic = function panic(e) { - pprint(e, 5) - os.quit() -} - -console.assert = function assert(op, str = `assertion failed [value '${op}']`) { - if (!op) console.panic(str) -} - var BASEPATH = 'scripts/core/base.js' var script = io.slurp(BASEPATH) var fnname = "base" @@ -350,7 +331,7 @@ var service_delay = 0.01 $_.portal = function(fn, port) { if (portal) throw new Error(`Already started a portal listening on ${portal.port}`) if (!port) throw new Error("Requires a valid port.") - console.log(`starting a portal on port ${port}`) + log.console(`starting a portal on port ${port}`) portal = enet.create_host({address: "any", port}) portal_fn = fn } @@ -359,23 +340,23 @@ $_.portal[prosperon.DOC] = "A portal is a special actor with a public address th function handle_host(e) { switch (e.type) { case "connect": - console.log(`connected a new peer: ${e.peer.address}:${e.peer.port}`) + log.console(`connected a new peer: ${e.peer.address}:${e.peer.port}`) peers[`${e.peer.address}:${e.peer.port}`] = e.peer var queue = peer_queue.get(e.peer) if (queue) { for (var msg of queue) e.peer.send(nota.encode(msg)) - console.log(`sent ${json.encode(msg)} out of queue`) + log.console(`sent ${json.encode(msg)} out of queue`) peer_queue.delete(e.peer) } break case "disconnect": peer_queue.delete(e.peer) for (var id in peers) if (peers[id] === e.peer) delete peers[id] - console.log('portal got disconnect from ' + e.peer.address + ":" + e.peer.port) + log.console('portal got disconnect from ' + e.peer.address + ":" + e.peer.port) break case "receive": var data = nota.decode(e.data) -// console.log(`got message ${json.encode(data)} over the wire`) +// log.console(`got message ${json.encode(data)} over the wire`) if (data.replycc && !data.replycc.address) { data.replycc.__ACTORDATA__.address = e.peer.address data.replycc.__ACTORDATA__.port = e.peer.port @@ -394,7 +375,7 @@ function handle_host(e) { } } if (data.data) populate_actor_addresses(data.data) -// console.log(`turned it into ${json.encode(data)} over the wire`) +// log.console(`turned it into ${json.encode(data)} over the wire`) handle_message(data) break } @@ -414,7 +395,7 @@ $_.receiver[prosperon.DOC] = "registers a function that will receive all message $_.start = function start(cb, prg, arg) { if (dying) { - console.warn(`Cannot start an underling in the same turn as we're stopping`) + log.warn(`Cannot start an underling in the same turn as we're stopping`) return } var id = util.guid() @@ -458,7 +439,7 @@ $_.delay[prosperon.DOC] = "used to schedule the invocation of a function..." var couplings = new Set() $_.couple = function couple(actor) { - console.log(`coupled to ${actor.__ACTORDATA__.id}`) + log.console(`coupled to ${actor.__ACTORDATA__.id}`) couplings.add(actor.__ACTORDATA__.id) } $_.couple[prosperon.DOC] = "causes this actor to stop when another actor stops." @@ -496,11 +477,11 @@ function actor_send(actor, message) { var peer = peers[actor.__ACTORDATA__.address + ":" + actor.__ACTORDATA__.port] if (!peer) { if (!portal) { - console.log(`creating a contactor ...`) + log.console(`creating a contactor ...`) portal = enet.create_host({address:"any"}) - console.log(`allowing contact to port ${portal.port}`) + log.console(`allowing contact to port ${portal.port}`) } - console.log(`no peer! connecting to ${actor.__ACTORDATA__.address}:${actor.__ACTORDATA__.port}`) + log.console(`no peer! connecting to ${actor.__ACTORDATA__.address}:${actor.__ACTORDATA__.port}`) peer = portal.connect(actor.__ACTORDATA__.address, actor.__ACTORDATA__.port) peer_queue.set(peer, [message]) } else { @@ -528,8 +509,8 @@ function send_messages() { } } if (errors.length > 0) { - console.error("Some messages failed to send:", errors) - for (var i of errors) console.error(i) + log.error("Some messages failed to send:", errors) + for (var i of errors) log.error(i) } } @@ -607,7 +588,7 @@ if (typeof prosperon.args.program !== 'string') actor_mod.setname(prosperon.args.program) function destroyself() { - console.log(`Got the message to destroy self.`) + log.console(`Got the message to destroy self.`) dying = true for (var i of underlings) $_.stop(create_actor({id:i})) @@ -621,7 +602,7 @@ function handle_actor_disconnect(id) { greeter({type: "stopped", id}) delete greeters[id] } - console.log(`actor ${id} disconnected`) + log.console(`actor ${id} disconnected`) if (couplings.has(id)) $_.stop() delete peers[id] } diff --git a/scripts/modules/cmd.js b/scripts/modules/cmd.js index 41e4d4e8..0313aa7c 100644 --- a/scripts/modules/cmd.js +++ b/scripts/modules/cmd.js @@ -83,13 +83,13 @@ Cmdline.register_order( "about", function (argv) { if (!argv[0]) { - console.print("About your game"); - console.print(`Prosperon version ${prosperon.version}`); - console.print(`Total entities ${ur._list.length}`); + log.print("About your game"); + log.print(`Prosperon version ${prosperon.version}`); + log.print(`Total entities ${ur._list.length}`); } switch (argv[0]) { case "entities": - for (var i of ur._list) console.print(i); + for (var i of ur._list) log.print(i); break; } }, @@ -111,8 +111,8 @@ Cmdline.register_order( "input", function (pawn) { use("editor.js"); - console.print(`## Input for ${pawn}`); - eval(`console.print(input.print_md_kbm(${pawn}));`); + log.print(`## Input for ${pawn}`); + eval(`log.print(input.print_md_kbm(${pawn}));`); }, "Print input documentation for a given object as markdown. Give it a file to save the output to", "OBJECT ?FILE?", @@ -122,8 +122,8 @@ Cmdline.print_order = function (fn) { if (typeof fn === "string") fn = Cmdline.orders[fn]; if (!fn) return; - console.print(`Usage: prosperon ${fn.usage}` + "\n"); - console.print(fn.doc + "\n"); + log.print(`Usage: prosperon ${fn.usage}` + "\n"); + log.print(fn.doc + "\n"); }; function parse_args(argv) @@ -198,7 +198,7 @@ Cmdline.register_order( var orfn = Cmdline.orders[order]; if (!orfn) { - console.warn(`No command named ${order}.`); + log.warn(`No command named ${order}.`); return; } @@ -208,7 +208,7 @@ Cmdline.register_order( Cmdline.print_order("help"); - for (var cmd of Object.keys(Cmdline.orders).sort()) console.print(cmd + "\n"); + for (var cmd of Object.keys(Cmdline.orders).sort()) log.print(cmd + "\n"); Cmdline.orders.version(); }, @@ -219,7 +219,7 @@ Cmdline.register_order( Cmdline.register_order( "version", function () { - console.print(`Prosperon version ${prosperon.version} [${prosperon.revision}]` + "\n"); + log.print(`Prosperon version ${prosperon.version} [${prosperon.revision}]` + "\n"); }, "Display Prosperon info.", ); diff --git a/scripts/modules/doc.js b/scripts/modules/doc.js index e67d0a56..29f3d2ba 100644 --- a/scripts/modules/doc.js +++ b/scripts/modules/doc.js @@ -284,7 +284,7 @@ Docstrings are set to the symbol \`prosperon.DOC\` \`\`\`js // Suppose we have a module that returns a function -function greet(name) { console.log("Hello, " + name) } +function greet(name) { log.console("Hello, " + name) } // We can attach a docstring greet.doc = \` @@ -299,7 +299,7 @@ return greet \`\`\`js // Another way is to add a docstring object to an object var greet = { - hello() { console.log('hello!') } + hello() { log.console('hello!') } } greet[prosperon.DOC] = {} diff --git a/scripts/modules/ext/controller.js b/scripts/modules/ext/controller.js index fb6af15a..33e7ebb4 100644 --- a/scripts/modules/ext/controller.js +++ b/scripts/modules/ext/controller.js @@ -295,7 +295,7 @@ var Player = { }, print_pawns() { - [...this.pawns].reverse().forEach(x => console.log(x)) + [...this.pawns].reverse().forEach(x => log.console(x)) }, create() { diff --git a/scripts/modules/ext/emitter.js b/scripts/modules/ext/emitter.js index b8fafce3..91032e39 100644 --- a/scripts/modules/ext/emitter.js +++ b/scripts/modules/ext/emitter.js @@ -15,7 +15,7 @@ ex.garbage = function() ex.update = function(dt) { for (var e of ex.emitters) - try { e.step(dt) } catch(e) { console.error(e) } + try { e.step(dt) } catch(e) { log.error(e) } } ex.step_hook = function(p) diff --git a/scripts/modules/ext/sprite.js b/scripts/modules/ext/sprite.js index 627c4a22..1119a0ce 100644 --- a/scripts/modules/ext/sprite.js +++ b/scripts/modules/ext/sprite.js @@ -66,7 +66,7 @@ var sprite = { set path(p) { var image = graphics.texture(p); if (!image) { - console.warn(`Could not find image ${p}.`); + log.warn(`Could not find image ${p}.`); return; } @@ -109,7 +109,7 @@ var sprite = { t.parent = undefined delete this.transform.sprite delete this._sprite -// console.log("CLEARED SPRITE") +// log.console("CLEARED SPRITE") }, anchor: [0, 0], set layer(v) { this._sprite.layer = v; }, diff --git a/scripts/modules/graphics.js b/scripts/modules/graphics.js index 4e3380ff..185e59a1 100644 --- a/scripts/modules/graphics.js +++ b/scripts/modules/graphics.js @@ -41,17 +41,17 @@ Object.defineProperties(graphics.Image.prototype, { var self = this; // Send message to load texture - console.log("LOADING") + log.console("LOADING") send(renderer_actor, { kind: "renderer", id: renderer_id, op: "loadTexture", data: this[CPU] }, function(response) { - console.log("GOT MSG") + log.console("GOT MSG") if (response.error) { - console.error("Failed to load texture:") - console.error(response.error) + log.error("Failed to load texture:") + log.error(response.error) self[LOADING] = false; } else { self[GPU] = response; @@ -190,7 +190,7 @@ function create_image(path){ throw new Error('Unsupported image structure from decoder'); }catch(e){ - console.error(`Error loading image ${path}: ${e.message}`); + log.error(`Error loading image ${path}: ${e.message}`); throw e; } } @@ -296,14 +296,14 @@ graphics.texture.total_vram[prosperon.DOC] = ` ` graphics.tex_hotreload = function tex_hotreload(file) { - console.log(`hot reloading ${file}`) + log.console(`hot reloading ${file}`) if (!(file in graphics.texture.cache)) return - console.log('really doing it') + log.console('really doing it') var img = create_image(file) var oldimg = graphics.texture.cache[file] - console.log(`new image:${json.encode(img)}`) - console.log(`old image: ${json.encode(oldimg)}`) + log.console(`new image:${json.encode(img)}`) + log.console(`old image: ${json.encode(oldimg)}`) merge_objects(oldimg, img, ['surface', 'texture', 'loop', 'time']) } @@ -356,7 +356,7 @@ graphics.get_font = function get_font(path, size) { data: font.surface }, function(response) { if (response.error) { - console.error("Failed to load font texture:", response.error); + log.error("Failed to load font texture:", response.error); } else { font.texture = response; } diff --git a/scripts/modules/imgui.js b/scripts/modules/imgui.js index c1983d9f..f4cc8dae 100644 --- a/scripts/modules/imgui.js +++ b/scripts/modules/imgui.js @@ -31,7 +31,7 @@ imgui.prosperon_menu = function prosperon_menu() { if (render_menu) { if (debug.console) debug.console = imgui.window("console", _ => { - imgui.text(console.transcript); + imgui.text(log.transcript); replstr = imgui.textinput(undefined, replstr); imgui.button("submit", _ => { eval(replstr); diff --git a/scripts/modules/scenetree.js b/scripts/modules/scenetree.js index 9282e4f3..78003672 100644 --- a/scripts/modules/scenetree.js +++ b/scripts/modules/scenetree.js @@ -264,7 +264,7 @@ function eachobj(obj, fn) { var val = fn(obj) if (val) return val for (var o in obj.objects) { - if (obj.objects[o] === obj) console.error(`Object ${obj.toString()} is referenced by itself.`) + if (obj.objects[o] === obj) log.error(`Object ${obj.toString()} is referenced by itself.`) val = eachobj(obj.objects[o], fn) if (val) return val } diff --git a/scripts/moth.js b/scripts/moth.js index 59b70e33..7ba4bcb6 100644 --- a/scripts/moth.js +++ b/scripts/moth.js @@ -68,7 +68,7 @@ var dir = args[0] if (!io.exists(args[0] + '/main.js')) throw Error(`No main.js found in ${args[0]}`) -console.log('starting game in ' + dir) +log.console('starting game in ' + dir) io.mount(dir) @@ -88,7 +88,7 @@ send(video_actor, { } }, e => { if (e.error) { - console.error(e.error) + log.error(e.error) os.exit(1) } @@ -100,14 +100,14 @@ send(video_actor, { id:window }, e => { if (e.error) { - console.error(e.error) + log.error(e.error) os.exit(1) } render = e.id graphics = use('graphics', video_actor, e.id) - console.log(`Created window and renderer id ${render}`) + log.console(`Created window and renderer id ${render}`) }) }) diff --git a/tests/blob.js b/tests/blob.js index a9407852..926e4b09 100644 --- a/tests/blob.js +++ b/tests/blob.js @@ -12,7 +12,7 @@ var Blob = use('blob') var pp = new Blob() -console.log(pp.length) +log.console(pp.length) // If you're testing in an environment without a 'use' loader, you might do // something like importing the compiled C module or linking it differently. @@ -150,7 +150,7 @@ let tests = [ let b = new Blob(); let length = b.length; let passed = (b instanceof Blob && length === 0); - console.log(`blob len: ${b.length}, is blob? ${b instanceof Blob}`) + log.console(`blob len: ${b.length}, is blob? ${b instanceof Blob}`) let messages = []; if (!(b instanceof Blob)) messages.push("Returned object is not recognized as a blob"); if (length !== 0) messages.push(`Expected length 0, got ${length}`); @@ -618,18 +618,18 @@ for (let i = 0; i < tests.length; i++) { let passedCount = 0; for (let r of results) { let status = r.passed ? "Passed" : "Failed"; - console.log(`${r.testName} - ${status}`); + log.console(`${r.testName} - ${status}`); if (!r.passed && r.messages.length > 0) { - console.log(" " + r.messages.join("\n ")); + log.console(" " + r.messages.join("\n ")); } if (r.passed) passedCount++; } -console.log(`\nResult: ${passedCount}/${results.length} tests passed`); +log.console(`\nResult: ${passedCount}/${results.length} tests passed`); if (passedCount < results.length) { - console.log("Overall: FAILED"); + log.console("Overall: FAILED"); if (os && os.exit) os.exit(1); } else { - console.log("Overall: PASSED"); + log.console("Overall: PASSED"); if (os && os.exit) os.exit(0); } diff --git a/tests/bunnymark.js b/tests/bunnymark.js index b8e06b1f..2de2b9bd 100644 --- a/tests/bunnymark.js +++ b/tests/bunnymark.js @@ -77,7 +77,7 @@ function loop() sprite.forEach(x => x.move(x.dir.scale(dt))) var queue = sprite.queue() - //console.log(json.encode(queue)) + //log.console(json.encode(queue)) for (var q of queue) { if (!q.image) continue diff --git a/tests/camera_colorspace.js b/tests/camera_colorspace.js index b90b3a3c..6cb155d8 100644 --- a/tests/camera_colorspace.js +++ b/tests/camera_colorspace.js @@ -5,16 +5,16 @@ var json = use('json'); // Get list of cameras var cameras = camera.list(); if (cameras.length === 0) { - console.log("No cameras found!"); + log.console("No cameras found!"); $_. stop(); } var cam_id = cameras[0]; -console.log("Testing camera:", camera.name(cam_id)); +log.console("Testing camera:", camera.name(cam_id)); // Get supported formats var formats = camera.supported_formats(cam_id); -console.log("\nLooking for different colorspaces in supported formats..."); +log.console("\nLooking for different colorspaces in supported formats..."); // Group formats by colorspace var colorspaces = {}; @@ -26,21 +26,21 @@ for (var i = 0; i < formats.length; i++) { colorspaces[fmt.colorspace].push(fmt); } -console.log("\nFound colorspaces:"); +log.console("\nFound colorspaces:"); for (var cs in colorspaces) { - console.log(" " + cs + ": " + colorspaces[cs].length + " formats"); + log.console(" " + cs + ": " + colorspaces[cs].length + " formats"); } // Try opening camera with different colorspaces -console.log("\nTrying to open camera with different colorspaces..."); +log.console("\nTrying to open camera with different colorspaces..."); for (var cs in colorspaces) { // Get first format for this colorspace var format = colorspaces[cs][0]; - console.log("\nTrying colorspace '" + cs + "' with format:"); - console.log(" Resolution: " + format.width + "x" + format.height); - console.log(" Pixel format: " + format.format); + log.console("\nTrying colorspace '" + cs + "' with format:"); + log.console(" Resolution: " + format.width + "x" + format.height); + log.console(" Pixel format: " + format.format); // You can also create a custom format with a specific colorspace var custom_format = { @@ -55,18 +55,18 @@ for (var cs in colorspaces) { var cam = camera.open(cam_id, custom_format); if (cam) { var actual = cam.get_format(); - console.log(" Opened successfully!"); - console.log(" Actual colorspace: " + actual.colorspace); + log.console(" Opened successfully!"); + log.console(" Actual colorspace: " + actual.colorspace); // Camera will be closed when object is freed cam = null; } else { - console.log(" Failed to open with this colorspace"); + log.console(" Failed to open with this colorspace"); } // Just test first 3 colorspaces if (Object.keys(colorspaces).indexOf(cs) >= 2) break; } -console.log("\nColorspace test complete!"); +log.console("\nColorspace test complete!"); $_.stop(); \ No newline at end of file diff --git a/tests/camera_colorspace_convert.js b/tests/camera_colorspace_convert.js index 47f6b42d..c05dc958 100644 --- a/tests/camera_colorspace_convert.js +++ b/tests/camera_colorspace_convert.js @@ -6,35 +6,35 @@ var json = use('json'); // Get first camera var cameras = camera.list(); if (cameras.length === 0) { - console.log("No cameras found!"); + log.console("No cameras found!"); $_.stop(); } var cam_id = cameras[0]; -console.log("Using camera:", camera.name(cam_id)); +log.console("Using camera:", camera.name(cam_id)); // Open camera with default settings var cam = camera.open(cam_id); if (!cam) { - console.log("Failed to open camera!"); + log.console("Failed to open camera!"); $_.stop(); } // Get the format being used var format = cam.get_format(); -console.log("\nCamera format:"); -console.log(" Resolution:", format.width + "x" + format.height); -console.log(" Pixel format:", format.format); -console.log(" Colorspace:", format.colorspace); +log.console("\nCamera format:"); +log.console(" Resolution:", format.width + "x" + format.height); +log.console(" Pixel format:", format.format); +log.console(" Colorspace:", format.colorspace); // Handle camera approval var approved = false; $_.receiver(e => { if (e.type === 'camera_device_approved') { - console.log("\nCamera approved!"); + log.console("\nCamera approved!"); approved = true; } else if (e.type === 'camera_device_denied') { - console.error("Camera access denied!"); + log.error("Camera access denied!"); $_.stop(); } }); @@ -46,59 +46,59 @@ function capture_test() { return; } - console.log("\nCapturing frame..."); + log.console("\nCapturing frame..."); var surf = cam.capture(); if (!surf) { - console.log("No frame captured yet, retrying..."); + log.console("No frame captured yet, retrying..."); $_.delay(capture_test, 0.1); return; } - console.log("\nCaptured surface:"); - console.log(" Size:", surf.width + "x" + surf.height); - console.log(" Format:", surf.format); + log.console("\nCaptured surface:"); + log.console(" Size:", surf.width + "x" + surf.height); + log.console(" Format:", surf.format); // Test various colorspace conversions - console.log("\nTesting colorspace conversions:"); + log.console("\nTesting colorspace conversions:"); // Convert to sRGB if not already if (format.colorspace !== "srgb") { try { var srgb_surf = surf.convert(surf.format, "srgb"); - console.log(" Converted to sRGB colorspace"); + log.console(" Converted to sRGB colorspace"); } catch(e) { - console.log(" sRGB conversion failed:", e.message); + log.console(" sRGB conversion failed:", e.message); } } // Convert to linear sRGB for processing try { var linear_surf = surf.convert("rgba8888", "srgb_linear"); - console.log(" Converted to linear sRGB (RGBA8888) for processing"); + log.console(" Converted to linear sRGB (RGBA8888) for processing"); } catch(e) { - console.log(" Linear sRGB conversion failed:", e.message); + log.console(" Linear sRGB conversion failed:", e.message); } // Convert to JPEG colorspace (common for compression) try { var jpeg_surf = surf.convert("rgb888", "jpeg"); - console.log(" Converted to JPEG colorspace (RGB888) for compression"); + log.console(" Converted to JPEG colorspace (RGB888) for compression"); } catch(e) { - console.log(" JPEG colorspace conversion failed:", e.message); + log.console(" JPEG colorspace conversion failed:", e.message); } // If YUV format, try BT.709 (HD video standard) if (surf.format.indexOf("yuv") !== -1 || surf.format.indexOf("yuy") !== -1) { try { var hd_surf = surf.convert(surf.format, "bt709_limited"); - console.log(" Converted to BT.709 limited (HD video standard)"); + log.console(" Converted to BT.709 limited (HD video standard)"); } catch(e) { - console.log(" BT.709 conversion failed:", e.message); + log.console(" BT.709 conversion failed:", e.message); } } - console.log("\nTest complete!"); + log.console("\nTest complete!"); $_.stop(); } diff --git a/tests/camera_info.js b/tests/camera_info.js index d86cdf49..99748a1b 100644 --- a/tests/camera_info.js +++ b/tests/camera_info.js @@ -3,38 +3,38 @@ var camera = use('camera'); // Get camera drivers var drivers = camera.drivers(); -console.log("Available camera drivers:", drivers); +log.console("Available camera drivers:", drivers); // Get list of cameras var cameras = camera.list(); -console.log("Found", cameras.length, "cameras"); +log.console("Found", cameras.length, "cameras"); // Get info about each camera for (var i = 0; i < cameras.length; i++) { var cam_id = cameras[i]; - console.log("\nCamera", i + 1, "ID:", cam_id); - console.log(" Name:", camera.name(cam_id)); - console.log(" Position:", camera.position(cam_id)); + log.console("\nCamera", i + 1, "ID:", cam_id); + log.console(" Name:", camera.name(cam_id)); + log.console(" Position:", camera.position(cam_id)); // Get supported formats var formats = camera.supported_formats(cam_id); - console.log(" Supported formats:", formats.length); + log.console(" Supported formats:", formats.length); // Show first few formats for (var j = 0; j < formats.length; j++) { var fmt = formats[j]; - console.log(" Format", j + 1 + ":"); - console.log(" Pixel format:", fmt.format); - console.log(" Resolution:", fmt.width + "x" + fmt.height); - console.log(" FPS:", fmt.framerate_numerator + "/" + fmt.framerate_denominator, + log.console(" Format", j + 1 + ":"); + log.console(" Pixel format:", fmt.format); + log.console(" Resolution:", fmt.width + "x" + fmt.height); + log.console(" FPS:", fmt.framerate_numerator + "/" + fmt.framerate_denominator, "(" + (fmt.framerate_numerator / fmt.framerate_denominator) + ")"); - console.log(" Colorspace:", fmt.colorspace); + log.console(" Colorspace:", fmt.colorspace); } } // Open the first camera with a specific format if available if (cameras.length > 0) { - console.log("\nOpening first camera..."); + log.console("\nOpening first camera..."); var cam_id = cameras[0]; var formats = camera.supported_formats(cam_id); @@ -49,25 +49,25 @@ if (cameras.length > 0) { var cam; if (preferred_format) { - console.log("Opening with 640x480 format..."); + log.console("Opening with 640x480 format..."); cam = camera.open(cam_id, preferred_format); } else { - console.log("Opening with default format..."); + log.console("Opening with default format..."); cam = camera.open(cam_id); } if (cam) { - console.log("Camera opened successfully!"); - console.log("Driver being used:", cam.get_driver()); + log.console("Camera opened successfully!"); + log.console("Driver being used:", cam.get_driver()); // Get the actual format being used var actual_format = cam.get_format(); - console.log("Actual format being used:"); - console.log(" Pixel format:", actual_format.format); - console.log(" Resolution:", actual_format.width + "x" + actual_format.height); - console.log(" FPS:", actual_format.framerate_numerator + "/" + actual_format.framerate_denominator, + log.console("Actual format being used:"); + log.console(" Pixel format:", actual_format.format); + log.console(" Resolution:", actual_format.width + "x" + actual_format.height); + log.console(" FPS:", actual_format.framerate_numerator + "/" + actual_format.framerate_denominator, "(" + (actual_format.framerate_numerator / actual_format.framerate_denominator) + ")"); - console.log(" Colorspace:", actual_format.colorspace); + log.console(" Colorspace:", actual_format.colorspace); // Clean up - camera will be closed when object is freed cam = null; diff --git a/tests/comments.js b/tests/comments.js index 1284ddb8..08312472 100644 --- a/tests/comments.js +++ b/tests/comments.js @@ -2,7 +2,7 @@ var parseq = use('parseq') function load_comment_from_api(id) { - console.log(`Loading comment #${id}`) + log.console(`Loading comment #${id}`) return { id: id, title: `Comment #${id}` diff --git a/tests/contact.js b/tests/contact.js index fae05370..d624f28e 100644 --- a/tests/contact.js +++ b/tests/contact.js @@ -2,15 +2,15 @@ function contact_fn(actor,reason) { if (actor) { - console.log(`Got an actor: ${json.encode(actor)}`) + log.console(`Got an actor: ${json.encode(actor)}`) send(actor, {greet: "Hello!"}, e => { - console.log(`Got the response ${json.encode(e)}. Goodbye!`); + log.console(`Got the response ${json.encode(e)}. Goodbye!`); $_.stop() }) } else - console.log(`Did not get an actor: ${json.encode(reason)}`) + log.console(`Did not get an actor: ${json.encode(reason)}`) } $_.contact(contact_fn, diff --git a/tests/delay.js b/tests/delay.js index 893570bb..c9784ef1 100644 --- a/tests/delay.js +++ b/tests/delay.js @@ -2,7 +2,7 @@ var count = 0 function loop() { count++; - console.log(`loop ${count}`); + log.console(`loop ${count}`); if (count < 60) $_.delay(loop, 0.01); else diff --git a/tests/draw2d.js b/tests/draw2d.js index 4340d906..8be36290 100644 --- a/tests/draw2d.js +++ b/tests/draw2d.js @@ -12,7 +12,7 @@ var window_id = null; var renderer_id = null; $_.receiver(e => { - console.log(json.encode(e)) + log.console(json.encode(e)) }) // Create window @@ -26,12 +26,12 @@ send(video_actor, { } }, function(response) { if (response.error) { - console.error("Failed to create window:", response.error); + log.error("Failed to create window:", response.error); return; } window_id = response.id; - console.log("Created window with id:", window_id); + log.console("Created window with id:", window_id); // Create renderer send(video_actor, { @@ -40,12 +40,12 @@ send(video_actor, { id: window_id }, function(response) { if (response.error) { - console.error("Failed to create renderer:", response.error); + log.error("Failed to create renderer:", response.error); return; } renderer_id = response.id; - console.log("Created renderer with id:", renderer_id); + log.console("Created renderer with id:", renderer_id); // Configure draw2d and graphics draw2d = use('draw2d', video_actor, renderer_id) @@ -220,7 +220,7 @@ function start_drawing() { if (frame < 600) { // Run for 10 seconds $_.delay(draw_frame, 1/60); } else { - console.log("Test completed - drew", frame, "frames"); + log.console("Test completed - drew", frame, "frames"); $_.delay($_.stop, 0.5); } } diff --git a/tests/dull.js b/tests/dull.js index c6bc99ef..9545ec4d 100644 --- a/tests/dull.js +++ b/tests/dull.js @@ -1,6 +1,6 @@ var render = use('render') -for (var i in render) console.log(i) +for (var i in render) log.console(i) function loop() { diff --git a/tests/http.js b/tests/http.js index 6959e4b4..170f6986 100644 --- a/tests/http.js +++ b/tests/http.js @@ -9,12 +9,12 @@ var got = false var count = 0 http.fetch("https://dictionary.ink/find?word=theological", { on_data: e => { - console.log(e.length) + log.console(e.length) count++ }, callback: e => { - for (var i in e) console.log(i) - console.log(e.data) + for (var i in e) log.console(i) + log.console(e.data) got = true } }) @@ -23,7 +23,7 @@ while (!got) { http.poll() } -console.log(`got hit ${count} times`) +log.console(`got hit ${count} times`) os.exit() @@ -214,30 +214,30 @@ function processResults() { results.push({ testName, passed, messages }); if (!passed) { - console.log(`\nDetailed Failure Report for ${testName}:`); - console.log(`URL: ${test.url}`); - console.log(messages.join("\n")); - console.log(""); + log.console(`\nDetailed Failure Report for ${testName}:`); + log.console(`URL: ${test.url}`); + log.console(messages.join("\n")); + log.console(""); } } // Summary - console.log("\nTest Summary:"); + log.console("\nTest Summary:"); results.forEach(result => { - console.log(`${result.testName} - ${result.passed ? "Passed" : "Failed"}`); + log.console(`${result.testName} - ${result.passed ? "Passed" : "Failed"}`); if (!result.passed) { - console.log(result.messages.join("\n")); + log.console(result.messages.join("\n")); } }); let passedCount = results.filter(r => r.passed).length; - console.log(`\nResult: ${passedCount}/${testCount} tests passed`); + log.console(`\nResult: ${passedCount}/${testCount} tests passed`); if (passedCount < testCount) { - console.log("Overall: FAILED"); + log.console("Overall: FAILED"); os.exit(1); } else { - console.log("Overall: PASSED"); + log.console("Overall: PASSED"); os.exit(0); } } diff --git a/tests/https.js b/tests/https.js index 9e0f90da..87508338 100644 --- a/tests/https.js +++ b/tests/https.js @@ -9,7 +9,7 @@ function checkin() if (download_complete) return send(downloader, {type:'status'}, e => { - console.log("Status:", json.encode(e)) + log.console("Status:", json.encode(e)) // Check if download is complete or error if (e.type === 'error' || (e.type === 'status_response' && e.status === 'idle')) { @@ -23,7 +23,7 @@ function checkin() } $_.start(e => { - console.log(json.encode(e)) + log.console(json.encode(e)) if (e.type === 'greet') { downloader = e.actor @@ -32,13 +32,13 @@ $_.start(e => { type:'download', url: 'https://dictionary.ink/find?word=palm' }, e => { - console.log("Download response:", json.encode(e)) + log.console("Download response:", json.encode(e)) download_complete = true if (e.type === 'complete') { - console.log("Download complete! Size:", e.size, "bytes") + log.console("Download complete! Size:", e.size, "bytes") } else if (e.type === 'error') { - console.log("Download failed:", e.error) + log.console("Download failed:", e.error) } }) diff --git a/tests/nota.js b/tests/nota.js index 7f5227db..dcb07c2f 100644 --- a/tests/nota.js +++ b/tests/nota.js @@ -243,30 +243,30 @@ for (let test of testCases) { results.push({ testName, passed, messages }); if (!passed) { - console.log(`\nDetailed Failure Report for ${testName}:`); - console.log(`Input: ${JSON.stringify(test.input)}`); - if (test.replacer) console.log(`Replacer: ${test.replacer.toString()}`); - if (test.reviver) console.log(`Reviver: ${test.reviver.toString()}`); - console.log(messages.join("\n")); - console.log(""); + log.console(`\nDetailed Failure Report for ${testName}:`); + log.console(`Input: ${JSON.stringify(test.input)}`); + if (test.replacer) log.console(`Replacer: ${test.replacer.toString()}`); + if (test.reviver) log.console(`Reviver: ${test.reviver.toString()}`); + log.console(messages.join("\n")); + log.console(""); } } // Summary -console.log("\nTest Summary:"); +log.console("\nTest Summary:"); results.forEach(result => { - console.log(`${result.testName} - ${result.passed ? "Passed" : "Failed"}`); + log.console(`${result.testName} - ${result.passed ? "Passed" : "Failed"}`); if (!result.passed) - console.log(result.messages) + log.console(result.messages) }); let passedCount = results.filter(r => r.passed).length; -console.log(`\nResult: ${passedCount}/${testCount} tests passed`); +log.console(`\nResult: ${passedCount}/${testCount} tests passed`); if (passedCount < testCount) { - console.log("Overall: FAILED"); + log.console("Overall: FAILED"); // os.exit(1); } else { - console.log("Overall: PASSED"); + log.console("Overall: PASSED"); // os.exit(0); } \ No newline at end of file diff --git a/tests/overling.js b/tests/overling.js index 1a9f6055..43b49cea 100644 --- a/tests/overling.js +++ b/tests/overling.js @@ -1,8 +1,8 @@ $_.start(e => { switch(e.type) { case "actor_started": - console.log(json.encode(e)) - $_.connection(e => console.log(json.encode(e)), e.actor) // get connection info + log.console(json.encode(e)) + $_.connection(e => log.console(json.encode(e)), e.actor) // get connection info send(e.actor, {message: "Hello!"}) diff --git a/tests/parseq.js b/tests/parseq.js index 5a041360..f9eec3d6 100644 --- a/tests/parseq.js +++ b/tests/parseq.js @@ -21,7 +21,7 @@ var actor = $_.start(undefined, "tests/comments.js") send(actor, tree, (result, reason) => { if (reason) - console.log(reason) + log.console(reason) else - console.log(json.encode(result)) + log.console(json.encode(result)) }); diff --git a/tests/portal.js b/tests/portal.js index 97ea7e91..fc2487cf 100644 --- a/tests/portal.js +++ b/tests/portal.js @@ -10,7 +10,7 @@ $_.portal(e => { }, 5678); $_.receiver(e => { - console.log(`Got message: ${json.encode(e)}`) + log.console(`Got message: ${json.encode(e)}`) send(e, {greet: "Hello back!"}) $_.delay(_ => $_.stop(), 0.2) }) diff --git a/tests/qr.js b/tests/qr.js index 7c018fef..c67c935f 100644 --- a/tests/qr.js +++ b/tests/qr.js @@ -8,5 +8,5 @@ var myqr = qr.encode("HELLO WORLD", { casesensitive: false }) -console.log("test finished success.") +log.console("test finished success.") os.exit() diff --git a/tests/qr_drag.js b/tests/qr_drag.js index bdfc9bfd..4464ad06 100644 --- a/tests/qr_drag.js +++ b/tests/qr_drag.js @@ -46,26 +46,26 @@ var qr = use('qr') var lvl = io.slurp('tests/level.json') var lvl_json = lvl -console.log(`json size is ${lvl.length}`) +log.console(`json size is ${lvl.length}`) lvl = json.decode(lvl) lvl = nota.encode(lvl) -console.log(`nota size is ${lvl.byteLength}`) +log.console(`nota size is ${lvl.byteLength}`) var lvl_cmp = miniz.compress(lvl) var lvl_json_cmp = miniz.compress(lvl_json) -console.log(`compressed json is ${lvl_json_cmp.byteLength}`) -console.log(`compressed nota is ${lvl_cmp.byteLength}`) +log.console(`compressed json is ${lvl_json_cmp.byteLength}`) +log.console(`compressed nota is ${lvl_cmp.byteLength}`) var uncmp = miniz.decompress(lvl_cmp, false) -console.log(uncmp.byteLength) +log.console(uncmp.byteLength) -console.log(`json cmp width: ${qr.encode(lvl_json_cmp).width}`) +log.console(`json cmp width: ${qr.encode(lvl_json_cmp).width}`) var qr_lvl = qr.encode(lvl_cmp) -console.log(`nota cmp width: ${qr_lvl.width}`) +log.console(`nota cmp width: ${qr_lvl.width}`) var lvl_bytes = qr.rgba(qr_lvl) -console.log(lvl_bytes.buffer.byteLength) -console.log(json.encode(lvl_bytes)) +log.console(lvl_bytes.buffer.byteLength) +log.console(json.encode(lvl_bytes)) var bsurf = graphics.surface_from_pixels(lvl_bytes) @@ -74,7 +74,7 @@ var frame_img = graphics.texture("alcinaqr") var blit_img = graphics.from_surface("frame", frame_img.cpu.dup()) var qr_size = lvl_bytes.width*4 -console.log(`blowing it up to ${qr_size}`) +log.console(`blowing it up to ${qr_size}`) var qr_rect = {x:300, y:500, width:qr_size, height:qr_size} var gutter = 25 // pixels per side var qr_rect_gutter = { @@ -135,7 +135,7 @@ $_.receiver(e => { switch(e.type) { case "drop_file": - console.log(`got ${e.data} dropped`) + log.console(`got ${e.data} dropped`) var data = io.slurpbytes(e.data) img = graphics.make_texture(data) var qr_surf = img;//extract_qr_surface(img) @@ -143,23 +143,23 @@ $_.receiver(e => { var image = {surface:qr_surf_scaled} display = graphics.from_surface("aaa", qr_surf_scaled) var data = qr.decode(image.surface.pixels(), image.surface.width, image.surface.height, image.surface.pitch) - console.log(`found ${data.length} qr codes`) + log.console(`found ${data.length} qr codes`) if (data.length == 0) break data = data[0] - console.log(data.byteLength) + log.console(data.byteLength) var ddata = miniz.decompress(data, false) - console.log(ddata.byteLength) - console.log(`qr data size was ${data.byteLength}, uncompressed ${ddata.byteLength}`) + log.console(ddata.byteLength) + log.console(`qr data size was ${data.byteLength}, uncompressed ${ddata.byteLength}`) var nn = nota.decode(ddata) - console.log(json.encode(nn)) + log.console(json.encode(nn)) break; case "drop_text": - console.log(`text ${e.data} dropped`) + log.console(`text ${e.data} dropped`) // if e.data is a url, fetch it if (is_url(e.data)) { - console.log('fetching!') + log.console('fetching!') http.fetch(e.data, parse_data) } break; diff --git a/tests/reply.js b/tests/reply.js index da1c8290..8bda74c2 100644 --- a/tests/reply.js +++ b/tests/reply.js @@ -1,7 +1,7 @@ var os = use('os') $_.receiver(e => { - console.log(`Got a message: ${json.encode(e)}`) + log.console(`Got a message: ${json.encode(e)}`) send(e, { message: "Good to go." diff --git a/tests/send.js b/tests/send.js index 3c5ad924..859975db 100644 --- a/tests/send.js +++ b/tests/send.js @@ -1,9 +1,9 @@ var os = use('os') $_.start(e => { - console.log(json.encode(e.actor)) + log.console(json.encode(e.actor)) send(e.actor, { message: "Hello! Good to go?" }, msg => { - console.log(`Original sender got message back: ${json.encode(msg)}. Stopping!`) + log.console(`Original sender got message back: ${json.encode(msg)}. Stopping!`) $_.stop() }) }, "tests/reply.js") diff --git a/tests/spawn_actor.js b/tests/spawn_actor.js index 117d28a0..efe93195 100644 --- a/tests/spawn_actor.js +++ b/tests/spawn_actor.js @@ -1,2 +1,2 @@ this.spawn() -console.log("SPAWNED") +log.console("SPAWNED") diff --git a/tests/spawnee.js b/tests/spawnee.js index cc0b9a66..d9addde1 100644 --- a/tests/spawnee.js +++ b/tests/spawnee.js @@ -1 +1 @@ -console.log("im alive") \ No newline at end of file +log.console("im alive") \ No newline at end of file diff --git a/tests/spawner.js b/tests/spawner.js index 3d98c85a..cb44df20 100644 --- a/tests/spawner.js +++ b/tests/spawner.js @@ -6,7 +6,7 @@ function spawnem() } with ([1,2,3]) { - console.log(toString()) + log.console(toString()) } $_.delay(spawnem, 3) \ No newline at end of file diff --git a/tests/steam.js b/tests/steam.js index dd7a6db1..73a72e73 100644 --- a/tests/steam.js +++ b/tests/steam.js @@ -1,40 +1,40 @@ var steam = use("steam"); -console.log("Steam module loaded:", steam); +log.console("Steam module loaded:", steam); if (steam) { - console.log("Steam functions available:"); - console.log("- steam_init:", typeof steam.steam_init); - console.log("- steam_shutdown:", typeof steam.steam_shutdown); - console.log("- steam_run_callbacks:", typeof steam.steam_run_callbacks); + log.console("Steam functions available:"); + log.console("- steam_init:", typeof steam.steam_init); + log.console("- steam_shutdown:", typeof steam.steam_shutdown); + log.console("- steam_run_callbacks:", typeof steam.steam_run_callbacks); - console.log("\nSteam sub-modules:"); - console.log("- stats:", steam.stats); - console.log("- achievement:", steam.achievement); - console.log("- app:", steam.app); - console.log("- user:", steam.user); - console.log("- friends:", steam.friends); - console.log("- cloud:", steam.cloud); + log.console("\nSteam sub-modules:"); + log.console("- stats:", steam.stats); + log.console("- achievement:", steam.achievement); + log.console("- app:", steam.app); + log.console("- user:", steam.user); + log.console("- friends:", steam.friends); + log.console("- cloud:", steam.cloud); // Try to initialize Steam - console.log("\nAttempting to initialize Steam..."); + log.console("\nAttempting to initialize Steam..."); var init_result = steam.steam_init(); - console.log("Initialization result:", init_result); + log.console("Initialization result:", init_result); if (init_result) { // Get some basic info - console.log("\nApp ID:", steam.app.app_id()); - console.log("User logged on:", steam.user.user_logged_on()); + log.console("\nApp ID:", steam.app.app_id()); + log.console("User logged on:", steam.user.user_logged_on()); if (steam.user.user_logged_on()) { - console.log("User name:", steam.friends.friends_name()); - console.log("User state:", steam.friends.friends_state()); + log.console("User name:", steam.friends.friends_name()); + log.console("User state:", steam.friends.friends_state()); } // Shutdown when done steam.steam_shutdown(); - console.log("Steam shut down"); + log.console("Steam shut down"); } } else { - console.log("Steam module not available (compiled without Steam support)"); + log.console("Steam module not available (compiled without Steam support)"); } \ No newline at end of file diff --git a/tests/surface.js b/tests/surface.js index fa2e9c3d..693fb30c 100644 --- a/tests/surface.js +++ b/tests/surface.js @@ -3,35 +3,35 @@ var Surface = use('surface'); // Test creating a surface var surf = new Surface({width: 100, height: 100}); -console.log("Created surface:", surf.width, "x", surf.height); +log.console("Created surface:", surf.width, "x", surf.height); -console.log(json.encode(surf)) +log.console(json.encode(surf)) // Test fill surf.fill([1, 0, 0, 1]); // Red // Test dup var surf2 = surf.dup(); -console.log("Duplicated surface:", surf2.width, "x", surf2.height); +log.console("Duplicated surface:", surf2.width, "x", surf2.height); // Test scale var surf3 = surf.scale([50, 50], "linear"); -console.log("Scaled surface:", surf3.width, "x", surf3.height); +log.console("Scaled surface:", surf3.width, "x", surf3.height); // Test format -console.log("Surface format:", surf.format); +log.console("Surface format:", surf.format); // Test pixels var pixels = surf.pixels(); -console.log("Got pixels array buffer, length:", pixels.byteLength); +log.console("Got pixels array buffer, length:", pixels.byteLength); // Test creating surface with custom format var surf4 = new Surface({width: 64, height: 64, format: "rgb24"}); -console.log("Created RGB24 surface:", surf4.width, "x", surf4.height, "format:", surf4.format); +log.console("Created RGB24 surface:", surf4.width, "x", surf4.height, "format:", surf4.format); // Test creating surface from pixels var pixelData = new ArrayBuffer(32 * 32 * 4); // 32x32 RGBA var surf5 = new Surface({width: 32, height: 32, pixels: pixelData}); -console.log("Created surface from pixels:", surf5.width, "x", surf5.height); +log.console("Created surface from pixels:", surf5.width, "x", surf5.height); -console.log("Surface module test passed!"); \ No newline at end of file +log.console("Surface module test passed!"); \ No newline at end of file diff --git a/tests/surface_colorspace.js b/tests/surface_colorspace.js index 86873351..ca14f4e3 100644 --- a/tests/surface_colorspace.js +++ b/tests/surface_colorspace.js @@ -9,39 +9,39 @@ var surf = surface({ format: "rgb888" }); -console.log("Created surface:"); -console.log(" Size:", surf.width + "x" + surf.height); -console.log(" Format:", surf.format); +log.console("Created surface:"); +log.console(" Size:", surf.width + "x" + surf.height); +log.console(" Format:", surf.format); // Fill with a test color surf.fill([1, 0.5, 0.25, 1]); // Orange color // Test 1: Convert format only (no colorspace change) -console.log("\nTest 1: Convert to RGBA8888 format only"); +log.console("\nTest 1: Convert to RGBA8888 format only"); var converted1 = surf.convert("rgba8888"); -console.log(" New format:", converted1.format); +log.console(" New format:", converted1.format); // Test 2: Convert format and colorspace -console.log("\nTest 2: Convert to YUY2 format with JPEG colorspace"); +log.console("\nTest 2: Convert to YUY2 format with JPEG colorspace"); var converted2 = surf.convert("yuy2", "jpeg"); -console.log(" New format:", converted2.format); +log.console(" New format:", converted2.format); // Test 3: Try different colorspaces var colorspaces = ["srgb", "srgb_linear", "jpeg", "bt601_limited", "bt709_limited"]; var test_format = "rgba8888"; -console.log("\nTest 3: Converting to", test_format, "with different colorspaces:"); +log.console("\nTest 3: Converting to", test_format, "with different colorspaces:"); for (var i = 0; i < colorspaces.length; i++) { try { var conv = surf.convert(test_format, colorspaces[i]); - console.log(" " + colorspaces[i] + ": Success"); + log.console(" " + colorspaces[i] + ": Success"); } catch(e) { - console.log(" " + colorspaces[i] + ": Failed -", e.message); + log.console(" " + colorspaces[i] + ": Failed -", e.message); } } // Test 4: YUV formats with appropriate colorspaces -console.log("\nTest 4: YUV format conversions:"); +log.console("\nTest 4: YUV format conversions:"); var yuv_tests = [ {format: "yuy2", colorspace: "jpeg"}, {format: "nv12", colorspace: "bt601_limited"}, @@ -53,11 +53,11 @@ for (var i = 0; i < yuv_tests.length; i++) { var test = yuv_tests[i]; try { var conv = surf.convert(test.format, test.colorspace); - console.log(" " + test.format + " with " + test.colorspace + ": Success"); + log.console(" " + test.format + " with " + test.colorspace + ": Success"); } catch(e) { - console.log(" " + test.format + " with " + test.colorspace + ": Failed -", e.message); + log.console(" " + test.format + " with " + test.colorspace + ": Failed -", e.message); } } -console.log("\nColorspace conversion test complete!"); +log.console("\nColorspace conversion test complete!"); $_.stop(); \ No newline at end of file diff --git a/tests/test_actor_access.js b/tests/test_actor_access.js index ca60aa50..25cebc08 100644 --- a/tests/test_actor_access.js +++ b/tests/test_actor_access.js @@ -1,18 +1,18 @@ // Test that actors have access to $_ -console.log("Testing actor access to $_:"); +log.console("Testing actor access to $_:"); // In an actor script, $_ should be available if (typeof $_ !== 'undefined') { - console.log("✓ Actor has access to $_"); - console.log(" $_.random is a", typeof $_.random); - console.log(" $_.clock is a", typeof $_.clock); + log.console("✓ Actor has access to $_"); + log.console(" $_.random is a", typeof $_.random); + log.console(" $_.clock is a", typeof $_.clock); // Test spawning another actor var child = this.spawn('test_child_actor.js'); // Test using a module var testModule = use('test_module'); - console.log("✓ Module loaded, result:", testModule.test()); + log.console("✓ Module loaded, result:", testModule.test()); } else { - console.error("✗ Actor does NOT have access to $_"); + log.error("✗ Actor does NOT have access to $_"); } \ No newline at end of file diff --git a/tests/test_args.js b/tests/test_args.js index f5896924..d0438342 100644 --- a/tests/test_args.js +++ b/tests/test_args.js @@ -1,8 +1,8 @@ // Test module to verify argument passing -console.log("Test args module loaded"); -console.log("Number of arguments:", arg.length); -console.log("Arguments received:", arg); +log.console("Test args module loaded"); +log.console("Number of arguments:", arg.length); +log.console("Arguments received:", arg); function createMessage(prefix) { prefix = prefix || "default"; diff --git a/tests/test_child_actor.js b/tests/test_child_actor.js index 5a55a775..c91e93bd 100644 --- a/tests/test_child_actor.js +++ b/tests/test_child_actor.js @@ -1,8 +1,8 @@ // Child actor test -console.log("Child actor spawned"); +log.console("Child actor spawned"); if (typeof $_ !== 'undefined') { - console.log("✓ Child actor has access to $_"); + log.console("✓ Child actor has access to $_"); } else { - console.error("✗ Child actor does NOT have access to $_"); + log.error("✗ Child actor does NOT have access to $_"); } \ No newline at end of file diff --git a/tests/test_event_watch.js b/tests/test_event_watch.js index 712bea5f..38c66e60 100644 --- a/tests/test_event_watch.js +++ b/tests/test_event_watch.js @@ -6,20 +6,20 @@ input.watch($_); $_.receiver(msg => { if (msg.type) { - console.log("Received event:", msg.type); + log.console("Received event:", msg.type); // Log specific event details switch(msg.type) { case "key_down": case "key_up": - console.log(" Key:", msg.key, "Scancode:", msg.scancode, "Down:", msg.down); + log.console(" Key:", msg.key, "Scancode:", msg.scancode, "Down:", msg.down); break; case "mouse_motion": - console.log(" Mouse position:", msg.pos, "Delta:", msg.d_pos); + log.console(" Mouse position:", msg.pos, "Delta:", msg.d_pos); break; case "mouse_button_down": case "mouse_button_up": - console.log(" Button:", msg.button, "Position:", msg.mouse, "Down:", msg.down); + log.console(" Button:", msg.button, "Position:", msg.mouse, "Down:", msg.down); break; } @@ -28,11 +28,11 @@ $_.receiver(msg => { $_.event_count++; if ($_.event_count >= 10) { - console.log("Received 10 events, stopping watch"); + log.console("Received 10 events, stopping watch"); input.unwatch($_); } } }); -console.log("Event watcher started. Press keys or move mouse to generate events."); -console.log("Will stop after 10 events."); \ No newline at end of file +log.console("Event watcher started. Press keys or move mouse to generate events."); +log.console("Will stop after 10 events."); \ No newline at end of file diff --git a/tests/test_module.js b/tests/test_module.js index 5dff7e41..e17e275f 100644 --- a/tests/test_module.js +++ b/tests/test_module.js @@ -2,10 +2,10 @@ function test() { if (typeof $_ !== 'undefined') { - console.error("✗ Module incorrectly has access to $_!"); + log.error("✗ Module incorrectly has access to $_!"); return "ERROR: Module has $_ access"; } else { - console.log("✓ Module correctly does NOT have access to $_"); + log.console("✓ Module correctly does NOT have access to $_"); return "Module loaded without $_ access"; } } diff --git a/tests/test_use_args.js b/tests/test_use_args.js index 357e2a75..8615fe76 100644 --- a/tests/test_use_args.js +++ b/tests/test_use_args.js @@ -1,18 +1,18 @@ // Test script to verify use() with arguments -console.log("Testing use() with arguments:"); +log.console("Testing use() with arguments:"); // Test 1: Load module without arguments var module1 = use('test_args'); -console.log("Module 1 message:", module1.message); -console.log("Module 1 args:", module1.args); +log.console("Module 1 message:", module1.message); +log.console("Module 1 args:", module1.args); // Test 2: Load module with arguments var module2 = use('test_args', 'hello', 'world', 123); -console.log("Module 2 message:", module2.message); -console.log("Module 2 all args:", module2.allArgs()); +log.console("Module 2 message:", module2.message); +log.console("Module 2 all args:", module2.allArgs()); // Test 3: Verify modules are cached (should return same as module1) var module3 = use('test_args'); -console.log("Module 3 (cached) message:", module3.message); -console.log("Are module1 and module3 the same?", module1 === module3); \ No newline at end of file +log.console("Module 3 (cached) message:", module3.message); +log.console("Are module1 and module3 the same?", module1 === module3); \ No newline at end of file diff --git a/tests/underling.js b/tests/underling.js index a3dc93ce..3fc660d0 100644 --- a/tests/underling.js +++ b/tests/underling.js @@ -1,5 +1,5 @@ var os = use('os') $_.receiver(e => { - console.log(`got message: ${json.encode(e)}`) + log.console(`got message: ${json.encode(e)}`) }) diff --git a/tests/unneeded.js b/tests/unneeded.js index 9bf0c7b3..bad30692 100644 --- a/tests/unneeded.js +++ b/tests/unneeded.js @@ -1,4 +1,4 @@ $_.unneeded(_ => { - console.log("Unneded function fired."); + log.console("Unneded function fired."); $_.unneeded($_.stop, 1); }, 1); diff --git a/tests/webcam.js b/tests/webcam.js index b5487973..40a28434 100644 --- a/tests/webcam.js +++ b/tests/webcam.js @@ -21,10 +21,10 @@ var webcam_texture = null; // Handle camera events $_.receiver(e => { if (e.type === 'camera_device_approved' && e.which === cam_id) { - console.log("Camera approved!"); + log.console("Camera approved!"); cam_approved = true; } else if (e.type === 'camera_device_denied' && e.which === cam_id) { - console.error("Camera access denied!"); + log.error("Camera access denied!"); $_.stop(); } }) @@ -40,12 +40,12 @@ send(video_actor, { } }, function(response) { if (response.error) { - console.error("Failed to create window:", response.error); + log.error("Failed to create window:", response.error); return; } window_id = response.id; - console.log("Created window with id:", window_id); + log.console("Created window with id:", window_id); // Create renderer send(video_actor, { @@ -54,12 +54,12 @@ send(video_actor, { id: window_id }, function(response) { if (response.error) { - console.error("Failed to create renderer:", response.error); + log.error("Failed to create renderer:", response.error); return; } renderer_id = response.id; - console.log("Created renderer with id:", renderer_id); + log.console("Created renderer with id:", renderer_id); // Configure draw2d and graphics draw2d = use('draw2d', video_actor, renderer_id) @@ -68,23 +68,23 @@ send(video_actor, { // List available cameras var cameras = camera.list(); if (cameras.length === 0) { - console.error("No cameras found!"); - console.log(json.encode(cameras)) + log.error("No cameras found!"); + log.console(json.encode(cameras)) $_.stop(); return; } - console.log("Found", cameras.length, "camera(s)"); + log.console("Found", cameras.length, "camera(s)"); // Open the first camera cam_id = cameras[0]; var cam_name = camera.name(cam_id); var cam_position = camera.position(cam_id); - console.log("Opening camera:", cam_name, "Position:", cam_position); + log.console("Opening camera:", cam_name, "Position:", cam_position); // Get supported formats and try to find a good one var formats = camera.supported_formats(cam_id); - console.log("Camera supports", formats.length, "formats"); + log.console("Camera supports", formats.length, "formats"); // Look for a 640x480 format with preferred colorspace var preferred_format = null; @@ -106,7 +106,7 @@ send(video_actor, { preferred_format.framerate_numerator = 30 if (preferred_format) { - console.log("Using format:", preferred_format.width + "x" + preferred_format.height, + log.console("Using format:", preferred_format.width + "x" + preferred_format.height, "FPS:", preferred_format.framerate_numerator + "/" + preferred_format.framerate_denominator, "Format:", preferred_format.format, "Colorspace:", preferred_format.colorspace); @@ -116,20 +116,20 @@ send(video_actor, { } if (!cam_obj) { - console.error("Failed to open camera!"); + log.error("Failed to open camera!"); $_.stop(); return; } - console.log("Camera driver:", cam_obj.get_driver()); + log.console("Camera driver:", cam_obj.get_driver()); // Get and display the actual format being used var actual_format = cam_obj.get_format(); - console.log("Actual camera format:"); - console.log(" Resolution:", actual_format.width + "x" + actual_format.height); - console.log(" Format:", actual_format.format); - console.log(" Colorspace:", actual_format.colorspace); - console.log(" FPS:", actual_format.framerate_numerator + "/" + actual_format.framerate_denominator); + log.console("Actual camera format:"); + log.console(" Resolution:", actual_format.width + "x" + actual_format.height); + log.console(" Format:", actual_format.format); + log.console(" Colorspace:", actual_format.colorspace); + log.console(" FPS:", actual_format.framerate_numerator + "/" + actual_format.framerate_denominator); // Start capturing after a short delay to wait for approval $_.delay(start_capturing, 0.5); @@ -140,7 +140,7 @@ var captured = false function start_capturing() { if (!cam_approved) { - console.log("Waiting for camera approval..."); + log.console("Waiting for camera approval..."); $_.delay(start_capturing, 0.1); return; } @@ -231,7 +231,7 @@ function start_capturing() { if (frame < 300) { // Run for 10 seconds $_.delay(capture_and_draw, 1/30); } else { - console.log("Test completed - captured", frame, "frames"); + log.console("Test completed - captured", frame, "frames"); // Clean up resources if (webcam_texture) { @@ -255,7 +255,7 @@ function start_capturing() { $_.delay(_ => { // Capture frame from camera var surface = cam_obj.capture().convert("rgba8888", "srgb") - console.log('capturing!') + log.console('capturing!') graphics.save_png("test.png", surface.width, surface.height, surface.pixels(),surface.pitch) }, 3) diff --git a/tests/window.js b/tests/window.js index e8712c4a..7595f4ee 100644 --- a/tests/window.js +++ b/tests/window.js @@ -53,5 +53,5 @@ $_.receiver(e => { if (e.type === 'quit') os.exit() else - console.log(json.encode(e)) + log.console(json.encode(e)) }) diff --git a/tests/wota.js b/tests/wota.js index cbc04673..e85cf5a7 100644 --- a/tests/wota.js +++ b/tests/wota.js @@ -231,30 +231,30 @@ for (let test of testCases) { results.push({ testName, passed, messages }); if (!passed) { - console.log(`\nDetailed Failure Report for ${testName}:`); - console.log(`Input: ${JSON.stringify(test.input)}`); - if (test.replacer) console.log(`Replacer: ${test.replacer.toString()}`); - if (test.reviver) console.log(`Reviver: ${test.reviver.toString()}`); - console.log(messages.join("\n")); - console.log(""); + log.console(`\nDetailed Failure Report for ${testName}:`); + log.console(`Input: ${JSON.stringify(test.input)}`); + if (test.replacer) log.console(`Replacer: ${test.replacer.toString()}`); + if (test.reviver) log.console(`Reviver: ${test.reviver.toString()}`); + log.console(messages.join("\n")); + log.console(""); } } // Summary -console.log("\nTest Summary:"); +log.console("\nTest Summary:"); results.forEach(result => { - console.log(`${result.testName} - ${result.passed ? "Passed" : "Failed"}`); + log.console(`${result.testName} - ${result.passed ? "Passed" : "Failed"}`); if (!result.passed) - console.log(result.messages); + log.console(result.messages); }); let passedCount = results.filter(r => r.passed).length; -console.log(`\nResult: ${passedCount}/${testCount} tests passed`); +log.console(`\nResult: ${passedCount}/${testCount} tests passed`); if (passedCount < testCount) { - console.log("Overall: FAILED"); + log.console("Overall: FAILED"); os.exit(1); } else { - console.log("Overall: PASSED"); + log.console("Overall: PASSED"); os.exit(0); }