Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
PureBasic
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
== Programming language == === Characteristics === 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.<ref name="PureBasic home page">[http://www.purebasic.com/index.php PureBasic home page]</ref> It can compile console applications,<ref name="PureBasic - Console">[http://www.purebasic.com/documentation/console/index.html PureBasic - Console]</ref> GUI applications,<ref name="PureBasic - Gadget">[http://www.purebasic.com/documentation/gadget/index.html PureBasic - Gadget]</ref> and DLL files.<ref name="Building a DLL">[http://www.purebasic.com/documentation/reference/dll.html Building a DLL]</ref> === Hello World example === 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!" program|Hello World]]". <syntaxhighlight lang="blitzbasic"> MessageRequester("Message Box", "Hello World")</syntaxhighlight> 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. <syntaxhighlight lang="blitzbasic"> MessageBox_(0, "Hello World", "Message Box", 0)</syntaxhighlight> The following is a console version of the Hello World example. <syntaxhighlight lang="blitzbasic"> OpenConsole() ; Open a console window. Print("Hello, World!") Delay(5000) ; Pause for 5 seconds</syntaxhighlight> === Procedural programming === 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 {{mono|Goto, Gosub Label}}, and {{mono|Return}}. Below is a sample procedure for sorting an array, although SortArray is now a built-in function of PureBasic. <syntaxhighlight lang="blitzbasic" line highlight="1,15"> 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</syntaxhighlight> Below is a sample program that displays a sizeable text editor with two menu items. <syntaxhighlight lang="blitzbasic"> ;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 </syntaxhighlight> PureBasic does not escape double quotes in strings so these must be concatenated with {{mono|Chr(34)}}. === Object-oriented programming === Fred, the developer of PureBasic, has stated that PureBasic will never be [[Object-oriented programming|object oriented]].<ref name="PureBasic won't be object oriented">[http://www.purebasic.fr/english/viewtopic.php?p=403070#p403070 PureBasic won't be object oriented]</ref> However, numerous users have created object oriented support systems.<ref name="PureBasic Forum: PureObject - PureBasic OOP support">[http://www.purebasic.fr/english/viewtopic.php?t=30236 PureObject: PureBasic OOP support]</ref><ref name="PureBasic Forum: OOP tutorial added to the nxSoftware site!">[http://www.purebasic.fr/english/viewtopic.php?t=36255 OOP tutorial]</ref><ref name="PureBasic Forum: Another OOP PreCompiler">[http://www.purebasic.fr/english/viewtopic.php?t=30774 Another OOP PreCompiler]</ref> === Data types === 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 - {{mono|.f, .d}} (float and double numbers), {{mono|.b, .c, .w, .l, .q}} (integers - from single-byte and 8-byte), {{mono|.s}} - strings. {| class="wikitable" |- ! Type !! Suffix !! Memory usage !! Numerical range |- | Byte || {{mono|b}} || 1 byte (8 bits) || β128 ... +127 |- | Ascii || {{mono|a}} || 1 byte (8 bits) || 0 ... +255 |- | Character || {{mono|c}} || 1 byte (8 bits) (ascii) || 0 ... +255 |- | Word || {{mono|w}} || 2 bytes (16 bits) || β32768 ... +32767 |- | Unicode || {{mono|u}} || 2 bytes (16 bits) || 0 ... +65535 |- | Character || {{mono|c}} || 2 bytes (16 bits) (unicode) || 0 ... +65535 |- | Long || {{mono|l}} || 4 bytes (32 bits) || β2147483648 ... +2147483647 |- | Integer || {{mono|i}} || 4 bytes (32 bits) x86 || β2147483648 ... +2147483647 |- | Float || {{mono|f}} || 4 bytes (32 bits) || Depending on the ratio of the decimal number. |- | Integer || {{mono|i}} || 8 bytes (64 bits) x64 || β9223372036854775808 ... +9223372036854775807 |- | Quad || {{mono|q}} || 8 bytes (64 bits) || β9223372036854775808 ... +9223372036854775807 |- | Double || {{mono|d}} || 8 bytes (64 bits) || Depending on the ratio of the decimal number. |- | String || {{mono|s}} || (String length + 1) * [[sizeof|SizeOf]](Character) || No limit. |- | Fixed String || {{mono|s{length}}} || (String length) * SizeOf(Character) || No limit. |} * {{mono|Len(String)}} used to count the length of a string will not exceed the first [[null character]] ({{mono|Chr(0)}}). In addition to basic types, the user can define the type of construction via <syntaxhighlight lang="text"> 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 </syntaxhighlight> Variables can be single (actually, standard variables), [[dynamic array]] (declared using the {{code|lang=blitzbasic|Dim var_name.type_name (size1, size2, ... )}}, a [[linked list]] ({{code|lang=blitzbasic|List() var_name.type_name}}), an [[associative array]] (in new versions of language) ({{code|Map var_name.type_name()}})
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)