[texworks] Kroll from Scripting API

Paul A Norman paul.a.norman at gmail.com
Tue Apr 27 02:11:17 CEST 2010


> >There is an interseting cross-platform,  cross-language, cross-compile
>> opensource project I've bneen following a bit that has devised a means
>> of running ruby, php, python, JavaScript and their own object system
>> together, quite facinating. You can actually mix language in scripts.
>
>> From: http://www.linuxjournal.com/article/10437 ...
>

>That is indeed fascinating - though I don't think something exactly like
>this will hit Tw anytime soon ;). If I understand the article correctly
>(I only browsed through it so far) they embed the code in other
>documents (html in this case). This means that they effectively have to
>parse their source for such code blocks and then distribute them to the
>different scripting interpreters. In our case, you'd still have separate
>files - although I would very much like the idea that different scripts
>can communicate with each other somehow.

Here is the site I was looking for, this will explain it all far
better than I have so far sorry:

"Kroll is a compact microkernel written in C++ for running pluggable
modules. Kroll supports a cross-language, cross-platform "binding"
and invocation framework which supports mixing and matching
code within the Kroll kernel. Yes, that means you can pass a
Javascript object to a Python function and stuff like that.  It's
just that bad ass ... admit it.

"Currently, Kroll supports the following languages:

- C/C++
- Python
- Ruby
- PHP
- JavaScript

"However, any C/C++ exposed language which supports embedding most likely
can be supported with not much effort. These languages are on the
target list to be added soon:

- Lua  (already in progress)
- Falcon (interest from Falcon community indicated)
- C# (maybe via Mono)
- Java

from a longer document at http://github.com/appcelerator/kroll

Some choice quotes:

" Languages are modules in Kroll and are first-class citizens in the
runtime environment. So, when using the runtime, you can pass objects
back and forth between JavaScript, PHP, Python, and Ruby"

http://benramsey.com/archives/building-titanium-with-php/
====

"The Kroll / Ruby Bridge
Kroll is the underlying object and communication system in Titanium.
It has its own object system, including its own spectrum of types.
Whenever you call Ruby from JavaScript or JavaScript from Ruby, your
data will be flowing through Kroll."

"Objects
Passing a JavaScript object to Ruby involves wrapping the JavaScript
object in a Ruby object. This means that if you change a JavaScript
object in Ruby, that change will be reflected in the original object.
When dealing with objects that flow from one language context to
another, it suffices to think of them as the same object. "

"Exceptions
Exceptions that are thrown in either Ruby or JavaScript will be
converted using the same rules as normal variables when bubbling up
into different languages. This means that if an exception is thrown in
Ruby, you should be able to catch it in JavaScript and vice-versa."

https://developer.appcelerator.com/doc/desktop/ruby
====

I think it is even possible to write dirctly in that 'script' Kroll.

Paul


More information about the texworks mailing list