1.11 External Procedures and Functions

INCLUDE file

The INCLUDE statement can be used to include another LynPlex script file at this point. The included code will be interpreted as if it had been written into the including script at that point.

If no path is specified, the search will start in the same folder as the current script. This means that versions under development or local versions will be used in preference.

If the included file is not in the local folder, any folders specified in the initialisation files will be used. Any user specific include folders will be searched before system include folders.

Finally if the file is still not found, the system search path will be used.

If the file is not found an error is returned.

External procedures and functions

If a you make a procedure or function call and the target of the call is not built-in or user-defined it will be assumed to be an external procedure or function.

At run time the interpreter will search for a file of the same name and if found will execute it.

If no path is specified, the search will start in the same folder as the current script. This means that versions under development or local versions will be used in preference.

If the file is not in the local folder, any folders specified in the initialisation files will be used. Any user specific include folders will be searched before system include folders.

Finally if the file is still not found, the system search path will be used.

If the file is not found an error is returned.

Implementation Status:

LynPlex Interpreter
To be implemented.
LynPlexC Compiler
To be implemented
LynPlexS Compiler
To be implemented

External libraries

External libraries or units are a set of procedures, functions that have been separately compiled. They are loaded in at run time.

A unit is declared by the use of UNIT keyword.

UNIT MyUnit

The functions, procedure or variables which we want to be visible to another programs must be declared with the EXPORT keyword.

UNIT MyUnit
EXPORT MyF
...
FUNC MyF(x)
...
END

Keep file-name and unit-name the same. That helps the SB to automatically recompile the required units when it is needed.

To link a program with a unit use the IMPORT keyword.

IMPORT MyUnit

To access a member of a unit use the unit-name, a point and the name of the member.

IMPORT MyUnit
...
PUT MyUnit.MyF(1/1.6)

file my_unit.bas:

UNIT MyUnit
EXPORT F, V

// a shared function
FUNC F(x)
  F = x*x
  END

// a non-shared function
FUNC I(x)
  I = x+x
  END

// Initialization code
V = "I am a shared variable"
L = "I am invisible to the application"
PUT "Unit 'MyUnit' initialized :)"

file my_app.bas:

IMPORT MyUnit

PUT MyUnit.V
PUT MyUnit.F(2)

Implementation Status:

LynPlex Interpreter
To be implemented.
LynPlexC Compiler
To be implemented
LynPlexS Compiler
To be implemented

lynplex/lp0111.txt · Last modified: 2011/09/08 16:07 (external edit)