MiniD 2 - Tentative Release Candidate 1

mpt mpt at iki.fi
Mon Dec 8 12:22:14 PST 2008


Jarrett Billingsley wrote:
> On Mon, Dec 8, 2008 at 3:44 AM, mpt <foo at invalid.x> wrote:
>> Great stuff, but I have some trouble with the binding lib.
> 
> Good!  Because I wasn't ;)
> 
>> 1. If I don't wrap a constructor, I get an error:
>> minid/bind.d(1101): static assert  "Cannot call default constructor for class Foo; please wrap a constructor explicitly"
> 
> Fixed.

Fix compiles for the explicitly defined ctor, but not for the default. 
This code gives:
minid/bind.d(1110): Error: no super class constructor for Foo

import minid.bind;
import minid.api;

class Foo {}

void main() {
     MDVM vm;
     auto t = openVM(&vm);
     loadStdlibs(t);
     WrapGlobals!(
         WrapType!(
             Foo, "Foo"
         )
     )(t);
}

>> 3. I can't find an obvious way to initialize global variables, so I try superPush, which gives a runtime error:
> 
> You're actually doing it right, unless you wanted to instantiate the
> wrapped MiniD class, in which case it'd be more like:
> 
>    pushGlobal(t, "Foo"); // get the global class Foo
>    pushNull(t); // make room for 'this'
>    rawCall(t, -2, 1); // call the class to instantiate it (1 return
> for the instance)
>    newGlobal(t, "myfoo"); // save it in the global myfoo
> 

I can't see the difference between superPush-created myfoo and one 
created by your example. superPush doc says it creates MiniD-converted 
objects, but they're not usable.

superPush(t, new Foo());
newGlobal(t, "myfoo");
runString(t, "myfoo.Call();");

This gives: 
"tango.core.Exception.AssertException at ../extern/minid/minid/bind.d(1397): 
Invalid 'this' parameter passed to method Foo.Call"

Your example works, but it's not what I need. I want to create the Foo 
object in D myself and pass it to MiniD and call its methods.

Ideally, I'd like to have/write a function like
void setGlobal(Type)(MDThread* t, char[] name, Type value) to create and 
modify global variables.


More information about the Digitalmars-d-announce mailing list