Changes

Jump to navigation Jump to search
2,050 bytes added ,  11:32, 27 August 2007
no edit summary
*http://wiki.contextgarden.net/HTML_and_ConTeXt
 
 
= Following [http://labix.org/lunatic-python] I was able, in a linux box, to modify luatex-snapshot-20070820.tar.bz2 so that <tt>luatex --luaonly</tt> can host python. Of course <tt>\directlua0{....}</tt> also works.<br/>
'''WARNING: these modifications break security and portability'''
<pre>
% engine=luatex
\def\TestA#1{%
\directlua0{%
require('python')
re = python.import("re")
pattern = re.compile(".*(TeX).*")
match = pattern.match("#1")
if match
then
print( 'match.group(1)===>',match.group(1))
else
print ('#1 no match')
end
}}
 
\def\TestB#1{%
\directlua1{%
require('python')
re = python.import("re")
pattern = re.compile(".*(TeX).*")
match = pattern.match("#1")
if match
then
print( 'match.group(1)===>',match.group(1))
else
print ('#1 no match')
end
}}
 
\def\TestC{%
\directlua0{%
require('python')
python.execute('n=1')
n=python.eval('n')
print("PYTHON:"..n)
%% --[[ --]]
python.execute('s="XYZ"')
s=python.eval('s')
print("PYTHON:"..s,",lenght="..\letterhash s)
%% --[[ --]]
python.execute('d={"Boo":1}')
python.execute('d["FOO"]=2')
d=python.eval('d')
print("PYTHON:",d)
print("PYTHON:",d.Boo,d["Boo"],d.FOO,d["FOO"])
%% --[[ --]]
python.execute('a=[1,3,2,5,9]')
a=python.eval('a')
print("PYTHON:",a)
print("PYTHON:",a[0],a[1])
python.execute('a.append("X")')
python.execute('a.sort()')
a=python.eval('a')
print("PYTHON:",a)
print("PYTHON:",a[0],a[1])
%% --[[ --]]
a=python.eval('[0,3,8,2,-1]')
print("PYTHON:",a[3])
print("PYTHON:",a,type(a))
%%
}}
 
%%-- testD.lua
%% require('python')
%% print("BEGIN PYTHON")
%% pycode=[[
%% class Test(object):
%% def __init__(self):
%% self.a=[0,3,81,2,-1]
%% self.b=self.a[:]
%% self.a.sort()
%%
%% def get(self):
%% return self.a,self.b
%% ]]
%% python.execute(pycode)
%% python.execute("t=Test()")
%% print(python.eval("t.get()"))
%% t=python.eval("Test()")
%% print(t.get())
%% print(t.get()[0])
%% print(t.get()[0][0])
%% print(TeX)
%% print("END PYTHON")
\def\TestD#1{%
\directlua0{%
TeX='#1'
dofile('testD.lua')}%
}
 
 
 
\starttext
 
\TestD
 
\stoptext
 
 
</pre>
 
=Future ConTeXt Users=
[[Future_ConTeXt_Users]]

Navigation menu