View previous topic :: View next topic |
Author |
Message |
windyu
Joined: 09 Jan 2009 Posts: 6
|
Posted: Fri Jan 09, 2009 5:18 am Post subject: some problem in use |
|
|
This is a great library, I like it! but I encountered some prob when using, hope can be resolved here.
first, a little bug, when the wrapped class has a function "char[] name {return "any"}", a error will be reported as "minid2\minid\bind.d(1170): Error: cannot evaluate name() at compile time", it seems get conflicted with the "name" declared in "private class WrappedClass(Type, char[] name, char[] moduleName, Members...) : Type", I temporary resolved it by change char[] name to char[] _rName.
second, WrapMethod will be visiable to sub class automatic, while WrapProperty can't.
third, when I WrapMethod a member fuction which take a struct embed struct member as parameter, i got the error:
Error: expression _D3gui6widget5frame5Inset6__initZ is not a valid template value argument
\tango\core\Tuple.d(393): template instance tango.core.Tuple.Tuple!(Backdrop(null,null,_D3gui6widget5frame5Inset6__initZ,false,0,0,
null,null)) error instantiating
code as below
struct Inset {
int left, top, right, bottom;
...
}
struct Backdrop {
Inset inset;
...
}
class Dummy {
void dummy(Backdrop b) {...}
}
last, how can i push a d object to minid function?
local f = Frame();
f.width = 222;
function test(a : Frame) {
writefln(a.width);
//a.width = 1;
}
test(f);
above minid code is ok!
auto frame = new Frame;
frame.width = 1234;
auto slot = pushGlobal(mState, "test");
pushNull(mState);
//pushNativeObj(mState, frame);
superPush(mState, frame);
rawCall(mState, slot, 0);
however, above code can't execute, when i use superPush, minid complained:
minid.types.MDException: test(9): Parameter 1: type 'class Frame' is not allowed
if i use pushNativeObj, i got:
minid.types.MDException: test(6): Parameter 1: type 'nativeobj gui.widget.frame. Frame' is not allowed
if i change function test to
function test(a) {
writefln(a.width);
//a.width = 1;
}
i still got error:
minid.types.MDException: test(7): Attempting to access field 'width' from a value of type 'nativeobj gui.widget.frame.Frame'
then what should i do? |
|
Back to top |
|
|
JarrettBillingsley
Joined: 20 Jun 2006 Posts: 457 Location: Pennsylvania!
|
Posted: Fri Jan 09, 2009 12:38 pm Post subject: Re: some problem in use |
|
|
windyu wrote: | This is a great library, I like it! but I encountered some prob when using, hope can be resolved here.
first, a little bug, when the wrapped class has a function "char[] name {return "any"}", a error will be reported as "minid2\minid\bind.d(1170): Error: cannot evaluate name() at compile time", it seems get conflicted with the "name" declared in "private class WrappedClass(Type, char[] name, char[] moduleName, Members...) : Type", I temporary resolved it by change char[] name to char[] _rName. |
Heh, that just causes DMD 1.039 to crash Scary. Oh well, it was an easy fix.
Quote: | second, WrapMethod will be visiable to sub class automatic, while WrapProperty can't. |
I'm not sure what you mean by this. I wrapped a class with a property, and the property works with both MiniD subclasses and wrapped D subclasses. Could you post some simple code which shows this?
Quote: | third, when I WrapMethod a member fuction which take a struct embed struct member as parameter, i got the error:
Error: expression _D3gui6widget5frame5Inset6__initZ is not a valid template value argument
\tango\core\Tuple.d(393): template instance tango.core.Tuple.Tuple!(Backdrop(null,null,_D3gui6widget5frame5Inset6__initZ,false,0,0,
null,null)) error instantiating
code as below
struct Inset {
int left, top, right, bottom;
...
}
struct Backdrop {
Inset inset;
...
}
class Dummy {
void dummy(Backdrop b) {...}
} |
Thanks, fixed.
Quote: | last, how can i push a d object to minid function?
local f = Frame();
f.width = 222;
function test(a : Frame) {
writefln(a.width);
//a.width = 1;
}
test(f);
above minid code is ok!
auto frame = new Frame;
frame.width = 1234;
auto slot = pushGlobal(mState, "test");
pushNull(mState);
//pushNativeObj(mState, frame);
superPush(mState, frame);
rawCall(mState, slot, 0);
however, above code can't execute, when i use superPush, minid complained:
minid.types.MDException: test(9): Parameter 1: type 'class Frame' is not allowed
if i use pushNativeObj, i got:
minid.types.MDException: test(6): Parameter 1: type 'nativeobj gui.widget.frame. Frame' is not allowed
if i change function test to
function test(a) {
writefln(a.width);
//a.width = 1;
}
i still got error:
minid.types.MDException: test(7): Attempting to access field 'width' from a value of type 'nativeobj gui.widget.frame.Frame'
then what should i do? |
Fixed. You were right to use superPush. pushNativeObj does not use the binding library and will just push a "raw" reference to the class instance. |
|
Back to top |
|
|
windyu
Joined: 09 Jan 2009 Posts: 6
|
Posted: Fri Jan 09, 2009 6:17 pm Post subject: Re: some problem in use |
|
|
Great, thanks for the quick reply
Quote: |
Quote: | second, WrapMethod will be visiable to sub class automatic, while WrapProperty can't. |
I'm not sure what you mean by this. I wrapped a class with a property, and the property works with both MiniD subclasses and wrapped D subclasses. Could you post some simple code which shows this? |
here is a example show what i mean:
class A {
char[] propA() {
return "A";
}
}
class B : A {
char[] propB() {
return "B";
}
}
then I wrap class A and B
WrapType!
(
A,
"A",
WrapProperty!(A.propA)
),
WrapType!
(
B,
"B",
WrapProperty!(B.propB)
)
in minid script
local b = B();
writefln(b.propB); //is ok!
writefln(b.propA); //wrong
last line is wrong, give error:
Error: B.opField(native): Attempting to access nonexistent field 'propA' from type B
only ok if i use WrapMethod!(A.propA) or add WrapProperty!(A.propA) when wrap class B |
|
Back to top |
|
|
JarrettBillingsley
Joined: 20 Jun 2006 Posts: 457 Location: Pennsylvania!
|
Posted: Fri Jan 09, 2009 7:59 pm Post subject: |
|
|
Ahh, yes, I see why that doesn't work. Hm. That will require a somewhat more complex implementation of properties in the binding lib. Until then, WrapProperty!(A.prop) is probably the best workaround. |
|
Back to top |
|
|
windyu
Joined: 09 Jan 2009 Posts: 6
|
Posted: Fri Jan 09, 2009 9:44 pm Post subject: |
|
|
ok, I will wait it |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|