"DefFunction" as Replacement/additional for Prototype

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
GPI
PureBasic Expert
PureBasic Expert
Posts: 1394
Joined: Fri Apr 25, 2003 6:41 pm

"DefFunction" as Replacement/additional for Prototype

Post 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.
User avatar
Keya
Addict
Addict
Posts: 1890
Joined: Thu Jun 04, 2015 7:10 am

Re: "DefFunction" as Replacement/additional for Prototype

Post by Keya »

+1 for anything that shaves keystrokes! time is money is life
Mistrel
Addict
Addict
Posts: 3415
Joined: Sat Jun 30, 2007 8:04 pm

Re: "DefFunction" as Replacement/additional for Prototype

Post 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.
Post Reply