[ Prev | Index | Next ]
Japanese English

Step 6 - How to Embed into Other Software

You can embed the scripting/calculation engine used in the RINPn, the "Vnano Engine", into your applications written in Java®. Let's try!

Example Code

In the package of the RINPn, an example code calculating a value of the expression "1.2 + 3.4" under almost the same engine-settings with the RINPn is attached as "EmbedUseExample.java":

import javax.script.ScriptEngine;
import javax.script.ScriptException;
import java.util.Map;
import java.util.HashMap;

public class EmbedUseExample {
    public static void main(String[] args) {

        ////////// Preparation of the Vnano Engine: Begin //////////

        // Get the script engine (Vnano Engine) used in the RINPn for calculations.
        ScriptEngine engine = new ScriptEngineManager.getEngineByName("vnano");
        if (engine == null) {
            System.err.println("Script engine loading error");
            return;
        }

        // Set ptions of the script engine (for details, see Settings.txt)
        Map optionMap = new HashMap();
        optionMap.put("EVAL_INT_LITERAL_AS_FLOAT", true);
        optionMap.put("EVAL_ONLY_FLOAT", true);
        optionMap.put("EVAL_ONLY_EXPRESSION", true);
        optionMap.put("UI_MODE", "CUI");      // For CUI applications
        // optionMap.put("UI_MODE", "GUI"); // For GUI applications
        optionMap.put("ACCELERATOR_ENABLED", true);
        optionMap.put("ACCELERATOR_OPTIMIZATION_LEVEL", 0);
        engine.put("___VNANO_OPTION_MAP", optionMap);

        // Set permissions referred from plug-ins supporting permission features.
        Map permissionMap = new HashMap();
        permissionMap.put("DEFAULT", "ASK");   // For asking to users by default
        // permissionMap.put("DEFAULT", "DENY"); // For denying by default
        // (Here add permission items you want to allow, as follows)
        // permissionMap.put("FILE_READ", "ALLOW");
        engine.put("___VNANO_PERMISSION_MAP", permissionMap);

        // Settings for loading libraries/plugins
        engine.put("___VNANO_LIBRARY_LIST_FILE", "lib/VnanoLibraryList.txt");
        engine.put("___VNANO_PLUGIN_LIST_FILE", "plugin/VnanoPluginList.txt");

        ////////// Preparation of the Vnano Engine: End //////////

        // Calculate the value of "1.2 + 3.4" by the script engine, and output
        try{
            String input = "1.2 + 3.4";
            double x = (double) engine.eval(input + ";");
            System.out.println("Output of the Vnano Engine: " + x);
        } catch (ScriptException e) {
            e.printStackTrace();
        }

        // Unload libraries/plugins
        engine.put("___VNANO_COMMAND", "REMOVE_LIBRARY");
        engine.put("___VNANO_COMMAND", "REMOVE_PLUGIN");
    }
}

How to Compile & Execute

How to compile:

javac -encoding UTF-8 EmbedUseExample.java

When the compilation is succeeded, a class file "EmbedUseExample.class" will be generated. Execute it with adding the Jar file of the Vnano Engine "Vnano.jar" (bundled in the package of the RINPn) to the class path:

java -cp ".;Vnano.jar" EmbedUseExample     (For Microsoft® Windows®)
java -cp ".:Vnano.jar" EmbedUseExample     (For Linux®, etc.)

(Result) Output of the Vnano Engine: 4.6

As the above, we get the correct value "4.6" of the expression "1.2 + 3.4". In the expression, you can use functions of libraries/plug-ins. In addition, to the eval(...) method of the script engine, you can pass the content(code) of a Vnano script instead of an expression.

License & More Detailed Information about the Vnano Engine

The Vnano Engine is an open source software released under the MIT License, so you can use it for free in both of commercial/non-commercial purposes, the same as the RINPn.

More detailed information (guide/specification documents and so on) are provided on the official website of the Vnano:

Vnano Official Website
https://www.vcssl.org/en-us/vnano/
- Trademarks/Credits -
  • Oracle and Java are registered trademarks of Oracle and/or its affiliates.
  • Microsoft Windows is either a registered trademarks or trademarks of Microsoft Corporation in the United States and/or other countries.
  • Linux is a trademark of linus torvalds in the United States and/or other countries.
  • Other names may be either a registered trademarks or trademarks of their respective owners.


Sponsored Link



Japanese English
Index of this category
News

RINEARN Graph 3D Updated and Next Version (Ver.6) Development Has Begun!
2023/09/04 - We have released RINEARN Graph 3D Ver.5.6.34. In addition, we have initiated the development of the next major version, Ver.6! Introducing the details.

Commitment to Significantly Expand English Documentation with AI Assistance - Presenting a Behind-the-Scenes Look at the Actual Workflow
2023/05/28 - We have decided to expand our English documentation by leveraging AI technologies such as ChatGPT. We will provide a detailed explanation of our initiative.

Update to RINEARN Graph 3D: Enhanced API-related Features and More
2023/05/18 - We recently released the latest version of RINEARN Graph 3D, Ver.5.6.32. Explains the details of this update.

Code Archive
Circular Wave Animation

Draws the circular wave as 3D animation, under the specified wave parameters.
2022/12/14
Sine Wave Animation

Draws the sine wave as animation, under the specified wave parameters.
2022/11/26
Tool For Converting Units of Angles: Degrees and Radians

A GUI tool for converting the angle in degrees into radians, or radians into degrees.
2022/11/22
Fizz Buzz Program

A program printing the correct result of Fizz Buzz game.
2022/05/12
Vnano | Solve The Lorenz Equations Numerically

Solve the Lorenz equations, and output data to plot the solution curve (well-known as the "Lorenz Attractor") on a 3D graph.
2021/02/18
» More