Page 2 of 3
Re: Procedures inside Structures
Posted: Wed Mar 02, 2011 6:22 pm
by inc.
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
Re: Procedures inside Structures
Posted: Wed Mar 02, 2011 10:39 pm
by akj
@inc:
I did not realise you could do that for procedures within structures. Thank you.
Re: Procedures inside Structures
Posted: Thu Mar 03, 2011 1:29 am
by Zach
Adding my vote for this idea. I think it would be neat to see this and I would probably use it a lot.
Re: Procedures inside Structures
Posted: Thu Mar 03, 2011 11:04 am
by bembulak
Adding my vote for this idea. I think it would be neat to see this and I would probably use it a lot.
+1
Re: Procedures inside Structures
Posted: Thu Mar 03, 2011 5:09 pm
by moogle
I'd like to have this too.
Re: Procedures inside Structures
Posted: Fri Mar 04, 2011 8:35 pm
by buddymatkona
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

)
Re: Procedures inside Structures
Posted: Fri Mar 04, 2011 9:16 pm
by skywalk
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\"
Re: Procedures inside Structures
Posted: Sat Mar 05, 2011 2:21 am
by buddymatkona
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.
Re: Procedures inside Structures
Posted: Sat Mar 05, 2011 2:27 am
by skywalk
@buddymatkona
I hear you, and I think some of this would go away, if PB adopted modules in some fashion.
Re: Procedures inside Structures
Posted: Sat Mar 19, 2011 3:35 am
by ColeopterusMaximus
+1 to this idea
Re: Procedures inside Structures
Posted: Tue Mar 22, 2011 3:19 am
by Amundo
+1 !!!!!!!!!!!!!!!!!
Come on Fred, Freak, anyone???? Please comment....
Re: Procedures inside Structures
Posted: Fri Jan 20, 2012 2:59 am
by ricardo
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)
Re: Procedures inside Structures
Posted: Sat Jan 21, 2012 2:03 pm
by Marlin
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.
Re: Procedures inside Structures
Posted: Sun Jan 22, 2012 6:08 am
by xorc1zt
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.
Re: Procedures inside Structures
Posted: Wed Jun 17, 2020 8:21 am
by Rinzwind
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..