Skip to content

Commit 83d73d7

Browse files
committed
Add install script.
1 parent 7e6f912 commit 83d73d7

File tree

4 files changed

+49
-8
lines changed

4 files changed

+49
-8
lines changed

scripts/install-byteskript.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/bin/bash
2+
3+
current_dir=$(pwd)
4+
script_dir=$(dirname "$0")
5+
6+
cd $script_dir
7+
if [[ ! -e bin ]]; then
8+
mkdir "bin"
9+
cd "bin"
10+
11+
echo $'#!/bin/bash\njava -jar '$script_dir'/ByteSkript.jar $@' > "bsk"
12+
fi
13+
14+
if [[ ! -e /usr/local/bin/bsk ]]; then
15+
rm /usr/local/bin/bsk
16+
fi
17+
18+
ln -s $script_dir"/bin/bsk" "/usr/local/bin/bsk"
19+
20+
chmod a+x $script_dir"/bin/bsk"
21+
chmod a+x /usr/local/bin/bsk

src/main/java/org/byteskript/skript/app/SkriptApp.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,15 @@ private static File getRoot() {
3838
}
3939
}
4040

41+
protected static File getJar() {
42+
try {
43+
return new File(SkriptApp.class.getProtectionDomain().getCodeSource().getLocation()
44+
.toURI());
45+
} catch (URISyntaxException e) {
46+
throw new IllegalStateException("Unable to find source file.", e);
47+
}
48+
}
49+
4150
protected static void registerLibraries(final Skript skript) {
4251
final List<File> files = getFiles(new ArrayList<>(), LIBRARIES.toPath());
4352
for (final File file : files) {

src/main/java/org/byteskript/skript/compiler/SimpleSkriptCompiler.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -109,14 +109,6 @@ public Library[] getLibraries() {
109109
return libraries.toArray(new Library[0]);
110110
}
111111

112-
@Override
113-
public SimpleSkriptCompiler clone() {
114-
final SimpleSkriptCompiler compiler = new SimpleSkriptCompiler();
115-
compiler.libraries.clear();
116-
compiler.libraries.addAll(this.libraries);
117-
return compiler;
118-
}
119-
120112
protected void compileLine(final String line, final FileContext context) {
121113
final ElementTree tree = parseLine(line, context);
122114
if (tree == null) return;
@@ -323,6 +315,14 @@ public PostCompileClass[] compile(String source, Type path) {
323315
return context.compile();
324316
}
325317

318+
@Override
319+
public SimpleSkriptCompiler clone() {
320+
final SimpleSkriptCompiler compiler = new SimpleSkriptCompiler();
321+
compiler.libraries.clear();
322+
compiler.libraries.addAll(this.libraries);
323+
return compiler;
324+
}
325+
326326
int trueIndent(final String line, final String unit) {
327327
if (unit == null) return 0;
328328
int indent = 0, offset = 0;

src/main/java/org/byteskript/skript/runtime/UnsafeAccessor.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@
77
package org.byteskript.skript.runtime;
88

99
import mx.kenzie.autodoc.api.note.Ignore;
10+
import org.byteskript.skript.error.ScriptRuntimeError;
1011
import sun.misc.Unsafe;
1112

13+
import java.lang.invoke.MethodHandles;
1214
import java.lang.reflect.Field;
1315
import java.security.PrivilegedActionException;
1416
import java.security.PrivilegedExceptionAction;
@@ -48,4 +50,13 @@ protected static void graveyard(final Object object) {
4850
}
4951
}
5052

53+
protected static Class<?> loadAnonymous(byte[] bytecode) {
54+
final MethodHandles.Lookup lookup = MethodHandles.lookup();
55+
try {
56+
return lookup.defineHiddenClass(bytecode, true, MethodHandles.Lookup.ClassOption.NESTMATE).lookupClass();
57+
} catch (IllegalAccessException ex) {
58+
throw new ScriptRuntimeError(ex);
59+
}
60+
}
61+
5162
}

0 commit comments

Comments
 (0)