Page 1 of 1

"DefFunction" as Replacement/additional for Prototype

Posted: Tue Jan 03, 2017 1:43 pm
by GPI
the most used form of prototype ist to create one prototype for one variable.
it would be useful to combine this in one step

for example:

Code: Select all

Prototype.i ProtoMessageBoxW(Window.i, Body.p-unicode, Title.p-unicode, Flags.i = 0)
  If OpenLibrary(0, "User32.dll")   
    ; 'MsgBox' is a variable with a 'ProtoMessageBoxW' type
    MsgBox.ProtoMessageBoxW = GetFunction(0, "MessageBoxW")
    MsgBox(0, "Hello", "World") ; We don't specify the flags
  EndIf
would be

Code: Select all

 If OpenLibrary(0, "User32.dll")   
    ; 'MsgBox' is a variable with a 'ProtoMessageBoxW' type
    DefFunction.i  MsgBox(Window.i, Body.p-unicode, Title.p-unicode, Flags.i = 0) = GetFunction(0, "MessageBoxW")
    MsgBox(0, "Hello", "World") ; We don't specify the flags
  EndIf
other example:

Code: Select all

Prototype.i ProtoMessageBoxW(Window.i, Body.p-unicode, Title.p-unicode, Flags.i = 0)
Structure API
  MsgBox.ProtoMessageBoxw
EndStructure
would be

Code: Select all

Structure API
  DefFunction.i MsgBox(Window.i, Body.p-unicode, Title.p-unicode, Flags.i = 0)
EndStructure
Maybe a other Keyword would be better. DefType? But this is used in C in a complete diffrent way. Or VariableType? Or UserType?
Don't forget a DefFunctionC and the Global command.

Re: "DefFunction" as Replacement/additional for Prototype

Posted: Tue Jan 03, 2017 2:01 pm
by Keya
+1 for anything that shaves keystrokes! time is money is life

Re: "DefFunction" as Replacement/additional for Prototype

Posted: Tue Jan 03, 2017 5:29 pm
by Mistrel
GPI wrote:But this is used in C in a complete diffrent way.
C uses the same structure by differentiating between a function declaration and definition; the only difference is that it doesn't use keywords to do so. A function signature without a body is a declaration and one with a body is a definition. This allows headers and source files to be referenced independently.

It certainly is frustrating at the beginning but PureBasic's implementation is actually very accurate.