[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kjsembed
Subject:    [kjsembed] Update on examples
From:       Ian Reinhart Geiser <geiseri () yahoo ! com>
Date:       2005-08-08 14:43:46
Message-ID: 200508081043.53644.geiseri () yahoo ! com
[Download RAW message or body]

[Attachment #2 (multipart/signed)]


Greetings,
I have gone ahead and broken out an example of how to embed and how to extend 
KJSEmbed.  In examples/embed is the start.  Its not very heavy on the 
comments yet, but it is small enough to talk about with some detail.

The embed.cpp is the main place of action.  That shows how to startup and 
embed the interpreter in as few lines as possible.

KJSEmbed::Engine *kernel = new KJSEmbed::Engine(); is the big todo.  This 
creates the basic interpreter and bindings.  After you do that you can add 
your own custom bindings.  I store off a few parts of the KJS interpreter and 
global object to make things easier to manage then.

To add bindings that you have created custom is pretty basic:
KJSEmbed::StaticConstructor::add( exec, &globalObject, 
TestObject::constructor() );

This basicly registers the constructor with the interpreter.  To make a static 
instance of an object you can construct an instance of it and put it on the 
global object like so:
globalObject.put( exec, "Test", TestObject::construct(exec, KJS::List() ) );

The KJS::List() is an argument list, so if you wish to pass args to the ctor, 
you can do so in that list.  It is just a list of KJS values.

Now if you have QObjects that you wish to publish to the global context we 
have a convenience function:
KJS::Object appobj = kernel->addObject( &app, "Application" );

This basicly will cause a QObjects properties and slots to become published in 
a global instance.  You cannot new or delete it, but you can use it as an 
interface to the base application.  This is handy if you have a QObject based 
interface, and don't wish to build a custom static binding.

Once you have the entire mess setup, you can then kick off the script with a:
KJSEmbed::Engine::ExitStatus result = kernel->runFile( "test.js" );

You can also run a single string if you wish.

The result is the exit status of the script.  If the script throws an 
exception that is not caught you can see the error message with a:
kernel->completion().value().toString(exec).qstring()

So thats it for the main embedding. To extend is a bit more indepth, so I will 
try to cover that separately.

Cheers
	-ian reinhart geiser


[Attachment #5 (application/pgp-signature)]

_______________________________________________
kjsembed mailing list
kjsembed@kde.org
https://mail.kde.org/mailman/listinfo/kjsembed


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic