diff options
Diffstat (limited to 'src/client/util/Scripting.ts')
-rw-r--r-- | src/client/util/Scripting.ts | 50 |
1 files changed, 42 insertions, 8 deletions
diff --git a/src/client/util/Scripting.ts b/src/client/util/Scripting.ts index ab577315c..237027c03 100644 --- a/src/client/util/Scripting.ts +++ b/src/client/util/Scripting.ts @@ -49,15 +49,37 @@ export function isCompileError(toBeDetermined: CompileResult): toBeDetermined is export namespace Scripting { export function addGlobal(global: { name: string }): void; export function addGlobal(name: string, global: any): void; - export function addGlobal(nameOrGlobal: any, global?: any) { - let n: string; + + export function addGlobal(global: { name: string }, decription?: string, params?: string): void; + export function addGlobal(global: { name: string }, decription?: string, params?: string, name?: string): void; + + export function addGlobal(first: any, second?: any, third?: string, fourth?: string) { + let n: any; let obj: any; - if (global !== undefined && typeof nameOrGlobal === "string") { - n = nameOrGlobal; - obj = global; - } else if (nameOrGlobal && typeof nameOrGlobal.name === "string") { - n = nameOrGlobal.name; - obj = nameOrGlobal; + + if (second !== undefined) { + if (typeof first === "string") { + n = first; + obj = second; + } else { + obj = [first]; + obj.push(second); + if (third) { + //if (third.indexOf("(") > 0) { + obj.push(third); + //} else { + //n = third; + //} + } + if (fourth) { + n = fourth; + } else { + n = first.name; + } + } + } else if (first && typeof first.name === "string") { + n = first.name; + obj = first; } else { throw new Error("Must either register an object with a name, or give a name and an object"); } @@ -75,6 +97,14 @@ export namespace Scripting { scriptingGlobals = globals; } + export function removeGlobal(name: string) { + if (_scriptingGlobals.hasKey(name)) { + delete _scriptingGlobals.container[name]; + return true; + } + return false; + } + export function resetScriptingGlobals() { scriptingGlobals = _scriptingGlobals; } @@ -87,6 +117,10 @@ export namespace Scripting { export function getGlobals() { return Object.keys(scriptingGlobals); } + + export function getGlobalObj() { + return _scriptingGlobals; + } } export function scriptingGlobal(constructor: { new(...args: any[]): any }) { |