www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Plugins, Property Injections and Reflection

reply Dennis Kempin <dennis xardias.net> writes:
Hi,

i had been using Java and liked the modern Container concepts (Just like
picocontainer.codehaus.org). I was wondering if something similar is
possible with D.
The following things are needed and i dont know exactly if this is possible
with D:
- Dynamically loading D binaries (Using .dll, .so files). I found the DDL
Project at dsource which should help on this. But at the moment it is not
available for D 1.0
- Java-like reflection for property injection: Well i know how to access
class fields using indices, but it would be be very helpful to have an
name->index mapping which can be used to set fields depending on their
name.

In the end it should be possible to place plugin files into a folder and
inject properties into classes loaded from these plugins. Just like this:

configuration file:
TestClass.testProperty=Hello

D interface source file:
interface TestInterface
{
        public void test();     
}

D implementation source file:
class TestClass: TestInterface // implement the Interface
{
        public char[] testProperty;
        public void test(){ writefln(testProperty); }
}

D usage:
// create a TestClass instance and inject the testProperty=Hello value
TestInterface test = Factory.loadFromPlugin(..); 
test.test(); // should now print "Hello"

The interface is known at compile time of the host application, but the
implementation should be replaceable at start time.

I hope you understand what i plan to do.
regards
Dennis
Feb 07 2007
parent "ideage" <lsina 126.com> writes:


1.D's DLL is C fromat,depend on Windows,can't link.
2.DDL: like dll,but not for D1.0.
3."flectioned" lib allow reflection but not for property injection.
   http://svn.dsource.org/projects/flectioned
4.Only one way,use embed language,like DLua,MiniD.

ideage from CHINA. 
Feb 07 2007