attempt to convert integer arguments

This commit is contained in:
jane 2021-06-04 22:02:13 -04:00
parent 3de793217b
commit 1e162cd7a5
2 changed files with 29 additions and 15 deletions

View file

@ -52,44 +52,51 @@ export const functions = {
(index, arg1, arg2) => { return Math.floor(Math.random() * 256) }, (index, arg1, arg2) => { return Math.floor(Math.random() * 256) },
{ {
requires_arg1: true, requires_arg1: true,
requires_arg2: false requires_arg2: false,
convert_args: false
} }
), ),
constant: new Function( constant: new Function(
(index, arg1, arg2) => { return args; }, (index, arg1, arg2) => { return arg2; },
{ {
requires_arg1: true, requires_arg1: true,
requires_arg2: true requires_arg2: true,
convert_args: false
}), }),
modulo: new Function( modulo: new Function(
(index, arg1, arg2) => { return arg1 % args; }, (index, arg1, arg2) => { return arg1 % arg2; },
{ {
requires_arg1: true, requires_arg1: true,
requires_arg2: true requires_arg2: true,
convert_args: true
}), }),
move: new Function( move: new Function(
(index, arg1, arg2) => { targets[args] = arg1; return arg1; }, (index, arg1, arg2) => { targets[arg1] = arg2; return arg2; },
{ {
requires_arg1: true, requires_arg1: true,
requires_arg2: true requires_arg2: true,
convert_args: false
}), }),
swap: new Function( swap: new Function(
(index, arg1, arg2) => { let temp = targets[args]; targets[args] = arg1; return temp; }, (index, arg1, arg2) => { let temp = targets[arg1]; targets[arg1] = arg2; return temp; },
{ {
requires_arg1: true, requires_arg1: true,
requires_arg2: true requires_arg2: true,
convert_args: false
}), }),
add: new Function( add: new Function(
(index, arg1, arg2) => { return arg1 + args; }, (index, arg1, arg2) => { return arg1 + arg2; },
{ {
requires_arg1: true, requires_arg1: true,
requires_arg2: true requires_arg2: true,
convert_args: true
}), }),
subtract: new Function( subtract: new Function(
(index, arg1, arg2) => { return arg1 - args; }, (index, arg1, arg2) => { return arg1 - arg2; },
{ {
requires_arg1: true, requires_arg1: true,
requires_arg2: true requires_arg2: true,
convert_args: true
}) })
} }
@ -102,7 +109,14 @@ function tick_pattern() {
for (let command of pattern) { for (let command of pattern) {
let name = command.command; let name = command.command;
if (functions[name]) { if (functions[name]) {
targets[command.arg1] = functions[name].func(i, targets[command.arg1], target.arg); if (functions[name].options.convert_args) {
let param_arg1 = parseInt(command.arg1) || targets[command.arg1];
let param_arg2 = parseInt(command.arg2) || targets[command.arg2];
targets[command.arg1] = functions[name].func(i, param_arg1, param_arg2);
}
else {
targets[command.arg1] = functions[name].func(i, command.arg1, command.arg2);
}
} }
} }
log.debug(`next: ${targets["r"]}, ${targets["g"]}, ${targets["b"]}`); log.debug(`next: ${targets["r"]}, ${targets["g"]}, ${targets["b"]}`);

View file

@ -29,7 +29,7 @@ export function recv(callback, errorCallback) {
con.on('data', (data) => { con.on('data', (data) => {
let parsed_data = parse(String(data)); let parsed_data = parse(String(data));
if (parsed_data.errors) { if (parsed_data.errors != undefined && parsed_data.errors.length > 0) {
con.write(JSON.stringify(parsed_data)); con.write(JSON.stringify(parsed_data));
errorCallback(parsed_data); errorCallback(parsed_data);
} }