Skip to content

Latest commit

 

History

History
106 lines (79 loc) · 2.84 KB

README.adoc

File metadata and controls

106 lines (79 loc) · 2.84 KB

Jamal ScriptBasic integration module

Using this integration module you can mix Jamal macro text with ScriptBasic code snippets. To use this module you have to add the dependency to your Maven project, as:

<dependency>
    <groupId>com.javax0.jamal</groupId>
    <artifactId>jamal-scriptbasic</artifactId>
    <version>2.8.1</version>
</dependency>

This library has one single built-in macro, basic. Using this macro you can embed BASIC programs into your Jamal file. Usually you will not use the macro directly. Instead, you can invoke the user-defined macros from the resource file scriptbasic.jim as demonstrated in the following example:

{@import res:scriptbasic.jim}
{expr 13+1}{@define start=1}{@define end=13}
{#basic for i={start} to {end}
if i%2 = 1 then
  oddity = "odd"
else
  oddity = "even"
endif
print i,". is an ",oddity," number\n"
next
}

resulting

14
1. is an odd number
2. is an even number
3. is an odd number
4. is an even number
5. is an odd number
6. is an even number
7. is an odd number
8. is an even number
9. is an odd number
10. is an even number
11. is an odd number
12. is an even number
13. is an odd number

There is also an include file defining a few user defined macros. You can refer to this include file, as

{@import res:scriptbasic.jim}

in your Jamal file. It will let you write things, like

{expr 13+14*55}

This will evaluate the expression and result the value of the expression. For more complex code you can use the macro basic, to execute a whole BASIC program and get the output into the Jamal output.

Note that you can also mix Jamal into the BASIC. It was demonstrated in the example above. The macro invocation {#basic …​} was using the # character, therefore the content is evaluated before it is passed to the built-in macro basic. That way the macros {start} and {end} are evaluated first. The BASIC interpreter already gets for i=1 to 13.

Starting with the version 2.0.0 the library is not configured to be on the class path of the command line version or the Asciidoctor preprocessor. The reason is security. The interpreter, just as well as the Groovy and Ruby interpreters, can execute arbitrary code. If you want to use the ScriptBasic interpreter you have to

  • modify the property maven.load.include and maven.load.exclude in the file ~/.jamal/settings.properties to include the scriptbasic module. For example:

    maven.load.include=com.javax0.jamal:jamal-scriptbasic:2.8.1
  • add the line

    {@maven:load com.javax0.jamal:jamal-scriptbasic:2.8.1}

    to the Jamal file where you want to use the ScriptBasic interpreter.

  • To include the resource file scriptbasic.jim you have to add the line

    {@import maven:com.javax0.jamal:jamal-scriptbasic:2.8.1::scriptbasic.jim}

    instead importing it as a resource.