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

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

Released Ver.1.0 of the Scientific Calculator App "RINPn"
2022/12/31 - We have released the first general release version (Ver.1.0) of the programmable scientific calculato app "RINPn". Explains the details.

Released Ver.1.0 of Vnano Scripting Engine/Language
2022/12/12 - Vnano Scripting Engine has transited from the beta stage to the general release stage, and we have released the first general release version: 1.0. Explains the details.

Updated the Scientific Calculator "RINPn": Added a Retractable Key-Panel, etc.
2022/11/11 - We have updated the scientific calculator app &quto;RINPn" to Ver.0.9.4. Explains the details of the changes by this update.

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
Announcementi Twitter j