All files / skin-beatoraja/src lua-diagnostics.ts

71.42% Statements 5/7
50% Branches 2/4
100% Functions 2/2
60% Lines 3/5

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24          84x             67x             7x        
/**
 * Whether the Lua sandbox logs each `require()` and `dofile()` it resolves, to trace a skin's load. Off, so a player's
 * console stays quiet: a skin's load resolves dozens of them. Turn it on in source while debugging a skin, as
 * player-web's `BEATORAJA_VIEW_DIAGNOSTICS`. Missing modules raise Lua errors, which a skin can catch with `pcall`.
 */
const BEATORAJA_LUA_DIAGNOSTICS = false;
 
/**
 * Logs how a `require()` resolved, behind {@link BEATORAJA_LUA_DIAGNOSTICS}. Direct `console.log` (not via the
 * player-web logger wrapper) so devtools resolves source-line clicks to the sandbox rather than to a logger module.
 */
export function logLuaRequire(name: string, kind: 'builtin' | 'module' | 'missing'): void {
  Eif (!BEATORAJA_LUA_DIAGNOSTICS) return;
  // eslint-disable-next-line no-console
  console.log(`[beatoraja-lua] require(${JSON.stringify(name)}) -> ${kind}`);
}
 
/** Logs a `dofile()` that loaded, behind {@link BEATORAJA_LUA_DIAGNOSTICS}. */
export function logLuaDofile(path: string, byteLength: number): void {
  Eif (!BEATORAJA_LUA_DIAGNOSTICS) return;
  // eslint-disable-next-line no-console
  console.log(`[beatoraja-lua] dofile(${JSON.stringify(path)}) -> ok (${byteLength}B)`);
}