Threads are a positive integer (#366)

* Added new positive integer ns validation helper
* `run`, `exec`, and `spawn` verify threads as a positive integer.
* `run` terminal command also fails if the provided threadcount is not a positive integer.
* Removed some references to .script files in various documentation, and removed some of the NS1 example blocks
This commit is contained in:
Snarling
2023-02-14 01:32:01 -05:00
committed by GitHub
parent b0bdf0c7ad
commit 08e71c732b
20 changed files with 165 additions and 474 deletions
+10
View File
@@ -38,6 +38,7 @@ import { RamCostConstants } from "./RamCostGenerator";
export const helpers = {
string,
number,
positiveInteger,
scriptArgs,
argsToString,
makeBasicErrorMsg,
@@ -157,6 +158,15 @@ function number(ctx: NetscriptContext, argName: string, v: unknown): number {
throw makeRuntimeErrorMsg(ctx, `'${argName}' should be a number. ${debugType(v)}`, "TYPE");
}
/** Convert provided value v for argument argName to a positive integer, throwing if it looks like something else. */
function positiveInteger(ctx: NetscriptContext, argName: string, v: unknown): number {
const n = number(ctx, argName, v);
if (n < 1 || !Number.isInteger(n)) {
throw makeRuntimeErrorMsg(ctx, `${argName} should be a positive integer, was ${n}`, "TYPE");
}
return n;
}
/** Returns args back if it is a ScriptArg[]. Throws an error if it is not. */
function scriptArgs(ctx: NetscriptContext, args: unknown) {
if (!isScriptArgs(args)) throw makeRuntimeErrorMsg(ctx, "'args' is not an array of script args", "TYPE");