Add documentation for ns.pid

This commit is contained in:
omuretsu 2022-12-13 09:08:23 -05:00
parent 52034ccedc
commit 75d2d8b7e8
6 changed files with 15 additions and 16 deletions

@ -1,4 +1,4 @@
import { NS } from "../ScriptEditor/NetscriptDefinitions"; import { NSFull } from "../NetscriptFunctions";
import { ExternalAPI } from "./APIWrapper"; import { ExternalAPI } from "./APIWrapper";
/** /**
@ -14,5 +14,5 @@ export class Environment {
runningFn = ""; runningFn = "";
/** Environment variables (currently only Netscript functions) */ /** Environment variables (currently only Netscript functions) */
vars: ExternalAPI<NS> | null = null; vars: ExternalAPI<NSFull> | null = null;
} }

@ -1,12 +1,12 @@
import { Player } from "@player"; import { Player } from "@player";
import { NSFull } from "../NetscriptFunctions"; import { NSFull } from "../NetscriptFunctions";
/** This type assumes any value that isn't an API layer or a function has been omitted (args and enum) */ /** This type assumes any value that isn't an API layer or a function has been omitted (enum) */
type RamCostTree<API> = Omit< type RamCostTree<API> = Omit<
{ {
[Property in keyof API]: API[Property] extends () => unknown ? number | (() => number) : RamCostTree<API[Property]>; [Property in keyof API]: API[Property] extends () => unknown ? number | (() => number) : RamCostTree<API[Property]>;
}, },
"enums" | "args" "enums"
>; >;
/** Constants for assigning costs to ns functions */ /** Constants for assigning costs to ns functions */

@ -13,10 +13,10 @@ import { RunningScript } from "../Script/RunningScript";
import { Script } from "../Script/Script"; import { Script } from "../Script/Script";
import { GetServer } from "../Server/AllServers"; import { GetServer } from "../Server/AllServers";
import { BaseServer } from "../Server/BaseServer"; import { BaseServer } from "../Server/BaseServer";
import { NS } from "../ScriptEditor/NetscriptDefinitions";
import { ScriptDeath } from "./ScriptDeath"; import { ScriptDeath } from "./ScriptDeath";
import { ScriptArg } from "./ScriptArg"; import { ScriptArg } from "./ScriptArg";
import { ExternalAPI } from "./APIWrapper"; import { ExternalAPI } from "./APIWrapper";
import { NSFull } from "../NetscriptFunctions";
export class WorkerScript { export class WorkerScript {
/** Script's arguments */ /** Script's arguments */
@ -83,7 +83,7 @@ export class WorkerScript {
/** Function called when the script ends. */ /** Function called when the script ends. */
atExit?: () => void; atExit?: () => void;
constructor(runningScriptObj: RunningScript, pid: number, nsFuncsGenerator?: (ws: WorkerScript) => ExternalAPI<NS>) { constructor(runningScriptObj: RunningScript, pid: number, nsFuncsGenerator?: (ws: WorkerScript) => ExternalAPI<NSFull>) {
this.name = runningScriptObj.filename; this.name = runningScriptObj.filename;
this.hostname = runningScriptObj.server; this.hostname = runningScriptObj.server;

@ -91,10 +91,9 @@ export const enums: NSEnums = {
LocationName, LocationName,
}; };
export type NSFull = Readonly<NS & INetscriptExtra>; export type NSFull = Readonly<Omit<NS & INetscriptExtra, "pid" | "args">>;
const base: InternalAPI<NS> = { export const ns: InternalAPI<NSFull> = {
args: [],
enums, enums,
singularity: NetscriptSingularity(), singularity: NetscriptSingularity(),
gang: NetscriptGang(), gang: NetscriptGang(),
@ -1898,14 +1897,10 @@ const base: InternalAPI<NS> = {
} }
}, },
flags: Flags, flags: Flags,
};
// add undocumented functions
export const ns = {
...base,
...NetscriptExtra(), ...NetscriptExtra(),
}; };
// add undocumented functions
export const wrappedNS = wrapAPILayer({} as ExternalAPI<NSFull>, ns, []); export const wrappedNS = wrapAPILayer({} as ExternalAPI<NSFull>, ns, []);
// Figure out once which layers of ns have functions on them and will need to be stamped with a private workerscript field for API access // Figure out once which layers of ns have functions on them and will need to be stamped with a private workerscript field for API access

@ -1,7 +1,8 @@
import { NSFull } from "../NetscriptFunctions";
import { ExternalAPI } from "../Netscript/APIWrapper"; import { ExternalAPI } from "../Netscript/APIWrapper";
import { AutocompleteData, NS } from "../ScriptEditor/NetscriptDefinitions"; import { AutocompleteData } from "../ScriptEditor/NetscriptDefinitions";
export interface ScriptModule { export interface ScriptModule {
main?: (ns: ExternalAPI<NS>) => unknown; main?: (ns: ExternalAPI<NSFull>) => unknown;
autocomplete?: (data: AutocompleteData, flags: string[]) => unknown; autocomplete?: (data: AutocompleteData, flags: string[]) => unknown;
} }

@ -4611,6 +4611,9 @@ export interface NS {
*/ */
readonly args: (string | number | boolean)[]; readonly args: (string | number | boolean)[];
/** The current script's PID */
readonly pid: number;
/** /**
* Steal a server's money. * Steal a server's money.
* @remarks * @remarks