BadScript 2
Loading...
Searching...
No Matches
BadFunctionExtension.cs
Go to the documentation of this file.
7
9
14{
16 protected override void AddExtensions(BadInteropExtensionProvider provider)
17 {
18 provider.RegisterObject<BadFunction>("Name", f => f.Name?.Text ?? "<anonymous>");
19 provider.RegisterObject<BadFunction>("ReturnType", f => f.ReturnType);
21 "Parameters",
22 f => new BadArray(f.Parameters.Select(x => BadObject.Wrap(x)).ToList())
23 );
25 "Invoke",
27 "Invoke",
28 (ctx, a) =>
29 {
31
32 BadObject[] args;
33 if (a is BadArray arr)
34 {
35 args = arr.InnerArray.ToArray();
36 }
37 else if (BadNativeClassBuilder.Enumerable.IsSuperClassOf(a.GetPrototype()))
38 {
39 args = BadNativeClassHelper.ExecuteEnumerate(ctx, a).ToArray();
40 }
41 else
42 {
43 throw new BadRuntimeException("Invalid Argument Type");
44 }
45
46 foreach (BadObject o in f.Invoke(args, ctx))
47 {
48 r = o;
49 }
50
51 return r;
52 },
53 f.ReturnType,
54 new BadFunctionParameter("args", false, false, false, null, BadNativeClassBuilder.Enumerable)
55 )
56 );
57
58 provider.RegisterObject<BadFunction>("Meta", f => f.MetaData);
59
60 provider.RegisterObject<BadFunctionParameter>("Name", p => p.Name);
61 provider.RegisterObject<BadFunctionParameter>("IsNullChecked", p => p.IsNullChecked);
62 provider.RegisterObject<BadFunctionParameter>("IsOptional", p => p.IsOptional);
63 provider.RegisterObject<BadFunctionParameter>("IsRestArgs", p => p.IsRestArgs);
64 provider.RegisterObject<BadFunctionParameter>("Type", p => p.Type ?? BadObject.Null);
65 }
66}
override void AddExtensions(BadInteropExtensionProvider provider)
Public Extension API for the BS2 Runtime.
void RegisterObject(Type t, string propName, BadObject obj)
Registers the specified extension for the specified type.
Implements a Dynamic List/Array for the BadScript Language.
Definition BadArray.cs:17
The Base Class for all BadScript Objects.
Definition BadObject.cs:14
static readonly BadObject Null
The Null Value for the BadScript Language.
Definition BadObject.cs:28
Implements a function that can be called from the script.
BadFunctionParameter[] Parameters
The Function Parameters.
BadWordToken? Name
(optional) Name of the Function
IEnumerable< BadObject > Invoke(BadObject[] args, BadExecutionContext caller)
Invokes the function with the specified arguments.
virtual BadMetaData MetaData
The Metadata of the Function.
BadClassPrototype ReturnType
The Return Type of the Function.
bool IsOptional
Indicates if this parameter is optional.
bool IsRestArgs
Indicates if this parameter is the rest parameter of the function.
bool IsNullChecked
Indicates if this parameter is null checked by the runtime.
Helper Class that Builds a Native Class from a Prototype.
static readonly BadInterfacePrototype Enumerable
The IEnumerable Interface Prototype.
Contains Common Interop Extensions for the BadScript2 Runtime.
Contains the Error Objects for the BadScript2 Language.
Contains the Interop Function Classes for the BadScript2 Language.
Contains the Interop Abstractions and Implementations for the BadScript2 Language.
Contains Runtime Function Objects.
Contains the Runtime Objects.
Definition BadArray.cs:10