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 5757import org .byteskript .skript .lang .syntax .map .MapCreator ;
5858import org .byteskript .skript .lang .syntax .maths .*;
5959import org .byteskript .skript .lang .syntax .timing .*;
60+ import org .byteskript .skript .lang .syntax .type .ThisThingExpression ;
6061import org .byteskript .skript .lang .syntax .type .TypeCreator ;
6162import org .byteskript .skript .lang .syntax .type .TypeMember ;
6263import org .byteskript .skript .lang .syntax .variable .AtomicVariableExpression ;
@@ -166,6 +167,7 @@ private SkriptLangSpec() {
166167 new ImplicitArrayCreator (),
167168 new BracketExpression (),
168169 new BooleanLiteral (),
170+ new ThisThingExpression (),
169171 new ThreadVariableExpression (),
170172 new AtomicVariableExpression (),
171173 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)
3434 if (object == null ) return null ;
3535 if (!(object instanceof Class <?> type ))
3636 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+ }
3844 }
3945
4046}
Original file line number Diff line number Diff line change 44// function another_func
55
66type 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
713 function my_func:
814 return: String
915 trigger:
@@ -27,3 +33,5 @@ function basic_use:
2733 assert {word} is "hello": "Member function call failed."
2834 set {number} to func_with_args(3) from {thing}
2935 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