Got an idea for enhancing PureBasic? New command(s) you'd like to see?
IceSoft
Addict
Posts: 1682 Joined: Thu Jun 24, 2004 8:51 am
Location: Germany
Post
by IceSoft » Sat Aug 14, 2010 7:59 pm
I belive this is very important for some purebasic wrappers
Code: Select all
Structure myStruct
a.f
b.f
EndStructure
Procedure test(d.myStruct)
Debug d\a
Debug d\b
EndProcedure
aa.myStruct
aa\a = 10.0
aa\b = 5.0
test(aa)
Same for some return valueas as structures
Last edited by
IceSoft on Sat Aug 14, 2010 9:15 pm, edited 1 time in total.
Belive! C++ version of Puzzle of Mystralia
<Wrapper>4PB, PB<game>, =QONK=, PetriDish, Movie2Image, PictureManager,...
TomS
Enthusiast
Posts: 342 Joined: Sun Mar 18, 2007 2:26 pm
Location: Munich, Germany
Post
by TomS » Sat Aug 14, 2010 8:08 pm
Code: Select all
Structure myStruct
a.f
b.f
EndStructure
Procedure test(*d.myStruct)
Debug *d\a
Debug *d\b
EndProcedure
aa.myStruct
aa\a = 10.0
aa\b = 5.0
test(aa)
STARGÅTE
Addict
Posts: 2227 Joined: Thu Jan 10, 2008 1:30 pm
Location: Germany, Glienicke
Contact:
Post
by STARGÅTE » Sat Aug 14, 2010 8:15 pm
and for Return:
Code: Select all
Structure myStruct
a.f
b.f
EndStructure
Procedure test(*d.myStruct)
*d\a = 10.0
*d\b = 5.0
EndProcedure
test(aa.myStruct)
Debug aa\a
Debug aa\b
but you will:?
Code: Select all
Structure myStruct
a.f
b.f
EndStructure
Procedure.myStruct test()
d.myStruct
d\a = 10.0
d\b = 5.0
ProcedureReturn d
EndProcedure
aa.myStruct = test()
Debug aa\a
Debug aa\b
Right ?
but i thinks ist the same way
KJ67
Enthusiast
Posts: 218 Joined: Fri Jun 26, 2009 3:51 pm
Location: Westernmost tip of Norway
Post
by KJ67 » Sat Aug 14, 2010 8:32 pm
It is a nice suggestion I like it
, it would open up to clearer implementations of this kind of things.
Code: Select all
Structure Polynom
a.i: b.i : c.i
EndStructure
Structure PolynomProduct
a1.i: b1.i: c1.i
a2.i: b2.i: c2.i
a3.i: b3.i: c3.i
EndStructure
Procedure.PolynomProduct PMul(a.Polynom, b.Polynom)
Protected result.PolynomProduct
;... code...
ProcedureReturn result
EndProcedure
But there may be a huge chunk of data on the stack, just imagine...
Code: Select all
Procedure.iso_image CatchCDImage(Drive)
EndProcedure
The best preparation for tomorrow is doing your best today.
IceSoft
Addict
Posts: 1682 Joined: Thu Jun 24, 2004 8:51 am
Location: Germany
Post
by IceSoft » Sat Aug 14, 2010 8:53 pm
By reference:
Procedure test(*d.myStruct)
by value:
Procedure test(d.myStruct)
Belive! C++ version of Puzzle of Mystralia
<Wrapper>4PB, PB<game>, =QONK=, PetriDish, Movie2Image, PictureManager,...
STARGÅTE
Addict
Posts: 2227 Joined: Thu Jan 10, 2008 1:30 pm
Location: Germany, Glienicke
Contact:
Post
by STARGÅTE » Sat Aug 14, 2010 8:56 pm
ah, you will work with "a copy" of structure in your procedure ...
TomS
Enthusiast
Posts: 342 Joined: Sun Mar 18, 2007 2:26 pm
Location: Munich, Germany
Post
by TomS » Sat Aug 14, 2010 8:57 pm
Code: Select all
By Value: aa\a = 10.0
By Value: test(aa)
Demivec
Addict
Posts: 4260 Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA
Post
by Demivec » Sat Aug 14, 2010 9:21 pm
Code: Select all
;by value
Procedure test(*d)
Protected e.myStruct
CopyStructure(*d, e, myStruct)
Debug e\a
EndProcedure
test(aa.myStruct)
IceSoft
Addict
Posts: 1682 Joined: Thu Jun 24, 2004 8:51 am
Location: Germany
Post
by IceSoft » Sat Aug 14, 2010 9:59 pm
Demivec wrote: Code: Select all
;by value
Procedure test(*d)
Protected e.myStruct
CopyStructure(*d, e, myStruct)
Debug e\a
EndProcedure
test(aa.myStruct)
This example works only for own written procedures. Not for external dll which want be wrapped for PB.
Belive! C++ version of Puzzle of Mystralia
<Wrapper>4PB, PB<game>, =QONK=, PetriDish, Movie2Image, PictureManager,...
Demivec
Addict
Posts: 4260 Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA
Post
by Demivec » Sun Aug 15, 2010 1:36 am
IceSoft wrote: This example works only for own written procedures. Not for external dll which want be wrapped for PB.
@IceSoft: You're correct, I had forgotten that you wanted this specifically for PureBasic wrappers.
cas
Enthusiast
Posts: 597 Joined: Mon Nov 03, 2008 9:56 pm
Post
by cas » Sun Aug 15, 2010 10:45 am
If you want to communicate with external dll then you must use AllocateMemory()/FreeMemory().
Code: Select all
Structure test
x.i
y.i
EndStructure
Procedure create()
Protected *dat.test=AllocateMemory(SizeOf(test))
*dat\x=15
*dat\y=45
ProcedureReturn *dat
EndProcedure
Procedure test_separate_copy(*struct)
Protected privatecopy.test
CopyMemory(*struct,@privatecopy,SizeOf(test))
Debug privatecopy\x
Debug privatecopy\y
EndProcedure
Procedure test(*struct.test)
Debug *struct\x
Debug *struct\y
*struct\y=80
EndProcedure
Define *mystruct.test=create()
test(*mystruct)
Debug *mystruct\x
Debug *mystruct\y
test_separate_copy(*mystruct)
FreeMemory(*mystruct)
IceSoft
Addict
Posts: 1682 Joined: Thu Jun 24, 2004 8:51 am
Location: Germany
Post
by IceSoft » Sun Aug 15, 2010 11:46 am
@cas,
As long you use *<varaiable name> as parameter as long it is always a pointer and this is byReference not byValue.
Belive! C++ version of Puzzle of Mystralia
<Wrapper>4PB, PB<game>, =QONK=, PetriDish, Movie2Image, PictureManager,...
cas
Enthusiast
Posts: 597 Joined: Mon Nov 03, 2008 9:56 pm
Post
by cas » Sun Aug 15, 2010 12:13 pm
Yes, but when you have reference then you know value to which it points, so i don't see a problem. Can you explain more how do you want to behave test() procedure in your first post? Do you want it to make separate protected d.myStruct which, when modified inside procedure, will not make changes in aa.myStruct?
Or you wan't to use C++ dll in PureBasic when it returns structure like this one(?):
Code: Select all
#define EXPORT extern "C" __declspec(dllexport)
struct DataStructure
{
int x;
int y;
};
EXPORT DataStructure TestReturnStructure() {
DataStructure data;
data.x=4;
data.y=7;
return data;
}
OrangeJuice
User
Posts: 24 Joined: Sat Jul 24, 2010 11:56 am
Post
by OrangeJuice » Mon Aug 16, 2010 9:28 pm
I think there was a good reason why C didn't allow that which i can't seem to remember right now. Maybe that is a slow thing to do?