MiniD 2 - Tentative Release Candidate 1

Jarrett Billingsley jarrett.billingsley at gmail.com
Mon Dec 8 13:31:09 PST 2008


On Mon, Dec 8, 2008 at 3:22 PM, mpt <mpt at iki.fi> wrote:
> 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);
> }

Fixed.

> 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.

There shouldn't be much different, at least from the point of view of
the MiniD code.  If you want to know, the difference is that instances
of the wrapped class created using MiniD are actually instances of a
class that is _derived_ from the class you wrapped, whereas instances
of the class you push are instances of the original class.  But the
binding library is *supposed* to abstract that away ;)

> 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"

Fixed.

> 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.

The implementation of that might be:

void SetGlobal(Type)(MDThread* t, char[] name, Type value)
{
    superPush(t, value);

    if(findGlobal(t, name))
    {
        swap(t);
        fielda(t, -2, name);
        pop(t);
    }
    else
        newGlobal(t, name);
}

This will create a global if it doesn't already exist, and will update
an existing global.  If you want it to always update an existing
global, it simply becomes "superPush(t, value); setGlobal(t, name);".


More information about the Digitalmars-d-announce mailing list