[Info-vax] Python for x86?

Arne Vajhøj arne at vajhoej.dk
Thu Apr 20 19:54:29 EDT 2023


On 4/20/2023 7:29 AM, Craig A. Berry wrote:
> 
> On 4/19/23 7:27 PM, Arne Vajhøj wrote:
>> On 4/14/2023 7:22 PM, Arne Vajhøj wrote:
>>> On 4/14/2023 8:19 AM, Simon Clubley wrote:
>>>> - Python is an excellent way to add automation/scripting 
>>>> capabilities to
>>>> a wide range of applications.
>>>>
>>>> Try doing the following with Perl: :-)
>>>>
>>>> https://docs.blender.org/api/current/info_overview.html
>>>
>>> It is possible to embed Perl as well.
>>>
>>> I would say Perl and Python is similar in that regard.
>>>
>>> https://docs.python.org/3/extending/embedding.html
>>>
>>> https://perldoc.perl.org/perlembed
>>
>> Of course JSR 223 is pretty cool in this regard.
>>
>> import javax.script.ScriptEngine;
>> import javax.script.ScriptEngineManager;
>> import javax.script.ScriptException;
>>
>> public class EmbeddedScript {
>>      public static void test(String language, String source) throws 
>> ScriptException {
>>          System.out.println(language + ":");
>>          System.out.print(source);
>>          ScriptEngineManager sem = new ScriptEngineManager();
>>          ScriptEngine se = sem.getEngineByName(language);
>>          se.eval(source);
>>      }
>>      public static void main(String[] args) throws ScriptException {
>>          test("javascript", "for(i = 0; i < 3; i++) {\r\n" +
>>                             "    print(\"Hi from JavaScript!\")\r\n" +
>>                             "}\r\n");
>>          test("python", "for i in range(3):\r\n" +
>>                         "    print(\"Hi from Python!\")\r\n");
>>          test("ruby", "for i in 1..3 do\r\n" +
>>                       "    puts 'Hi from Ruby!'\r\n" +
>>                       "end\r\n");
>>          test("php", "<?php\r\n" +
>>                      "for($i = 0; $i < 3; $i++) {\r\n" +
>>                      "    echo \"Hi from PHP!\\r\\n\";\r\n" +
>>                      "}\r\n" +
>>                      "?>\r\n");
>>          test("groovy", "for(i in 1..3) {\r\n" +
>>                         "    println \"Hi from Groovy!\"\r\n" +
>>                         "}\r\n");
>>          test("perl", "for(1..3) {\r\n" +
>>                       "    print(\"Hi from Perl!\\n\");\r\n" +
>>                       "}\r\n");
>>          test("lua", "for i = 1,3\r\n" +
>>                      "do\r\n" +
>>                      "    print(\"Hi from Lua!\")\r\n" +
>>                      "end\r\n");
>>          test("Lisp", "(dotimes (n 3)\r\n" +
>>                       "    (format t \"Hi from Lisp!~%\"))\r\n");
>>          test("tcl", "for {set i 0} {$i < 3} {incr i} {\r\n" +
>>                       "    puts \"Hi from Tcl!\"\r\n" +
>>                       "}\r\n");
>>      }
>> }
>>
>> outputs:
>>
>> javascript:
>> for(i = 0; i < 3; i++) {
>>      print("Hi from JavaScript!")
>> }
>> Hi from JavaScript!
>> Hi from JavaScript!
>> Hi from JavaScript!
>> python:
>> for i in range(3):
>>      print("Hi from Python!")
>> Hi from Python!
>> Hi from Python!
>> Hi from Python!
>> ruby:
>> for i in 1..3 do
>>      puts 'Hi from Ruby!'
>> end
>> Hi from Ruby!
>> Hi from Ruby!
>> Hi from Ruby!
>> php:
>> <?php
>> for($i = 0; $i < 3; $i++) {
>>      echo "Hi from PHP!\r\n";
>> }
>> ?>
>> Hi from PHP!
>> Hi from PHP!
>> Hi from PHP!
>> groovy:
>> for(i in 1..3) {
>>      println "Hi from Groovy!"
>> }
>> Hi from Groovy!
>> Hi from Groovy!
>> Hi from Groovy!
>> perl:
>> for(1..3) {
>>      print("Hi from Perl!\n");
>> }
>> Hi from Perl!
>> Hi from Perl!
>> Hi from Perl!
>> lua:
>> for i = 1,3
>> do
>>      print("Hi from Lua!")
>> end
>> Hi from Lua!
>> Hi from Lua!
>> Hi from Lua!
>> Lisp:
>> (dotimes (n 3)
>>      (format t "Hi from Lisp!~%"))
>> Hi from Lisp!
>> Hi from Lisp!
>> Hi from Lisp!
>> tcl:
>> for {set i 0} {$i < 3} {incr i} {
>>      puts "Hi from Tcl!"
>> }
>> Hi from Tcl!
>> Hi from Tcl!
>> Hi from Tcl!

> Seems odd to omit BeanShell from a list of embedded scripting
> capabilities based on Java:
> 
> <https://github.com/beanshell/beanshell>
> 
> I think Java people often prefer to do their scripting in a subset of
> Java rather than some other language.

BeanShell is probably the most common scripting language
in Java and it supposedly supports JSR 223.

But I could not get it working. Neither 2.0b4 or 2.0b5
worked with JSR 223 call.

And 2.0b6 docs said:

<quote>
BeanShell 2.0b6 is a security update that is functionally equivalent to 
the previous version 2.0b5.

No other functionality has changed since 2.0b5, but this is a 
recommended update for all BeanShell users, as it fixes a remote code 
execution vulnerability.
</quote>

But guess what - it works with 2.0b6!

So:

         test("beanshell", "for(int i = 0; i < 3; i++) {\r\n" +
                           "    System.out.println(\"Hi from 
BeanShell!\");\r\n"+
         		          "}\r\n");

beanshell:
for(int i = 0; i < 3; i++) {
     System.out.println("Hi from BeanShell!");
}
Hi from BeanShell!
Hi from BeanShell!
Hi from BeanShell!

Arne




More information about the Info-vax mailing list