This article includes a list of general references, but it remains largely unverified because it lacks sufficient corresponding inline citations. (June 2011) |
Paradigm | structured, imperative, procedural |
---|---|
Family | BASIC |
Designed by | Fantaisie Software |
Developer | Fantaisie Software |
First appeared | 1998 (AmigaOS) 2000 (Windows) |
Stable release | 5.73 LTS
/ November 23, 2020 |
OS | cross-platform: Microsoft Windows, Linux, macOS (active) AmigaOS (discontinued, open source) |
License | commercial |
Filename extensions | .pb, .pbi, .pbf, .pbp, .pbv |
Website | www |
PureBasic is a commercially distributed procedural computer programming language and integrated development environment based on BASIC and developed by Fantaisie Software for Windows 32/64-bit, Linux 32/64-bit, and macOS. An Amiga version is available, although it has been discontinued and some parts of it are released as open source. The first public release of PureBasic for Windows was on 17 December 2000. It has been continually updated since.
PureBasic has a "lifetime license model". As cited on the website, the first PureBasic user (who registered in 1998) still has free access to new updates and this is not going to change.[1]
PureBasic compiles directly to x86, x86-64, PowerPC or 680x0 instruction sets, generating small standalone executables and DLLs which need no runtime libraries beyond the standard system libraries. Programs developed without using the platform-specific application programming interfaces (APIs) can be built easily from the same source file with little or no modification.
PureBasic supports inline assembly, allowing the developer to include FASM assembler commands within PureBasic source code, while using the variables declared in PureBasic source code, enabling experienced programmers to improve the speed of speed-critical sections of code. PureBasic supports and has integrated the OGRE 3D Environment. Other 3D environments such as the Irrlicht Engine are unofficially supported.
PureBasic is a native cross platform 32 bit and 64 bit BASIC compiler. Currently supported systems are Windows, Linux, macOS. The AmigaOS version is legacy and open-source. The compiler produces native executables and the syntax of PureBasic is simple and straightforward, comparable to plain C without the brackets and with native unicode string handling and a large library of built-in support functions.[2] It can compile console applications,[3] GUI applications,[4] and DLL files.[5]
The following single line of PureBasic code will create a standalone x86 executable (4.5 KiB (4,608 bytes) on Windows version) that displays a message box with the text "Hello World".
MessageRequester("Message Box", "Hello World")
And the following variant of the same code, which instead uses an inline Windows API call with no need for declarations or other external references, will create an even smaller 2.0 KiB (2,048 bytes) standalone x86 executable for Windows.
MessageBox_(0, "Hello World", "Message Box", 0)
The following is a console version of the Hello World example.
OpenConsole() ; Open a console window.
Print("Hello, World!")
PureBasic is a "Second generation BASIC" language, with structured conditionals and loops, and procedure-oriented programming supported. The user is not required to use procedures, so a programmer may opt for a coding style which includes Goto, Gosub Label, and Return.
Below is a sample procedure for sorting an array, although SortArray is now a built-in function of PureBasic.
Procedure bubbleSort(Array a(1))
Protected i, itemCount, hasChanged
itemCount = ArraySize(a())
Repeat
hasChanged = #False
itemCount - 1
For i = 0 To itemCount
If a(i) > a(i + 1)
Swap a(i), a(i + 1)
hasChanged = #True
EndIf
Next
Until hasChanged = #False
EndProcedure
Below is a sample program that displays a sizeable text editor with two menu items.
;Create Window:
OpenWindow(0, #PB_Ignore, #PB_Ignore, 800, 600, "Simple Text Editor", #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget | #PB_Window_SizeGadget)
;Add 2 menus:
CreateMenu(0, WindowID(0))
MenuItem(1, "&OK")
MenuItem(2, "&Cancel")
;Add Editor:
EditorGadget(0, 0, 0, 0, 0)
SetGadgetFont(0, LoadFont(0, "Courier New", 10))
;Process window messages until closed:
Repeat
Select WaitWindowEvent()
Case #PB_Event_Menu
Select EventMenu()
Case 1: MessageRequester("OK clicked directly or with '&' mnemonic.", GetGadgetText(0))
Case 2: Break
EndSelect
Case #PB_Event_SizeWindow: ResizeGadget(0, 0, 0, WindowWidth(0, #PB_Window_InnerCoordinate), WindowHeight(0, #PB_Window_InnerCoordinate))
Case #PB_Event_CloseWindow: Break
EndSelect
ForEver
Note that PureBasic does not escape double quotes in strings so these must be concatenated with Chr(34).
Fred, the developer of PureBasic, has stated that PureBasic will never be object oriented.[6] However, numerous users have created object oriented support systems.[7][8][9]
Variable data type specified when you first use it (and optionally - in the future), and is separated from the name of the point. There is a set of basic types - .f, .d (float and double numbers), .b, .c, .w, .l, .q (integers - from single-byte and 8-byte), .s - strings.
Type | Suffix | Memory usage | Numerical range |
---|---|---|---|
Byte | b | 1 byte (8 bits) | −128 ... +127 |
Ascii | a | 1 byte (8 bits) | 0 ... +255 |
Character | c | 1 byte (8 bits) (ascii) | 0 ... +255 |
Word | w | 2 bytes (16 bits) | −32768 ... +32767 |
Unicode | u | 2 bytes (16 bits) | 0 ... +65535 |
Character | c | 2 bytes (16 bits) (unicode) | 0 ... +65535 |
Long | l | 4 bytes (32 bits) | −2147483648 ... +2147483647 |
Integer | i | 4 bytes (32 bits) x86 | −2147483648 ... +2147483647 |
Float | f | 4 bytes (32 bits) | Depending on the ratio of the decimal number. |
Integer | i | 8 bytes (64 bits) x64 | −9223372036854775808 ... +9223372036854775807 |
Quad | q | 8 bytes (64 bits) | −9223372036854775808 ... +9223372036854775807 |
Double | d | 8 bytes (64 bits) | Depending on the ratio of the decimal number. |
String | s | (String length + 1) * SizeOf(Character) | No limit. |
Fixed String | s{length} | (String length) * SizeOf(Character) | No limit. |
In addition to basic types, the user can define the type of construction via
Structure type_name
field_name.type ; Single field. Perhaps the structures attachment.
field_name[count].type ; Static arrays.
; ...
; Optional construction StructureUnion .. EndStructureUnion allows you
; to combine multiple fields into one area of memory
; that is sometimes required for the conversion types.
StructureUnion
type_name.type
; ...
EndStructureUnion
EndStructure
Variables can be single (actually, standard variables), dynamic array (declared using the Dim var_name.type_name (size1, size2, ... )
, a linked list (List() var_name.type_name
), an associative array (in new versions of language) (Map var_name.type_name()
)
PureBasic has its own form designer to aid in the creation of forms for applications, but other third-party solutions are also available.[10][11][12] The original non-integrated Visual Designer was replaced with a new integrated Form Designer on 14 Feb 2013.[13]
PureBasic provides an online forum for users to ask questions and share knowledge. On 6 May 2013 the English language forum had 4,769 members and contained 44,043 threads comprising 372,200 posts since 17 May 2002.[14]
Numerous code sharing sites show PureBasic is used to create tools[15] and games in a fast and easy way,[16] and share large amounts of open-source code.[17]
By: Wikipedia.org
Edited: 2021-06-18 15:19:08
Source: Wikipedia.org