[ Prev | Index | Next ]
Japanese English

Step 6 - How to Embed into Other Software

In this page, as an advanced extra step, Let's embed the processing engine of RINPn into your original app!

Sponsored Link

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");

        // 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
            String input = "1.2 + 3.4";
            double x = (double) engine.eval(input + ";");
            System.out.println("Output of the Vnano Engine: " + x);
        } catch (ScriptException e) {

        // 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
- 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

Software Updates: Command Expansion in RINEARN Graph, and English Support in VCSSL
2024/02/05 - We updated our apps. This updates include "Enhancing the Command-Line Features of RINEARN Graph" and "Adding English Support to VCSSL." Delves into each of them!

Inside the Repetitive Execution Speedup Impremented in Vnano Ver.1.1
2024/01/17 - Delves into the update in Vnano 1.1 from a developer's viewpoint, providing detailed insights into the specific improvements made to the internal structure of the script engine.

Scripting Engine Vnano Ver.1.1 Released: Dramatic Speed Improvement for Repetitive Executions of the Same Content
2023/12/22 - Released the Vnano script engine Ver.1.1. In this version, we've made significant enhancements in processing speed by reducing the overhead of handling requests. Explains the details.

Code Archive
Circular Wave Animation

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

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

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

A program printing the correct result of Fizz Buzz game.
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.
» More