On Wed, Feb 15, 2017 at 12:12 PM, Gergely Buday <
buday.gerg...@uni-eszterhazy.hu> wrote:

> Where in the Libre Office source tree I can find the glue code for various
> extension languages?

I do not remember the code locations, but I once had a look at Java and
Python bindings. For python, some (most, almost all?) classes are generated
dynamically at runtime (so you get no code completion in IDE). For Java,
there is some hand-written glue code and the rest are generated jar files
(it directly generates jars from the IDL without intermediate Java sources;
method parameter names are not specified in the jars, so you get some code
completion, but it is not great.)

There are manual attempts to write nicer, more human friendly bindings, I
saw something e.g. for python when I searched Pypi. Not sure how
comprehensive they are; it possibly covers only what the original author
needed covered...

> Another option is to use Scala as it is possible to write extensions in
> Java and Scala can use Java libraries.
> Did anybody write a Libre Office extension in Scala?

I was looking into writing a macro[1] in Kotlin. It is not ML, but it has
some syntactic elements borrowed from that tradition... One nice thing you
can do in Kotlin (that you cannot in Java) is create extension function

fun <T> Any.query(anInterface: Class<T>): T {
// TODO: taking KClass did not work for me
return UnoRuntime.queryInterface(anInterface, this)

and then you can do

val sheets = xScriptContext.document.query(com.sun.star.sheet.XSpreadshee

instead of

val sheets = UnoRuntime.queryInterface(com.sun.star.sheet.XSpreadsheetDoc
ument::class.java, xScriptContext.document)

Neither is spectacularly readable, but choosing from the two, the first is
IMO nicer.

Also, I have a gradle task to compile and push the macro to my libreoffice
directory, so I can recompile and redeploy it into running Calc in about 5
seconds. Not spectacular either, but it is as good as I was able to get
given I have to have a compilation step.

[1] https://github.com/msgqe/doccheck
Jiří Daněk
LibreOffice mailing list

Reply via email to