module dtest; import dmdscript.dobject; import dmdscript.value; import dmdscript.script; import dmdscript.dnative; import dmdscript.property; import dmdscript.threadcontext; import dmdscript.dfunction; import dmdscript.text; // this is a test to implemnt: // a: var x = new test() <-- a new object // b: x.dfdfdfd(); <-- call the object instance. // our methods go in here... class Dtest_prototype : Dtest { // our instance methods.. static void* testworld( Dobject pthis, CallContext* cc, Dobject othis, Value* ret, Value[] arglist) { ret.putVstring("Hello World"); return null; } // we register all our methods in here.. this(ThreadContext *tc) { super(tc.Dobject_prototype); this.Put(TEXT_constructor, tc.ctorTable[this.classname], DontEnum); this.Put("testworld", new DnativeFunction(&testworld, "testworld", 0, Dfunction.getPrototype()), 0); } } class Dtest_Constructor : Dfunction { // register static methods.. this(ThreadContext *tc) { super(7, tc.Dfunction_prototype); this.name = "test"; this.Put("testworld2", new DnativeFunction(&Dtest.testworld2, "testworld2", 0, Dfunction.getPrototype()), 0); } // our constructor void *Construct(CallContext *cc, Value *ret, Value[] arglist) { Dobject o; o = new Dtest(); // can this be automated?? ret.putVobject(o); return null; } } class Dtest: Dobject { static dsname = "test"; // our static methods.. static void* testworld2( Dobject pthis, CallContext* cc, Dobject othis, Value* ret, Value[] arglist) { ret.putVstring("Hello World2"); return null; } this(Dobject prototype) { super(prototype); this.classname = dsname; //value.putVnumber(d_number.nan); } this() // called when new Object is created... { ThreadContext *tc = ThreadContext.getThreadContext(); super( tc.protoTable[dsname]); this.classname = dsname; //this.value.putVnumber(n); } } /*-------------test.test -------------------*/ class Dtest_test_prototype : Dtest_test { // our instance methods.. static void* testworld( Dobject pthis, CallContext* cc, Dobject othis, Value* ret, Value[] arglist) { ret.putVstring("Hello World"); return null; } // we register all our methods in here.. this(ThreadContext *tc) { super(tc.Dobject_prototype); this.Put(TEXT_constructor, tc.ctorTable[this.classname], DontEnum); this.Put("testworld", new DnativeFunction(&testworld, "testworld", 0, Dfunction.getPrototype()), 0); } } class Dtest_test : Dobject { static dsname = "test"; static class Constructor : Dfunction { // our static methods.. static void* testworld2( Dobject pthis, CallContext* cc, Dobject othis, Value* ret, Value[] arglist) { ret.putVstring("Hello World2"); return null; } // register static methods.. this(ThreadContext *tc) { super(7, tc.Dfunction_prototype); this.name = dsname; this.Put("testworld2", new DnativeFunction(&testworld2, "testworld2", 0, Dfunction.getPrototype()), 0); } // our constructor void *Construct(CallContext *cc, Value *ret, Value[] arglist) { Dobject o; o = new Dtest_test(); // can this be automated?? ret.putVobject(o); return null; } } this(Dobject prototype) { super(prototype); this.classname = dsname; //value.putVnumber(d_number.nan); } this() // called when new Object is created... { ThreadContext *tc = ThreadContext.getThreadContext(); this(tc.protoTable["test.test"]); /// this is not going to work!? this.classname = dsname; //this.value.putVnumber(n); } } // register all the classes in this file.. static void Dtest_init(CallContext* cc) { char[] dsname; ThreadContext *tc = ThreadContext.getThreadContext(); // add cto & proto to db. dsname = "test"; tc.ctorTable[dsname] = new Dtest_Constructor(tc); tc.protoTable[dsname] = new Dtest_prototype(tc); // add the ctor to the global namespace. cc.global.Put(dsname, tc.ctorTable[dsname], DontEnum); // add {object}.prototype = prototype. tc.ctorTable[dsname].Put("prototype", tc.protoTable[dsname], DontEnum | DontDelete | ReadOnly); dsname = "test.test"; tc.ctorTable[dsname] = new Dtest_test.Constructor(tc); tc.protoTable[dsname] = new Dtest_test_prototype(tc); // add the ctor to the global namespace. //cc.global.Put(dsname, tc.ctorTable[dsname], DontEnum); // add {object}.prototype = prototype. tc.ctorTable[dsname].Put("prototype", tc.protoTable[dsname], DontEnum | DontDelete | ReadOnly); tc.ctorTable["test"].Put("test", tc.ctorTable[dsname] , 0); }