mirror of
https://github.com/captbaritone/webamp.git
synced 2026-07-22 09:37:17 +00:00
Inject logger
This commit is contained in:
parent
6ce7193bc0
commit
c02b59219c
2 changed files with 6 additions and 7 deletions
|
|
@ -3,7 +3,7 @@ const { getClass, getFormattedId } = require("./objects");
|
|||
const interpret = require("./virtualMachine");
|
||||
const { printCommand } = require("./prettyPrinter");
|
||||
|
||||
function main({ runtime, data, system, log }) {
|
||||
function main({ runtime, data, system, log, logger }) {
|
||||
const program = parse(data);
|
||||
|
||||
// Replace class hashes with actual JavaScript classes from the runtime
|
||||
|
|
@ -26,10 +26,11 @@ function main({ runtime, data, system, log }) {
|
|||
const { commandOffset, variableOffset, methodOffset } = binding;
|
||||
const variable = program.variables[variableOffset];
|
||||
const method = program.methods[methodOffset];
|
||||
const logger = log ? printCommand : null;
|
||||
// TODO: Handle disposing of this.
|
||||
// TODO: Handle passing in variables.
|
||||
variable.hook(method.name, () => {
|
||||
interpret(commandOffset, program, { log });
|
||||
interpret(commandOffset, program, { logger });
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,4 @@
|
|||
const { printCommand } = require("./prettyPrinter");
|
||||
|
||||
function interpret(start, program, { log = false }) {
|
||||
function interpret(start, program, { logger = null }) {
|
||||
const { commands, methods, variables, classes, offsetToCommand } = program;
|
||||
|
||||
// Run all the commands that are safe to run. Increment this number to find
|
||||
|
|
@ -102,8 +100,8 @@ function interpret(start, program, { log = false }) {
|
|||
}
|
||||
|
||||
// Print some debug info
|
||||
if (log) {
|
||||
printCommand({ i, command, stack, variables });
|
||||
if (logger) {
|
||||
logger({ i, command, stack, variables });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue