berkelium is dead. Long live berkelium!

368 views
Skip to first unread message

Dennis Rieks

unread,
Oct 14, 2012, 6:47:34 PM10/14/12
to berk...@googlegroups.com
hi,

i started to write documentation for a new berkelium version.

it is avaible here:
https://docs.google.com/document/d/1SWxMnDsCqvUUuYAYXsH5I0FUV6C6w4S_Lmff3HiwCNY/edit#

feedback is welcome! you can leave comments there.

if you want to contribute: tell me your google account name and i give
you write permissions..

greetings
dennis

mikbal

unread,
Oct 15, 2012, 4:22:58 AM10/15/12
to berk...@googlegroups.com
Awesome!

Do you have any plans to expand javascript support in this new version?

chrome11 irritates me with its bugs and missing html5 features :(
Good Job

Romain Pironneau

unread,
Oct 15, 2012, 5:29:35 AM10/15/12
to berk...@googlegroups.com
Hello, I sort of have a stable C# wrapper to Berkelium built against version 11.

If you want to consider including it in this overhaul, I'd gladly help you.
--
- Romain

Dennis Rieks

unread,
Oct 15, 2012, 6:06:59 AM10/15/12
to berk...@googlegroups.com
Hi,

I had seen your c# wrapper some time ago and wanted to ask if you
could maintain the c# wrapper in the new version. presumably i think
it is necessary to reimplement it from from scratch because there are
many many changes.

Dennis

2012/10/15 Romain Pironneau <roma...@gmail.com>:

Dennis Rieks

unread,
Oct 15, 2012, 6:08:38 AM10/15/12
to berk...@googlegroups.com
Hi,

what exactly do you mean with expanded javascript support?

Dennis

2012/10/15 mikbal <sae...@gmail.com>:

Romain Pironneau

unread,
Oct 15, 2012, 6:16:28 AM10/15/12
to berk...@googlegroups.com
I'm up for it. I'd love to use this opportunity to do something cleaner than my current funky implementation.

BTW this was based on Kevin Gadd's Berkelium-Sharp project (thanks again Kevin!)
--
- Romain

mikbal

unread,
Oct 15, 2012, 6:51:56 AM10/15/12
to berk...@googlegroups.com
passing objects and array as parameters would be great addition.
get them as json, parse and serve to application.

methods like this

JsVariable var = window->GetVariable("MyVariable");

and

// lock c++ thread till result arrives. (or timeout)
JsVariable var = window->ExecuteScript("function() { return 42; }");



Dennis Rieks

unread,
Oct 15, 2012, 6:08:39 PM10/15/12
to berk...@googlegroups.com
Hi,

there is already a function sync() in the new api which we can use to
ensure that all previously called java script functions are processed.

A very simple implementation for GetVariable can be this:
std::string var = window->GetVariable("MyVariable");

the problem is that js is typeless, we can only provide helper functions like

JsVariable var = window->GetVariable("MyVariable");
if(var.isInt()) {
int i = var.toInt();
}
for int, double, float...

for this:
var.setInt(10);
JsVariable has to store a reference to the window, we must handle some
sort of errors for this (e.g. tab was already closed)

another useful function can be something like Javas AtomicInteger and
AtomicBoolean members:

var.increment()
var.getAndSet()

Because javascript runs in another process every set operation must be
done via ipc. to avoid ipc for reading we can introduce a update
function which will fetch the current value from javascript.

GetVariable and ExecuteScript should be no problem this way i think.

any comments?

-Dennis

2012/10/15 mikbal <sae...@gmail.com>:

mikbal

unread,
Oct 16, 2012, 2:33:48 AM10/16/12
to berk...@googlegroups.com
var.setInt(10);
var.increment();
var.getAndSet();

these are not necessary. imo JsVariable should stay as a value type. references will introduce unnecessary complexity for such a simple type.


About objects,
i get objects and arrays like this,

function SendVariableToCpp(obj){}

SendVariableToCpp(window.JSON.stringify(MyObj));

then parse it in c++.
it supports nested objects too. 
i would be great if new berkelium supported objects and array as function parameters.
JsVariable should be expanded to a recursive tree structure to hold objects/arrays.





Matt Vandermeulen

unread,
Oct 16, 2012, 10:33:10 AM10/16/12
to berk...@googlegroups.com
I'd like to second the request for Berkelium's support of objects and arrays.  I'm not entirely sure what would be involved with implementing that, but it would be nice to have.  I currently use a JSON library which throws a stringified version of the object to C++, and use a library to parse that and then access it through that library (jsonpp makes this pretty painless though, which is great).  It's just a bit of a nuisance.

Dennis Rieks

unread,
Oct 16, 2012, 2:01:48 PM10/16/12
to berk...@googlegroups.com
Hi,

2012/10/16 mikbal <sae...@gmail.com>:
> var.setInt(10);
> var.increment();
> var.getAndSet();
>
> these are not necessary. imo JsVariable should stay as a value type.
> references will introduce unnecessary complexity for such a simple type.
>

I think of a value type, the set methods can be helper functions which
calls "execJavaScript('x = 123')". a strong reference which always has
the same value is not possible i think.

>
> About objects,
> i get objects and arrays like this,
>
> function SendVariableToCpp(obj){}
>
> SendVariableToCpp(window.JSON.stringify(MyObj));
>
> then parse it in c++.
> it supports nested objects too.
> i would be great if new berkelium supported objects and array as function
> parameters.
> JsVariable should be expanded to a recursive tree structure to hold
> objects/arrays.

For this i think JsVariable must be a very very complex type, much
complexer then setter support.

maybe it is easier to use an existing json library for this?

We can use a simple javascript callback mehtod like:

void TabDelegate::JavaScriptCallback(Tab* tab, String name, String jsonData);

and provide an optional library where you can write:

void TabDelegate::JavaScriptCallback(Tab* tab, String name, String jsonData) {
JSON json(jsonData);
std::string str1 = json.index(5).string();
std::string str2 = json.index(8).get("key");
int i = json.index(20).int();
}

can this be a solution that fit your needs?

Dennis

Ivan Vučica

unread,
Oct 16, 2012, 3:01:42 PM10/16/12
to berk...@googlegroups.com
Dennis,

your suggestion of getting a reference to an in-engine variable, and then applying a value to this variable, is acceptable. I also think Mikbal can easily wrap stuff around whatever you provide. 

Berkelium is in my mind supposed to be primarily an easy-to-integrate engine, not a scripting powerhouse. And as long as arbitrary Javascript can be injected into a page, and as long as arbitrary Javascript can return a value, anything else is easily achievable.

If someone needs a powerful Javascript or other scripting engine, it's easy to find a stand-alone engine online. So I think a powerful API for integration with Javascript isn't necessary.

I'd say -- just do whatever is easiest for you, and provides a bare minimum of access to scripting. I, personally, would be happy to have anything at my disposal, as long as it works and is somewhat easy to understand.

:-)

mikbal

unread,
Oct 16, 2012, 4:04:22 PM10/16/12
to berk...@googlegroups.com
class JsVariable
{
std::string str;
double nbr;
std::map<std::string, JsVariable> children;
};

this can hold any js object.

but you should focus on task ahead first :)
as Ivan said, i am content with any version that works.
i will be very happy if i could get my hands on that shiny chrome22 :-)

Patrick Reiter Horn

unread,
Oct 16, 2012, 4:52:15 PM10/16/12
to berk...@googlegroups.com
I agree that this is useful--however, I think it's probably better to get the basics ironed out. A scripting interface is easy to implement on top of being able to execute javascript and get callbacks--you can see some of the code to do this from the old berkelium:


There's some messy code to register javascript callbacks in WindowImpl: I'm sure it can be cleaned up with some work:

For ABI compatibility reasons (thanks MSVC), we had used the WeakString struct instead of an actual std::string -- with the new library, ABI compatibility won't be an issue, so I'm fine going the route of using STL classes. This means the new berkelium can support non-empty objects/arrays, which would be nice.

-Patrick
Reply all
Reply to author
Forward
0 new messages