BadScript 2
Loading...
Searching...
No Matches
BadExpressionFunction.cs
Go to the documentation of this file.
6
11
16{
20 private readonly List<BadExpression> m_Body;
21
25 private readonly string m_FuncString;
26
30 public readonly BadScope ParentScope;
31
35 public readonly BadSourcePosition Position;
36
51 BadScope parentScope,
52 BadWordToken? name,
53 List<BadExpression> expressions,
54 BadFunctionParameter[] parameters,
55 BadSourcePosition position,
56 bool isConstant,
57 bool isStatic,
58 BadMetaData? metaData,
59 BadClassPrototype returnType,
60 bool isSingleLine) : base(name, isConstant, isStatic, returnType, isSingleLine, parameters)
61 {
62 m_Body = expressions;
63 Position = position;
64 ParentScope = parentScope;
65 MetaData = metaData ?? BadMetaData.Empty;
66 m_FuncString = base.ToString() + " at " + Position.GetPositionInfo();
67 }
68
72 public IEnumerable<BadExpression> Body => m_Body;
73
74
76 public override BadMetaData MetaData { get; }
77
79 public override BadFunction BindParentScope(BadScope scope)
80 {
81 return new BadExpressionFunction(
82 scope,
83 Name,
84 m_Body,
92 );
93 }
94
96 protected override IEnumerable<BadObject> InvokeBlock(BadObject[] args, BadExecutionContext caller)
97 {
100 ToString(),
101 caller.Scope,
102 null,
103 BadScopeFlags.Returnable | BadScopeFlags.AllowThrow | BadScopeFlags.CaptureThrow
104 )
105 );
106
107 ctx.Scope.FunctionObject = this;
108
109 ApplyParameters(ctx, args, Position);
110
111 if (m_Body.Count == 0)
112 {
113 yield return Null;
114
115 yield break;
116 }
117
118 foreach (BadObject o in ctx.Execute(Body))
119 {
120 yield return o;
121 }
122
123 if (ctx.Scope.ReturnValue != null)
124 {
125 yield return ctx.Scope.ReturnValue;
126 }
127 else
128 {
129 yield return Null;
130 }
131
132 }
133
135 public override string ToString()
136 {
137 return m_FuncString;
138 }
139}
Describes a specific position inside a source file.
string GetPositionInfo()
Returns position info. Format: file://[FileName] : Line [Line].
Implements a Meta Data container for an expression.
static readonly BadMetaData Empty
An empty Meta Data object.
The Execution Context. Every execution of a script needs a context the script is running in....
BadScope Scope
The Root Scope of the Context.
Implements the Scope for the Script Engine.
Definition BadScope.cs:238
BadScope CreateChild(string name, BadScope? caller, bool? useVisibility, BadScopeFlags flags=BadScopeFlags.RootScope)
Creates a subscope of the current scope.
Definition BadScope.cs:792
The Base Class for all BadScript Objects.
Definition BadObject.cs:14
override string ToString()
Returns a String Representation of this Object.
Definition BadObject.cs:210
static readonly BadObject Null
The Null Value for the BadScript Language.
Definition BadObject.cs:28
The Expression Function Implementation used if a function gets defined in the Source Code.
readonly BadSourcePosition Position
The Source Position of the Function.
BadExpressionFunction(BadScope parentScope, BadWordToken? name, List< BadExpression > expressions, BadFunctionParameter[] parameters, BadSourcePosition position, bool isConstant, bool isStatic, BadMetaData? metaData, BadClassPrototype returnType, bool isSingleLine)
Creates a new Expression Function.
readonly List< BadExpression > m_Body
The Function Body.
override BadFunction BindParentScope(BadScope scope)
Returns an instance that is bound to the given scope.Function Instance
readonly BadScope ParentScope
The Scope the function is defined in.
override IEnumerable< BadObject > InvokeBlock(BadObject[] args, BadExecutionContext caller)
IEnumerable< BadExpression > Body
Enumeration of all expressions in the function body.
Implements a function that can be called from the script.
BadFunctionParameter[] Parameters
The Function Parameters.
bool IsSingleLine
Indicates if the function is a single line function(without block) Is used to determine the behaviour...
BadWordToken? Name
(optional) Name of the Function
static void ApplyParameters(string funcStr, BadFunctionParameter[] parameters, BadExecutionContext context, BadObject[] args, BadSourcePosition? position=null)
Applies the function arguments to the context of the function.
bool IsConstant
Indicates if the function has no side effects and the result can be cached.
bool IsStatic
Indicates if the Function is static.
BadClassPrototype ReturnType
The Return Type of the Function.
Implements a Class Prototype for the BadScript Language.
Contains Shared Data Structures and Functionality.
Contains the Expressions for the BadScript2 Language.
Contains the Parser for the BadScript2 Language.
Contains the Reader Tokens for the BadScript2 Language.
Contains Runtime Function Objects.
BadScopeFlags
Defines Different Behaviours for the Current Scope.