Got an idea for enhancing PureBasic? New command(s) you'd like to see?
inc.
Enthusiast
Posts: 406 Joined: Thu May 06, 2004 4:28 pm
Location: Cologne/GER
Post
by inc. » Wed Mar 02, 2011 6:22 pm
akj wrote: I also like Aonym's syntax but I think the variation below is neater.
Code: Select all
Structure foobar
; Members
x.i
y.i
; Methods
Declare.i bar(z.i)
Declare set(x.i, y.i)
EndStructure
Why using "Declare"? Its not needed as in PureBasic's syntax you can declare the return type at the end of the methods name like its already possible in interfaces:
Code: Select all
Structure foobar
; Members
x.i
y.i
; Methods
bar.i(z.i)
set(x.i, y.i)
EndStructure
Check out OOP support for PB here!
akj
Enthusiast
Posts: 665 Joined: Mon Jun 09, 2003 10:08 pm
Location: Nottingham
Post
by akj » Wed Mar 02, 2011 10:39 pm
@inc:
I did not realise you could do that for procedures within structures. Thank you.
Anthony Jordan
Zach
Addict
Posts: 1654 Joined: Sun Dec 12, 2010 12:36 am
Location: Somewhere in the midwest
Contact:
Post
by Zach » Thu Mar 03, 2011 1:29 am
Adding my vote for this idea. I think it would be neat to see this and I would probably use it a lot.
bembulak
Enthusiast
Posts: 572 Joined: Mon Mar 06, 2006 3:53 pm
Location: Austria
Post
by bembulak » Thu Mar 03, 2011 11:04 am
Adding my vote for this idea. I think it would be neat to see this and I would probably use it a lot.
+1
cheers,
bembulak
moogle
Enthusiast
Posts: 372 Joined: Tue Feb 14, 2006 9:27 pm
Location: London, UK
Post
by moogle » Thu Mar 03, 2011 5:09 pm
I'd like to have this too.
buddymatkona
Enthusiast
Posts: 252 Joined: Mon Aug 16, 2010 4:29 am
Post
by buddymatkona » Fri Mar 04, 2011 8:35 pm
Without OOP, "procedures inside a structure" are a good way to organize and store everything in one place however it might lead to some confusion with multiple source versions of a procedure. By the way, I hope as hardware gets faster and faster, compiler writers will again prefer a 2-pass approach so the tool can automate simple tasks rather than pass them on to the user. (mindless things like prototyping procedures present in the source code
)
skywalk
Addict
Posts: 3972 Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA
Post
by skywalk » Fri Mar 04, 2011 9:16 pm
buddymatkona wrote: (mindless things like prototyping procedures present in the source code )
Prototypes are not always explicit
Given pointers, you can write multiple prototypes for the same function, given your preference.
...example...
Code: Select all
WinLib = OpenLibrary(#PB_Any, "kernel32.dll")
If WinLib
Prototype.l GetTempPath(nBufferLength.l, *lpBuffer.i)
Global GetTempPath.GetTempPath = GetFunction(WinLib, "GetTempPathA")
Prototype.l GetTempPathSTR(nBufferLength.l, lpBuffer.s)
Global GetTempPathSTR.GetTempPathSTR = GetFunction(WinLib, "GetTempPathA")
EndIf
buf.s = Space(513)
fn = GetTempPath(512, @buf)
Debug Trim(buf) ; -> "C:\DOCUME~1\SKYWALK\LOCALS~1\Temp\"
buf = Space(513)
fn = GetTempPathSTR(512, buf)
Debug Trim(buf) ; -> "C:\DOCUME~1\SKYWALK\LOCALS~1\Temp\"
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
buddymatkona
Enthusiast
Posts: 252 Joined: Mon Aug 16, 2010 4:29 am
Post
by buddymatkona » Sat Mar 05, 2011 2:21 am
I was not talking about all prototypes. Those containing mindless repetition can be supplied by the compiler. A 1-pass compiler may need a simple prototype just because the procedure comes after its first reference in the source file. A 2-pass compiler can find all the definitions before it deals with references.
From a user interface point of view, the goal should be to never require the user to supply the same information more than once unless required to resolve ambiguity.
skywalk
Addict
Posts: 3972 Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA
Post
by skywalk » Sat Mar 05, 2011 2:27 am
@buddymatkona
I hear you, and I think some of this would go away, if PB adopted modules in some fashion.
Amundo
Enthusiast
Posts: 191 Joined: Thu Feb 16, 2006 1:41 am
Location: New Zealand
Post
by Amundo » Tue Mar 22, 2011 3:19 am
+1 !!!!!!!!!!!!!!!!!
Come on Fred, Freak, anyone???? Please comment....
Win8.1, PB5.x, okayish CPU, onboard video card, fuzzy monitor (or is that my eyesight?)
"When the facts change, I change my mind" - John Maynard Keynes
ricardo
Addict
Posts: 2402 Joined: Fri Apr 25, 2003 7:06 pm
Location: Argentina
Post
by ricardo » Fri Jan 20, 2012 2:59 am
This is very nice
Look this one:
Code: Select all
Prototype Suma(uno,dos)
Prototype Resta(uno,dos,this)
Structure Js
;Propiedades
a.l
b.l
c.l
;Method
Suma.Suma
Resta.Resta
EndStructure
Procedure Suma(uno,dos)
Result = uno + dos
ProcedureReturn Result
EndProcedure
Procedure Resta(uno,dos,*this.Js)
dos = *this\a
Result = uno - dos
ProcedureReturn Result
EndProcedure
Probemos.Js
Probemos\Suma = @Suma()
Probemos\Resta = @Resta()
Debug Probemos\Suma(Probemos\a,2)
Probemos\a=2
Debug Probemos\Resta(10,2,Probemos)
Probemos\a=7
Debug Probemos\Resta(10,2,Probemos)
ARGENTINA WORLD CHAMPION
Marlin
Enthusiast
Posts: 406 Joined: Sun Sep 17, 2006 1:24 pm
Location: Germany
Post
by Marlin » Sat Jan 21, 2012 2:03 pm
I love to see my favorite thread injected with new life.
However there is no suggestion about Procedures inside Structures
as nice, easy, sensible, simple, ... as was posted at the beginning of this thread.
Just see
the first post .
xorc1zt
Enthusiast
Posts: 276 Joined: Sat Jul 09, 2011 7:57 am
Post
by xorc1zt » Sun Jan 22, 2012 6:08 am
interface allow oop, devs should finish the works with a less crappy way.
Code: Select all
; interface example
; xorc1zt
Interface MY_INTERFACE
abcd( arg1.s )
f1234( arg1.i, arg2.i )
get()
set( val.i )
destroyInterface()
EndInterface
Structure MY_INTERFACESTR
VirtualTablePointer.i
myvar.i
EndStructure
;-----------------------------------------
;---------- INTERFACE FUNCTIONS ----------
;-----------------------------------------
Procedure debugString (*Self.MY_INTERFACESTR, str.s )
Debug "debugString()"
Debug str
Debug ""
EndProcedure
Procedure debugInt (*Self.MY_INTERFACESTR, int1.i, int2.i )
Debug "debugInt()"
Debug int1
Debug int2
Debug ""
EndProcedure
Procedure.i getMyVar(*Self.MY_INTERFACESTR)
Debug "getMyVar()"
Debug ""
ProcedureReturn *Self\myvar
EndProcedure
Procedure setMyVar(*Self.MY_INTERFACESTR, newvalue.i)
Debug "setMyVar()"
Debug ""
*Self\myvar = newvalue
EndProcedure
Procedure destroy(*Self.MY_INTERFACESTR)
Debug "destroy()"
Debug "delete "+ Hex(*Self)
Debug ""
FreeMemory(*self)
EndProcedure
;-----------------------------------------
;-------------- Constructor --------------
;-----------------------------------------
Procedure.i myInterfaceConstructor()
Define *temp.MY_INTERFACESTR
*temp = AllocateMemory( SizeOf ( MY_INTERFACESTR ) )
*temp\VirtualTablePointer = ?VMT
*temp\myvar = 45
Debug "Create interface at "+Hex(*temp)
Debug "VMT at "+Hex(?VMT)
Debug ""
ProcedureReturn *temp
EndProcedure
;-----------------------------------------
;--------- Vitual Methods Table ----------
;-----------------------------------------
DataSection
VMT: ; THE INTERFACE MUST RESPECT THE SAME ORDER!!!
Data.i @debugString()
Data.i @debugInt()
Data.i @getMyVar()
Data.i @setMyVar()
Data.i @destroy()
EndDataSection
;-----------------------------------------
;----------------- TEST ------------------
;-----------------------------------------
test.MY_INTERFACE = myInterfaceConstructor()
test\abcd( "HELLO" )
test\f1234( 45, 37 )
Debug "var = "+Str( test\get() )
test\set( 7777 )
Debug "var = "+Str( test\get() )
test\destroyInterface()
; test\abcd( "HELLO" ) will produce a error, the inferface is no more.
Rinzwind
Enthusiast
Posts: 636 Joined: Wed Mar 11, 2009 4:06 pm
Location: NL
Post
by Rinzwind » Wed Jun 17, 2020 8:21 am
Yup here we are still waiting for the last few bits to be available in a compact easy to follow and maintain way. Obviously the need/wish is there for many years now. Just add the final pieces please. See first post in this topic..