Welcome!

Join our community of MMO enthusiasts and game developers! By registering, you'll gain access to discussions on the latest developments in MMO server files and collaborate with like-minded individuals. Join us today and unlock the potential of MMO server development!

Join Today!

Nashorn script engine Java 8

Skilled Illusionist
Joined
Apr 26, 2015
Messages
302
Reaction score
77



AbstractScriptManager:
Code:
f (engine == null) {                if(isDebugMode){
                    System.out.println("Loading file " + path);
                }
                
                engine = sem.getEngineByName("nashorn");
                if (c != null) {
                    c.setScriptEngine(path, engine);
                }
                StringBuilder builder = new StringBuilder();
                builder.append("load('nashorn:mozilla_compat.js');" + System.lineSeparator());
                builder.append(StringUtil.readFileAsString(path));


                engine.eval(builder.toString());


            }


ScringUtils:

Code:
public static String readFileAsString(String path){        StringBuilder builder = new StringBuilder();
        try {
            for(String str : Files.readAllLines(Paths.get(path))){
                builder.append(str + System.lineSeparator());
            }
            return builder.toString();
        } catch (IOException e) {
            System.out.println("Error while loading file " + path + " " + e.getMessage());
        }
        return "";
    }


PortalScriptManager:

Code:
public class PortalScriptManager {

	private static final org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(PortalScriptManager.class);
	private static PortalScriptManager instance = new PortalScriptManager();
	private Map<String, PortalScript> scripts = new HashMap<String, PortalScript>();
	private ScriptEngineFactory sef;
	private boolean isDebugMode = false;


	private PortalScriptManager() {
		isDebugMode = ServerEnvironment.isDebugMode();
		ScriptEngineManager sem = new ScriptEngineManager();
		sef = sem.getEngineByName("nashorn").getFactory();
	}
 
(O_o(o_O(O_O)o_O)O_o)
Loyal Member
Joined
Apr 9, 2009
Messages
1,088
Reaction score
322
Is this like what oxysoft released but less elegant? It looks like that. You should put some ducumentation on top of that stuff.
 
Skilled Illusionist
Joined
Apr 26, 2015
Messages
302
Reaction score
77
Is this like what oxysoft released but less elegant? It looks like that. You should put some ducumentation on top of that stuff.
I dont know if my code is less elegant performance wise.
However, as most of people dont understand this Java 8 streams, i think mine is more easy to understand.

The idea of the source is the same, just a different way of doing the same thing(check nashorn docs).



Is this like what oxysoft released but less elegant? It looks like that. You should put some ducumentation on top of that stuff.
The documentation is the code itself.
 
(O_o(o_O(O_O)o_O)O_o)
Loyal Member
Joined
Apr 9, 2009
Messages
1,088
Reaction score
322
I dont know if my code is less elegant performance wise.
However, as most of people dont understand this Java 8 streams, i think mine is more easy to understand.

The idea of the source is the same, just a different way of doing the same thing(check nashorn docs).




The documentation is the code itself.

The people who don't understand java 8 steams, are the people who are going to need more documentation as to what this release actually is.
 
Skilled Illusionist
Joined
Apr 26, 2015
Messages
302
Reaction score
77
The people who don't understand java 8 steams, are the people who are going to need more documentation as to what this release actually is.

Yea. I myself didnt tried many of Java 8 features yet, as i work mainly with JEE 7.

I think it will take one year or more to banks actualy use java 8 in future projects.
Believe me, some bank projects still use java 6 and new ones Java 7 :)
 
Elite Diviner
Joined
Mar 24, 2015
Messages
426
Reaction score
416
I don't think it's a good idea to integrate this algorithm to modify the scripts you parse into your actual main program. From a design standpoint this makes no sense and it makes your code harder to understand for someone who just wants to find out what AbstractScriptManager does.
Why not just write a small tool which goes through the files in your scripts folder and alters them permanently?
 
Skilled Illusionist
Joined
Apr 26, 2015
Messages
302
Reaction score
77
I don't think it's a good idea to integrate this algorithm to modify the scripts you parse into your actual main program. From a design standpoint this makes no sense and it makes your code harder to understand for someone who just wants to find out what AbstractScriptManager does.
Why not just write a small tool which goes through the files in your scripts folder and alters them permanently?
if you do that, you create a dependency between your scripts and java 8.
 
Elite Diviner
Joined
Mar 24, 2015
Messages
426
Reaction score
416
if you do that, you create a dependency between your scripts and java 8.

Scripts are meaningless without something that uses and interprets them, of course there will be a dependency. I assume what you mean is that the scripts will then only be usable with a java8 server. That's not really a bad thing imo, there is no reason to use java7 over java8.

Edit:
Anyway don't take this as a direct comment on your release here. It was more of a theoretical statement.
 
Skilled Illusionist
Joined
Apr 26, 2015
Messages
302
Reaction score
77
This implementation is not good as it should.

The correct implementation i would do today is have some interface "ScriptProvider" that could provide an execution environment to Java
7 and java 8 by using 2 different implementations Java8ScriptProvider, DefaultScriptProvider(Prior java 8) and choose the correct based on java version.
 
Back
Top