View Full Version : Nesting Lianja.evaluate to call foxpro and javascript from python.

2016-09-13, 13:26
Just thought I would share this one.

I have a custom VFP section, with a webview control in a container I called alphaweb.
alphaweb is declared as public variable in my VFP Section.

I have the URL set to a jssp page that has several javascript functions declared in the jssp page.

I also have a python library that I am using for some image manipulation.

The challenge is to call the javascript functions from the python code.
Normally that's easy, I could use Lianja.get().webview, but recall the webview is in a custom section, so you need to reference it by public variable.

With a bit of tinkering, I found it was pretty easy.

Using Lianja.evaluate, I call the foxpro code to call the javascript code from the python code.

Like so.

Def procname():

I thought it was pretty cool to be able to go back and forth between, the VFP, Python and javascript functions.

Lianja made that easy.


ps - I am sure there is an easier way, but it was still fun.;)

2016-09-13, 23:39
Its also worth mentioning that in Lianja 3.1 the execPython( expr ), execPHP( expr ) and execJavaScript( expr ) Lianja/VFP functions return the result of the executed code. This makes it simple to integrate Lianja/VFP with Python/PHP/JavaScript. If expr is a filename it it loaded and executed.

And also just to remind you.

1. In Python, PHP and JavaScript you can call Lianja.evaluate( expr ) to call back into Lianja/VFP.
2. The Lianja/VFP loadLibrary( filename ) function can load Python (.py), PHP (.php) and JavaScript (.js) libraries too.