[prev in list] [next in list] [prev in thread] [next in thread]
List: kjsembed
Subject: [kjsembed] Suggestion on bindings macros
From: ian reinhart geiser <geiseri () yahoo ! com>
Date: 2005-08-09 4:27:53
Message-ID: 200508090027.53626.geiseri () yahoo ! com
[Download RAW message or body]
Greetings,
In an effort to make adding bindings less verbose I have been playing
with some macros. Normally I tend to want to avoid heavy macro usage
(bad memories of windows message maps), but I think in this case it
can remove tons of duplicated code, that is errorprone and just plain
ugly.
Basicly I simplified the bindings macro to the following:
KJS_BINDING( <ClassName> )
This will expand the stub code needed build the enum, method and
constructor tables. This removes about 8 lines of code, of which 4
have properties that are VERY important to have names match up.
On the implementation side to actually implement the binding I have
added three macros beyond the current ones for creating methods.
START_METHOD_LUT( <ClassName> ) and
START_STATIC_METHOD_LUT(<ClassName>)
This bugger will replace the method table, it creates the right setup
and name for the array, so all you have to do is let it know what
class it is a part of. END_METHOD_LUT will close it up. An example
is as follows:
START_METHOD_LUT( TestObject )
{"print", 1, KJS::DontDelete|KJS::ReadOnly|KJS::DontEnum,
&TestObjectNS::callPrint }
END_METHOD_LUT
START_ENUM_LUT( <ClassName> ) is the same jazz only with enums. An
example is as follows:
START_ENUM_LUT( TestPointer )
{"START", Line::START},
{"END", Line::END}
END_ENUM_LUT
In cases where there are no methods or enums you can use the
NO_ENUMS(<ClassName>), NO_STATICS(<ClassName>) or
NO_METHODS(<ClassName>) macro to stub them out correctly.
The biggest one then is the START_CTOR( <ClassName>, <MaxArgs> )
macro. This will setup the constructor method and table correctly so
all you have to do is add the constructor method code. Again this
removes about 5 lines of tedious code. A simple example is below:
START_CTOR( TestPointer, 1 )
Line *line = new Line();
line->name = "unnamed";
if( args.size() == 1 )
line->name = args[0].toString(exec).qstring();
KJSEmbed::ObjectBinding object(exec, "Line", line );
StaticBinding::publish( exec, &object, TestPointer::methods() );
return object;
END_CTOR
I am not 100% happy with this so far, but I think I like the
direction. Anyone else have some opinions?
Cheers
-ian reinhart geiser
_______________________________________________
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