Skip to content

Commit

Permalink
Broke out standard cali includes into their respective .ca files and …
Browse files Browse the repository at this point in the history
…added a loader to load text resources. Incremented the version number.
  • Loading branch information
rsv-code committed Sep 2, 2017
1 parent e6dd4cc commit 8490ab3
Show file tree
Hide file tree
Showing 10 changed files with 657 additions and 617 deletions.
2 changes: 1 addition & 1 deletion cali.lang.base/pom.xml
Expand Up @@ -3,7 +3,7 @@

<groupId>com.cali-lang</groupId>
<artifactId>cali.lang.base</artifactId>
<version>1.0.0</version>
<version>1.0.1-SNAPSHOT</version>
<packaging>jar</packaging>

<name>cali.lang.base</name>
Expand Down
2 changes: 1 addition & 1 deletion cali.lang.base/src/com/cali/Main.java
Expand Up @@ -54,7 +54,7 @@ public static void main(String[] args) throws Exception {
*/
public static void printUsage() {
String rstr = "";
rstr += "Cali-Lang Version 1.0\n";
rstr += "Cali-Lang Version " + Universe.getCaliVersion() + "\n";
rstr += "Copyright 2017 Austin Lehman\n";
rstr += "Apache License Version 2\n";
System.out.println(rstr);
Expand Down
4 changes: 2 additions & 2 deletions cali.lang.base/src/com/cali/Universe.java
Expand Up @@ -42,7 +42,7 @@ public class Universe {
/**
* Defines the Cali version.
*/
private static final String version = "1.0";
private static final String version = "1.0.1";

/**
* Map of class definitions. This is used to hold the base lang clases. It allows
Expand All @@ -65,7 +65,7 @@ private Universe() { }
public void init(Engine eng) throws Exception {
if (!this.initialized) {
// Load native class definitions here!
eng.parseString("lang.ca", Lang.langSrc);
eng.parseString("lang.ca", Lang.get().langIncludes.get("lang.ca"));
this.classes = eng.getClasses();
this.initialized = true;
}
Expand Down
32 changes: 32 additions & 0 deletions cali.lang.base/src/com/cali/Util.java
Expand Up @@ -20,6 +20,8 @@
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;

/**
Expand Down Expand Up @@ -95,4 +97,34 @@ public static String join(ArrayList<String> parts, String Glue) {
}
return sb.toString();
}

/**
* Loads a file resource with the provided path
* within the project/jar and returns it as a String.
* @param ResourceName is a String with the resource to get.
* @return A String with the contents of the resource.
*/
public static String loadResource(String ResourceName) {
String ret = "";

InputStream in = Util.class.getResourceAsStream(ResourceName);
InputStreamReader rdr = new InputStreamReader(in);
try {
int len = -1;
char[] buff = new char[4096];
final StringBuffer buffer = new StringBuffer();
while ((len = rdr.read(buff)) > 0) { buffer.append(buff, 0, len); }

ret = buffer.toString();
} catch (IOException e) {
System.err.println("Lang.loadResource(): Failed to load resource '" + ResourceName + "'.");
} finally {
if(rdr != null) {
try { rdr.close(); }
catch (IOException e) { }
}
}

return ret;
}
}

0 comments on commit 8490ab3

Please sign in to comment.