mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-11-13 11:13:50 +01:00
added check for NS interface with user defined guard
This commit is contained in:
parent
9ddb1c4379
commit
6ed5a445a8
@ -98,6 +98,11 @@ interface NS extends INS {
|
|||||||
stanek: IStanek;
|
stanek: IStanek;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//interface guard
|
||||||
|
function isNS(object: any): boolean {
|
||||||
|
return (object as NS).gang !== undefined;
|
||||||
|
}
|
||||||
|
|
||||||
export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
||||||
const updateDynamicRam = function (fnName: string, ramCost: number): void {
|
const updateDynamicRam = function (fnName: string, ramCost: number): void {
|
||||||
if (workerScript.dynamicLoadedFns[fnName]) {
|
if (workerScript.dynamicLoadedFns[fnName]) {
|
||||||
@ -1772,7 +1777,7 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
|||||||
return res;
|
return res;
|
||||||
},
|
},
|
||||||
writePort: function (port: any, data: any = ""): any {
|
writePort: function (port: any, data: any = ""): any {
|
||||||
if (typeof data !== "string" && typeof data !== "number") {
|
if ((typeof data !== "string" && typeof data !== "number") || isNS(data)) {
|
||||||
throw makeRuntimeErrorMsg(
|
throw makeRuntimeErrorMsg(
|
||||||
"writePort",
|
"writePort",
|
||||||
`Trying to write invalid data to a port: only strings and numbers are valid.`,
|
`Trying to write invalid data to a port: only strings and numbers are valid.`,
|
||||||
|
Loading…
Reference in New Issue
Block a user