File tree Expand file tree Collapse file tree 4 files changed +58
-1
lines changed
main/java/org/byteskript/skript Expand file tree Collapse file tree 4 files changed +58
-1
lines changed Original file line number Diff line number Diff line change 57
57
import org .byteskript .skript .lang .syntax .map .MapCreator ;
58
58
import org .byteskript .skript .lang .syntax .maths .*;
59
59
import org .byteskript .skript .lang .syntax .timing .*;
60
+ import org .byteskript .skript .lang .syntax .type .ThisThingExpression ;
60
61
import org .byteskript .skript .lang .syntax .type .TypeCreator ;
61
62
import org .byteskript .skript .lang .syntax .type .TypeMember ;
62
63
import org .byteskript .skript .lang .syntax .variable .AtomicVariableExpression ;
@@ -166,6 +167,7 @@ private SkriptLangSpec() {
166
167
new ImplicitArrayCreator (),
167
168
new BracketExpression (),
168
169
new BooleanLiteral (),
170
+ new ThisThingExpression (),
169
171
new ThreadVariableExpression (),
170
172
new AtomicVariableExpression (),
171
173
new GlobalVariableExpression (),
Original file line number Diff line number Diff line change
1
+ /*
2
+ * Copyright (c) 2021 ByteSkript org (Moderocky)
3
+ * View the full licence information and permissions:
4
+ * https://github.com/Moderocky/ByteSkript/blob/master/LICENSE
5
+ */
6
+
7
+ package org .byteskript .skript .lang .syntax .type ;
8
+
9
+ import mx .kenzie .foundation .MethodBuilder ;
10
+ import mx .kenzie .foundation .Type ;
11
+ import mx .kenzie .foundation .WriteInstruction ;
12
+ import org .byteskript .skript .api .syntax .SimpleExpression ;
13
+ import org .byteskript .skript .compiler .*;
14
+ import org .byteskript .skript .lang .element .StandardElements ;
15
+
16
+ public class ThisThingExpression extends SimpleExpression {
17
+
18
+ public ThisThingExpression () { // todo test this
19
+ super (SkriptLangSpec .LIBRARY , StandardElements .EXPRESSION , "this (thing|object)" );
20
+ }
21
+
22
+ @ Override
23
+ public Type getReturnType () {
24
+ return CommonTypes .STRING ;
25
+ }
26
+
27
+ @ Override
28
+ public Pattern .Match match (String thing , Context context ) {
29
+ if (!thing .startsWith ("this " )) return null ;
30
+ if (!context .hasFlag (AreaFlag .IN_TYPE )) return null ;
31
+ return super .match (thing , context );
32
+ }
33
+
34
+ @ Override
35
+ public void compile (Context context , Pattern .Match match ) throws Throwable {
36
+ final MethodBuilder method = context .getMethod ();
37
+ assert method != null ;
38
+ method .writeCode (WriteInstruction .loadThis ());
39
+ }
40
+
41
+ }
Original file line number Diff line number Diff line change @@ -34,7 +34,13 @@ public static Object create(Object object)
34
34
if (object == null ) return null ;
35
35
if (!(object instanceof Class <?> type ))
36
36
throw new ScriptRuntimeError ("Tried to create a new non-type thing: " + object );
37
- return type .newInstance ();
37
+ try {
38
+ return type .newInstance ();
39
+ } catch (InstantiationException ex ) {
40
+ throw new ScriptRuntimeError ("The type '" + ((Class <?>) object ).getSimpleName () + "' cannot be created like this." );
41
+ } catch (IllegalAccessException ex ) {
42
+ throw new ScriptRuntimeError ("The type '" + ((Class <?>) object ).getSimpleName () + "' does not permit creation." );
43
+ }
38
44
}
39
45
40
46
}
Original file line number Diff line number Diff line change 4
4
// function another_func
5
5
6
6
type Box:
7
+ function bonk:
8
+ return: Boolean
9
+ trigger:
10
+ set {var} to my_func() from this object
11
+ assert {var} is "hello": "Member-local function didn't return properly."
12
+ return true
7
13
function my_func:
8
14
return: String
9
15
trigger:
@@ -27,3 +33,5 @@ function basic_use:
27
33
assert {word} is "hello": "Member function call failed."
28
34
set {number} to func_with_args(3) from {thing}
29
35
assert {number} is 211: "Member function call with args failed."
36
+ set {boolean} to bonk() from {thing}
37
+ assert {boolean} is true: "Member function didn't return correctly."
You can’t perform that action at this time.
0 commit comments