Purebasic Reference Manual 5.73
Total Page:16
File Type:pdf, Size:1020Kb
PureBasic Reference Manual 5.73 http://www.purebasic.com/ November 23, 2020 Contents I General5 1 Introduction 6 2 Terms And Conditions9 3 System requirements 10 4 Installation 11 5 Order 12 6 Contact 14 7 Acknowledgements 15 II The PureBasic Editor 17 8 Getting Started 18 9 Working with source files 19 10 Editing features 21 11 Managing projects 27 12 Compiling your programs 32 13 Using the debugger 40 14 Included debugging tools 47 15 Using the built-in Tools 54 16 Using external tools 61 17 Getting Help 66 18 Customizing the IDE 68 19 Command-line options for the IDE 83 III Language Reference 85 20 Working with different number bases 86 21 Break : Continue 90 22 Using the command line compiler 92 23 Compiler Directives 95 1 24 Compiler Functions 99 25 Data 106 26 Debugger keywords in PureBasic 110 27 Define 112 28 Dim 114 29 Building a DLL 116 30 Enumerations 118 31 For : Next 121 32 ForEach : Next 123 33 General Syntax Rules 125 34 Global 129 35 Gosub : Return 132 36 Handles and Numbers 134 37 If : Else : EndIf 136 38 Import : EndImport 138 39 Includes Functions 140 40 Inline x86 ASM 142 41 Interfaces 145 42 Licenses for the PureBasic applications (without using 3D engine) 147 43 Licenses for the 3D engine integrated with PureBasic 159 44 Macros 186 45 Pointers and memory access 189 46 Migration guide 193 47 Migration from PureBasic 5.20 LTS to 5.40 LTS 194 48 Migration from PureBasic 5.30 to 5.40 197 49 Migration from PureBasic 5.40 to 5.50 200 50 Migration from PureBasic 5.50 to 5.60 201 51 Migration from PureBasic 5.60 to 5.72 LTS 202 52 Module 203 53 NewList 206 54 NewMap 208 55 Others Commands 210 2 56 Procedures 212 57 Protected 216 58 Prototypes 218 59 Pseudotypes 220 60 PureBasic objects 222 61 Repeat : Until 225 62 Residents 226 63 Runtime 227 64 Select : EndSelect 229 65 Using several PureBasic versions on Windows 231 66 Shared 232 67 Static 233 68 Structures 235 69 Subsystems 241 70 Threaded 243 71 UserGuide - Advanced functions 245 72 UserGuide - Constants 246 73 UserGuide - Storing data in memory 247 74 UserGuide - Decisions & Conditions 249 75 UserGuide - Compiler directives (for different behavior on different OS) 251 76 UserGuide - Reading and writing files 255 77 UserGuide - First steps with the Debug output (variables & operators) 258 78 UserGuide - Displaying graphics output & simple drawing 260 79 UserGuide - Building a graphical user interface (GUI) 265 80 UserGuide - Input & Output 269 81 UserGuide - Other Compiler keywords 270 82 UserGuide - Other Library functions 271 83 UserGuide - Loops 272 84 UserGuide - Memory access 274 85 UserGuide - Overview 280 86 UserGuide - Dynamic numbering of windows and gadgets using #PB_Any 281 87 UserGuide - Managing multiple windows with different content 287 3 88 UserGuide - Structuring code in Procedures 302 89 UserGuide - String Manipulation 307 90 UserGuide - Displaying text output (Console) 310 91 UserGuide - Some Tips & Tricks 313 92 UserGuide - Variables and Processing of variables 316 93 Unicode 319 94 Variables and Types 320 95 While : Wend 329 96 Windows Message Handling 330 97 With : EndWith 332 4 Part I General 5 Chapter 1 Introduction PureBasic is an ”high-level” programming language based on established ”BASIC” rules. It is mostly compatible with any other ”BASIC” compiler. Learning PureBasic is very easy! PureBasic has been created for beginners and experts alike. Compilation time is extremely fast. This software has been developed for the Windows operating system. We have put a lot of effort into its realization to produce a fast, reliable and system-friendly language. The syntax is easy and the possibilities are huge with the ”advanced” functions that have been added to this language like pointers, structures, procedures, dynamic lists, maps, interfaces, modular programmation (modules), an inline assembler and much more. For the experienced coder, there are no problems gaining access to any of the legal OS structures or API objects. PureBasic is a portable programming language which currently works on Linux, Mac OS X and Windows computer systems. This means that the same code can be compiled natively for the OS and use the full power of each. There are no bottlenecks like a virtual machine or a code translator, the generated code produces an optimized executable. The main features of PureBasic - x86 and x64 support - 83 native libraries - Hundreds of functions - Built-in arrays, dynamic lists, complex structures, maps, pointers and variable definitions - Supported types: Byte (8-bit), Word (16-bit), Long (32-bit), Quad (64-bit), Float (32-bit), Double (64-bit) and Characters - User defined types (structures) - Built-in string types (characters), including ascii and unicode - Powerful macro support - Constants, binary and hexadecimal numbers supported - Expression reducer by grouping constants and numeric numbers together - Standard arithmetic support in respect of sign priority and parenthesis: +, -, /, *, and, or, «, » - Extremely fast compilation - Procedure support for structured programming with local and global variables - All Standard BASIC keywords: If-Else-EndIf, Repeat-Until, etc - Specialized libraries to manipulate BMP pictures, windows, gadgets, DirectX, etc - Specialized libraries are very optimized for maximum speed and compactness - The Win32 API is fully supported as if they were BASIC keywords - Inline Assembler - Precompiled structures with constants files for extra-fast compilation - Integrated debugger to follow the execution of a program and correct errors more easily - Configurable CLI compiler - Dedicated editor with automatically highlighted syntax - Very high productivity, comprehensive keywords, online help 6 - System friendly, easy to install and easy to use - IDE and help available in english, french and german - SDK Visual C - Compilation of windowed program, console and DLL - Creation of integrated wysiwyg windows - Creation of windows with automatic reorganization of gadgets (layout) with the ’Dialog’ library - 33 native gadgets - 1 gadget specialized in OpenGL - 1 scintilla gadget - Process, thread, mutex, semaphore - Drag’n drop - DPI for MS Windows - QT and GTK3 for Linux - DirectX and OpenGL systems - Import of static (lib) or dynamic libraries (dll, so, etc.) - Drawing with antialiasing with the ’Vector’ library - 3D functions with the 3D engine OGRE - Pseudotypes: p-ascii, p-utf8, p-bstr, p-unicode, p-variant - Array, linked-list (list), maps, Database (MySQL, SQLite, ODBC, PostgreSQL, Maria) - json, xml - Regular expression - http, ftp, mail, application server / client, CGI and FastCGI - Cypher - OnError - Compressor/decompressor: BriefLZ, JCALG1, LZMA, Tar, Zip - ini file - Printer, serial port - Runtime Here is the exhaustive list of all the libraries that PureBasic offers: 1 Windows & system : 2 arrays 3 cgi 4 cipher 5 clipboard 6 console 7 database 8 date 9 debugger 10 desktop 11 dialog 12 dragdrop 13 file 14 filesystem 15 font 16 ftp 17 gadget 18 help 19 http 20 json 21 library 22 lists 23 mail 24 maps 25 math 26 memory 27 menu 28 network 29 onerror 30 packer 7 31 preference 32 printer 33 process 34 regularexpression 35 requester 36 runtimes 37 scintilla 38 serialport 39 sort 40 statusbar 41 string 42 system 43 systray 44 thread 45 toolbar 46 window 47 xml 48 49 2D & Medias : 50 2 ddrawing 51 audiocd 52 font 53 image 54 imageplugin 55 joystick 56 keyboard 57 mouse 58 movie 59 music 60 screen 61 sound 62 soundplugin 63 sprite 64 vectordrawing 65 66 3D Engine : 67 billboard 68 camera 69 engine3d 70 entity 71 entityanimation 72 gadget3d 73 joint 74 light 75 material 76 mesh 77 node 78 nodeanimation 79 particle 80 sound3d 81 specialeffect 82 spline 83 staticgeometry 84 terrain 85 text3d 86 texture 87 vehicle 88 vertexanimation 89 window3d 8 Chapter 2 Terms And Conditions This program is provided ”AS IS”. Fantaisie Software are NOT responsible for any damage (or damages) attributed to PureBasic. You are warned that you use PureBasic at your own risk. No warranties are implied or given by Fantaisie Software or any representative. The demo version of this program may be freely distributed provided all contents, of the original archive, remain intact. You may not modify, or change, the contents of the original archive without express written consent from Fantaisie Software. PureBasic has an user-based license. This means you can install it on every computer you need but you can’t share it between two or more people. All components, libraries, and binaries are copyrighted by Fantaisie Software. The PureBasic license explicitly forbids the creation of DLLs whose primary function is to serve as a ’wrapper’ for PureBasic functions. Fantaisie Software reserves all rights to this program and all original archives and contents. PureBasic uses the OGRE OpenSource 3D-Engine and its licence can be consulted here . The full sources of the PureBasic-customized OGRE engine can be downloaded at http://www.purebasic.com/OgreSources.zip. PureBasic uses the OnError library, written and (c) 2003 by Siegfried Rings and Sebastian Lackner. PureBasic uses the Scintilla editing component and its related license can be consulted here . The PureBasic XML library uses the expat XML parser. Its license can be viewed here . The PureBasic RegularExpression library uses the PCRE library. Its license can be viewed here . 9 Chapter 3 System requirements PureBasic will run on Windows XP, Windows Vista, Windows 7, Windows 8 and Windows 10 (in both 32-bit and 64-bit edition), Linux (kernel 2.2 or above) and MacOS X (10.8.5 or above). If there are any problems, please contact us. Windows For many graphic functions like 3D or Sprites there is needed the DirectX9.0c version. Windows Vista and later don’t have installed this from start, so it need to be installed manually. You can download and install it via the ”DirectX End-User Runtime Web Installer” here: http://www.microsoft.com/en-us/download/details.aspx?displaylang=en&id=35.