thinBasic

From Wikipedia, the free encyclopedia
Jump to: navigation, search
ThinBasic
ThinBasic Logo
Developer Eros Olmi
Stable release v1.8.9.0 (September 04 - 2011)
Preview release v1.8.8.0 (June 19 - 2011)
Dialects BASIC
Influenced by Powerbasic
OS Windows
License Freeware / Proprietary
Website http://www.thinbasic.com/

thinBasic is a BASIC-like computer programming language interpreter[1] with a central core engine architecture surrounded by many specialized modules. Although originally designed mainly for computer automation, thanks to its modular structure it can be used for wide range of tasks.

Contents

[edit] Main Features

  • Modular structure
  • Rich set of predefined keywords
  • User-defined functions can take up to 32 parameters
  • All main flow control statements:
    • SELECT CASE
    • IF ... THEN/ELSEIF/ELSE/END IF
    • loops ( infinite, conditional, FOR, WHILE, DO/LOOP WHILE ..., DO/LOOP UNTIL ...)
  • Strong focus on string manipulation
  • Implicit line continuation
  • Dynamic calling of functions with function name composed at runtime using string expression
  • Mechanism of include files allows specify them using wildcard
  • Binding to third party DLLs (such as OpenGL, OpenCL, XML, ODE) can be provided via header files
  • Professional and huge help material
  • Advanced IDE
  • Hundred of examples covering many programming aspects
  • A Basic GUI tutorial released as thinBasic source code ready to be used for new programs

[edit] Variables and data types

ThinBASIC supports wide range of numeric[2] and string[3] data types.

Integer Floating point String Other
BYTE SINGLE STRING VARIANT
WORD DOUBLE STRING * n GUID
DWORD CURRENCY ASCIIZ * n BOOLEAN
INTEGER EXTENDED, EXT UDT (User defined type)
LONG UNIONS
QUAD

Besides those mentioned in the table above, programmer can define pointers, user defined types and unions.

The special features related to user defined types in ThinBASIC are[4]:

  • possibility to inherit members from one or more other user defined types
  • static members (members whose value is shared among all variables of given UDT)
  • dynamic strings

Variables can be defined in global, local or static scope. ThinBASIC supports arrays of up to 3 dimensions.

[edit] Modules

ThinBASIC is being installed with modules. Each module is dedicated to specific area of interest.[5]

Module name Purpose
UI creation of dialogs and windows, handling of controls, 2D double-buffered graphics
Console handling of Windows console
File creating, copying and saving information to files
Eval formula evaluation
TBGL 2D/3D hardware accelerated graphics
TBDI Game devices input
Bundle script self-bundling to EXE
INet Internet communications
Stat Statistics performed on arrays, such as median, arithmetic/geometric/harmonic mean, standard deviation, standard error...
Tokenizer various functionalities for parsing text
XPrint printing of text, shapes and bitmaps
Oxygen JIT compiler of machine code, assembler and BASIC like syntax which can be used to speed up the performance of time critical parts of otherwise interpreted ThinBASIC code
... ...

To use a module, programmer just has to write:

Uses "ModuleName"

By doing so, modules can immediately provide:

  • functions and procedures implementations
  • variable predefinition
  • constants predefinition
  • user-defined type definition

[edit] Customizing the language

Language can be enhanced by module development using SDK for many languages ( PowerBASIC, FreeBASIC, C, MASM ).

[edit] Integrated development environment (IDE)

thinAir, thinBasic IDE

ThinBASIC comes with own IDE, called thinAir, in the default installation.[6] It provides:

  • Customizable syntax highlighting
  • Code templates
  • Multiple source files opened at once
  • Ability to view one source using multiple views
  • Optional script obfuscation
  • Creation of independent executable from the script
  • Access to the help file


thinAir allows using the debugger as well.
This component is called thinDebug[7] and can be watched on the image linked below.

[edit] Code samples

Console program, which asks user about name and then greets him:

' Specifies program will use functions from console module
uses "Console"
 
' TBMain represents main body of the program
function TBMain()
  ' Creates variable to hold user name
  local UserName as string
 
  ' Asks user for the name
  Console_Print("What is your name?: ")
 
  ' Stores it to variable
  UserName = Console_ReadLine
 
  ' If length of username is 0 then no name is specified, else program will say hello
  if len(UserName) = 0 then
    Console_PrintLine("No user name specified...") 
  else
    Console_PrintLine("Hello " + UserName + "!")  
  end if  
 
  ' Waits for any key from user before program ends
  Console_WaitKey
end function

Calling function by composing it name at run-time from strings:

' Use File module for handling files
uses "FILE"
 
function TBMain()
  ' Assign file name to variable, notice assignment can be done at time of declaring variable
  local MyFile as string = "c:\File.txt"
  local ReturnValue as long
 
  ' Functions are named Load_<fileExtension>, so we can determine
  ' the function name we need at run time and save some lines of code
  call "Load_"+FILE_PATHSPLIT(MyFile, %Path_Ext) ( MyFile ) To ReturnValue
 
end function
 
function Load_TXT( fName as string ) as long
 
  ' Code to load TXT file here
 
end function
 
function Load_BMP( fName as string ) as long
 
  ' Code to load BMP file here
 
end function

Code to draw 3D cube, which can be manipulated using arrow keys:
note: some keywords not correctly highlighted due to old version of syntax highligher on the Wiki

Uses "TBGL"
 
Begin Const
  ' -- Scene IDs
  %sScene  = 1
 
  ' -- Entity IDs 
  %eCamera = 1
  %eLight  
  %eBox        
End Const 
 
Function TBMain()
  Local hWnd As DWord
  Local FrameRate As Double
 
  ' -- Create and show window
  hWnd = TBGL_CreateWindowEx("TBGL script - press ESC to quit", 640, 480, 32, %TBGL_WS_WINDOWED Or %TBGL_WS_CLOSEBOX) 
  TBGL_ShowWindow 
 
  ' -- Create scene
  TBGL_SceneCreate(%sScene)
 
  ' -- Create basic entities
  ' -- Create camera to look from 15, 15, 15 to 0, 0, 0 
  TBGL_EntityCreateCamera(%sScene, %eCamera)
    TBGL_EntitySetPos(%sScene, %eCamera, 15, 15, 15)
    TBGL_EntitySetTargetPos(%sScene, %eCamera, 0, 0, 0)  
 
  ' -- Create point light  
  TBGL_EntityCreateLight(%sScene, %eLight)
    TBGL_EntitySetPos(%sScene, %eLight, 15, 10, 5)
 
  ' -- Create something to look at
  TBGL_EntityCreateBox(%sScene, %eBox, 0, 1, 1, 1, 0, 255, 128, 0)
    TBGL_EntitySetPos(%sScene, %eBox, 0, 0, 0)
 
  ' -- Resets status of all keys 
  TBGL_ResetKeyState() 
 
  ' -- Main loop
  While TBGL_IsWindow(hWnd) 
    FrameRate = TBGL_GetFrameRate
 
    TBGL_ClearFrame 
 
      TBGL_SceneRender(%sScene)
 
    TBGL_DrawFrame 
 
    ' -- ESCAPE key to exit application
    If TBGL_GetWindowKeyState(hWnd, %VK_ESCAPE) Then Exit While 
 
    If TBGL_GetWindowKeyState(hWnd, %VK_LEFT) Then
      TBGL_EntityTurn(%sScene, %eBox, 0,-90/FrameRate, 0)
    ElseIf TBGL_GetWindowKeyState(hWnd, %VK_RIGHT) Then
      TBGL_EntityTurn(%sScene, %eBox, 0, 90/FrameRate, 0)
    End If
 
  Wend 
 
  TBGL_DestroyWindow
End Function

[edit] Pros and cons

Advantages:

  • Takes full advantage of resources provided by Windows platform ( registry, user interface, work with processes, COM, DLLs)
  • Usually fast execution
  • Speed optimizations can be done using machine code and assembler
  • Under continuous development
  • Great string library with tons of functions working on dynamic strings

Disadvantages:

[edit] Compatibility

thinBASIC has been developed under Microsoft Windows XP Professional using PowerBASIC[8], and requires Internet Explorer version 5.50 or above.

[edit] References

  1. ^ Olmi, E. ThinBASIC Help Manual. Introducing ThinBASIC. Retrieved 2011-09-21
  2. ^ Olmi, E. ThinBASIC Help Manual. Numeric variables. Retrieved 2011-09-21
  3. ^ Olmi, E. ThinBASIC Help Manual. String variables. Retrieved 2011-09-21
  4. ^ Olmi, E. ThinBASIC Help Manual. Type. Retrieved 2011-09-21
  5. ^ Olmi, E. ThinBASIC Help Manual. Modules. Retrieved 2011-09-21
  6. ^ Olmi, E. ThinBASIC Help Manual. How to use. Retrieved 2011-09-21
  7. ^ Olmi, E. ThinBASIC Help Manual. thinTools/thinDebug. Retrieved 2011-09-21
  8. ^ www.powerbasic.com. Built with PowerBASIC!. Retrieved 2011-09-21

[edit] External links


[edit] See also

Personal tools
Namespaces

Variants
Actions
Navigation
Interaction
Toolbox
Print/export