|
@@ -4,14 +4,14 @@
|
|
To add additional source files to a monkey2 project, you use the #Import directive. #Import can also be used to import other stuff into a project, but more on that late
|
|
To add additional source files to a monkey2 project, you use the #Import directive. #Import can also be used to import other stuff into a project, but more on that late
|
|
|
|
|
|
\#Imports should appear at the top of a source file before any declarations occur. #Import takes one parameter – the path to the file to import. If the file is a '.monkey2' file, the extensions can be omitted, eg:
|
|
\#Imports should appear at the top of a source file before any declarations occur. #Import takes one parameter – the path to the file to import. If the file is a '.monkey2' file, the extensions can be omitted, eg:
|
|
-
|
|
|
|
|
|
+
|
|
|
|
|
|
```
|
|
```
|
|
'file1.monkey2
|
|
'file1.monkey2
|
|
'
|
|
'
|
|
#Import "file2"
|
|
#Import "file2"
|
|
#Import "file3"
|
|
#Import "file3"
|
|
-
|
|
|
|
|
|
+
|
|
Function Something()
|
|
Function Something()
|
|
End
|
|
End
|
|
```
|
|
```
|
|
@@ -29,23 +29,23 @@ Code in any imported monkey2 file can use code in any other imported monkey2 fil
|
|
'
|
|
'
|
|
#Import "file2"
|
|
#Import "file2"
|
|
#Import "file3"
|
|
#Import "file3"
|
|
-
|
|
|
|
|
|
+
|
|
Function Func1()
|
|
Function Func1()
|
|
Func1()
|
|
Func1()
|
|
Func2()
|
|
Func2()
|
|
Func3()
|
|
Func3()
|
|
End
|
|
End
|
|
-
|
|
|
|
|
|
+
|
|
'***** file2.monkey2 *****
|
|
'***** file2.monkey2 *****
|
|
-
|
|
|
|
|
|
+
|
|
Function Func2()
|
|
Function Func2()
|
|
Func1()
|
|
Func1()
|
|
Func2()
|
|
Func2()
|
|
Func3()
|
|
Func3()
|
|
End
|
|
End
|
|
-
|
|
|
|
|
|
+
|
|
'***** file3.monkey2 *****
|
|
'***** file3.monkey2 *****
|
|
-
|
|
|
|
|
|
+
|
|
Function Func3()
|
|
Function Func3()
|
|
Func1()
|
|
Func1()
|
|
Func2()
|
|
Func2()
|
|
@@ -55,4 +55,37 @@ End
|
|
|
|
|
|
This is perfectly valid, as long as file1.monkey2 is the ‘root file’ you compile.
|
|
This is perfectly valid, as long as file1.monkey2 is the ‘root file’ you compile.
|
|
|
|
|
|
-
|
|
|
|
|
|
+You may encapsulate some code within a file by using the `Private` keyword. That code will only be accessible within the file. The `Public` keyword allows you to go back to the default public privacy level.
|
|
|
|
+
|
|
|
|
+```
|
|
|
|
+'***** file1.monkey2 *****
|
|
|
|
+'
|
|
|
|
+#Import "file2"
|
|
|
|
+
|
|
|
|
+Function Func1()
|
|
|
|
+ Func1()
|
|
|
|
+ Func2()
|
|
|
|
+ Func3() 'this call is not valid, Func3 is private to file2.monkey!
|
|
|
|
+ Func4()
|
|
|
|
+End
|
|
|
|
+
|
|
|
|
+'***** file2.monkey2 *****
|
|
|
|
+
|
|
|
|
+Function Func2()
|
|
|
|
+ Func1()
|
|
|
|
+ Func3() 'here the call is valid
|
|
|
|
+End
|
|
|
|
+
|
|
|
|
+Private 'entering private declarations
|
|
|
|
+
|
|
|
|
+Function Func3()
|
|
|
|
+ 'some statements
|
|
|
|
+End
|
|
|
|
+
|
|
|
|
+Public 'back to public declarations
|
|
|
|
+
|
|
|
|
+Function Func4()
|
|
|
|
+ 'some statements
|
|
|
|
+End
|
|
|
|
+
|
|
|
|
+```
|