hi,
recently and by surprise a remarkable new version of HyperTalk calles
OpenXION, implemented as Java compiler, appeared online. As the source
code is also available it was simply to tempting to embed this next
generation HyperTalk inside of Field. ... and it's amazing, cause it
opens up the possibility to combine a very user centric and easy to
learn scripting language with flow/node based, graphical programming
languages like Field and Max/MSP and with finita state automate driven
graphic environments like Processing and Nodebox2.
To embed OpenXION into Field is straight forward. I simply loaded the
necessary Lexer and Parser classes from the openxion.jar (already
placed inside the Field package ) and then handed over a HyperTalk
structure for execution. To hand over the results of the HyperTalk
processes i simply used to write to and read from the file system
following a predefined naming scheme. Everything works as expected and
it's a joy to use HyperTalk this way.
########## example code start ######################
import os
from
java.io import FileWriter
from
java.io import FileReader
from
java.io import BufferedWriter
from
java.io import BufferedReader
from
java.io import StringReader
from com.kreative.openxion import *
hyptlkCmd ="""
global Fabuloes
on field var, varName
put "/tmp/f" & varName into varPath
open file varPath
write var to file varPath
close file varPath
end field
put 3 + 4
put "hello world from hypertalk" & return & "und so weiter" into world
put world
repeat 10
put world
end repeat
put "a" into z
field world, "world"
"""
ui = XNNullUI( )
context = XNContext( ui)
context.setSecurityProfile(XNSecurityProfile(XNSecurityValue.ALLOW))
print " XNMain.readEnviron( contxt): "
print XNMain.readEnviron( context)
context.loadModule( XNStandardModule.instance())
context.loadModule( XNExtendedModule.instance())
interp = XNInterpreter( context)
print "XNInterpreter( context)"
print interp
lexer = XNLexer( hyptlkCmd, StringReader(hyptlkCmd))
print "XNLexer( hyptlkCmd, StringReader(hyptlkCmd))"
print lexer
parser = XNParser( context, lexer)
print "XNParser( context, lexer)"
print parser
program = parser.parse()
print "parser.parse()"
print program
result = interp.executeScript(program)
reader = BufferedReader(FileReader("/tmp/fworld"))
while 1:
s = reader.readLine()
if not s:
break
else:
print s
reader.close()
########## example code end ######################
Naturally these first experiments are encouraging to go forward.
Therefore my question: "As there exists access to the OpenXION source
code, which runs inside Field, what is the best way to directly call
into Field's Jython environment?". Of special interest are calls into
the DrawingPLines code. This way it would be easy to set up a
HyperCard-ish environment inside of Field! Which Field classes have to
be loaded inside the OpenXION runtime and how can it be assured that
the Field drawing calls get executed inside the canvas of the active
Field instance?
OpenXION is available at Google Code:
http://code.google.com/p/openxion/
I went through the whole source code of Field, but without advice it
will get to cumbersome to find the right implementation strategy.
Regards,
/tom fuerstner