#Compiled / #EndCompiled

<< Click to Display Table of Contents >>

Navigation:  ThinBASIC and External Compilers interop >

#Compiled / #EndCompiled

 

Description

 

Defines section of external compilers source code inside ThinBASIC script.

 

Syntax

 

#Compiled [SuppressRTE] [language = INISectionLanguageName]

 {source code statements and exported functions}

#EndCompiled

 

Returns

 

Parameters

 

Name

Meaning

INISectionLanguageName

Is the name of the INI section name specified inside \thinBasic\Compilers\thinBasic_Compilers_Usr.ini containing compiler options

 

Remarks

 

There can be multiple #Compiled / #EndCompiled sections in your thinBasic script(s).

 

The content of all #Compiled / #EndCompiled sections will be concatenated into a single source code and compiled automatically by ThinBASIC into a single DLL to be usable from thinBASIC script.

 

DLL will be named with the same name of the ThinBASIC script and placed into the same directory.

The name of the compiled DLL can be retrieved at script runtime via Compiled_DLL_FileName command.

 

In case there are functions or subs defined inside the #Compiled / #EndCompiled, they can be used directly from ThinBASIC code without the need to declare them if and only if:

1.they use CDECL calling convention

2.they use EXPORT to be visible from DLL

 

If SuppressRTE option is present, no classic thinBasic runtime error will occur in case of errors

 

Language option is used to specify compiled languages configuration section.

Actually ONLY FreeBasic is allowed in case Language option is specified - at the moment.

 

Restrictions

 

If compiled code will contain errors, a standard ThinBASIC runtime error window will appear showing output from external compiler.

 

If programmer wants to handle compiler errors, use SuppressRTE option. In this case no ThinBASIC runtime error window will appear and programmer can use Compiled_LastCompile_Result and Compiled_LastCompile_Output functions to handle errors.

 

See also

 

Examples

 

#Compiled Language = FreeBasic

 

sub SayHelloFromFreeBasic cdecl alias "SayHelloFromFreeBasic" (byref sMessage as zstringexport

  print sMessage

end sub

  

#EndCompiled

 

uses "Console"

 

' Thanks to thinBASIC autodetection,

' the FreeBasic function is discovered automatically

SayHelloFromFreeBasic("Hello, BASIC")

 

printl "Press a key to end..."

waitKey