Re: DSEL syntax, or opening the can of worms.
"Roman Yakovenko" <[email protected]>
| Newsgroups | gmane.comp.lib.boost.langbinding |
|---|---|
| Message-ID | <[email protected]> |
On 8/8/07, Rene Rivera <[email protected]> wrote: > First I think we all agree that the Luabind DSEL syntax is "nicer" than > the BPL syntax. Last night, something kept bothering me. The syntax > dealing with namespaces/modules vs. the syntax for dealing with classes > and inner classes are inconsistent with each other. Yet to me both deal > with defining scopes, and members within those scopes. To take a simple > example: > > namespace a > { > int f(); > > struct A > { > void do(); > > struct B > { > void again(); > }; > }; > } > > In Luabind the binding declaration would look like: > > module(L) > [ > namespace_(L,"a") > [ > def("f",&a::f), > class<a::A>("A") > .def("do",&a::A::do) > .scope > [ > class_<a::A::B>("B") > .def("again",&a::A::B::again) > ] > ] > ] > > That shows that 'module' and 'namespace_' use [] to bound the scope they > define. But 'class' uses ".method" to chain the scope out as needed. And > introduces the rather unintuitive, IMO, '.scope' to allow one "access" > to the class scope. So I though, why not be consistent and use [] to > define all scopes. Which leads to (removing the module/namespace > destinction): > > namespace_(L,"a") > [ > def("f",&a::f), > class_<a::A>("A") > [ > def("do",&a::A::do), > class_<a::A::B>("B") > [ > def("again",&a::A::B::again) > ] > ] > ] > > Which has a one-to-one correspondence with the C++ code. Boost.Python code looks familiar to Python users: class< X > ( "X" ) .def( ... ) .def( ... ); I guess that this was one the goals of the library. lang-binding is a little bit different: it aims to provide different "back-ends". I think it is impossible to come with a DSL, which will satisfy all "back-end" developers and you are right: we should stick to one-to-one correspondence with the C++ code. -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ ------------------------------------------------------------------------- This SF.net email is sponsored by: Splunk Inc. Still grepping through log files to find problems? Stop. Now Search log events and configuration files using AJAX and a browser. Download your FREE copy of Splunk now >> http://get.splunk.com/