Skip to content

Commit 1e99fab

Browse files
committed
fbdocs: update examples/manual from wiki
1 parent 5ffd463 commit 1e99fab

22 files changed

+171
-10
lines changed

examples/manual/gfx/cls-memset.bas

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
'' --------
88

99
Dim scrbuf As Byte Ptr, scrsize As Integer
10-
Dim As Integer scrhei, scrpitch
10+
Dim As Long scrhei, scrpitch
1111
Dim As Integer r = 0, dr = 1
1212

1313
ScreenRes 640, 480, 8

examples/manual/gfx/imageconvertrow.bas

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ Sleep
4848

4949
'' copy the image data into a 32-bit image
5050
Dim As Byte Ptr p8, p32
51-
Dim As Integer pitch8, pitch32
51+
Dim As Long pitch8, pitch32
5252

5353
#ifndef ImageInfo '' older versions of FB don't have the ImageInfo feature
5454
#define GETPITCH(img_) IIf(img_->Type=PUT_HEADER_NEW,img_->pitch,img_->old.width*img_->old.bpp)

examples/manual/gfx/imageinfo.bas

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
ScreenRes 320, 200, 32
1111
Dim image As Any Ptr = ImageCreate( 64, 64 )
1212

13-
Dim pitch As Integer
13+
Dim pitch As Long
1414
Dim pixels As Any Ptr
1515

1616
'' Get enough information to iterate through the pixel data.

examples/manual/gfx/screenptr.bas

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ ScreenLock()
3333
Dim As UByte Ptr pixel = buffer + (y * pitch) + (x * bypp)
3434

3535

36-
'' Set the pixel color to 10 (light green).
36+
'' Set the center pixel color to 10 (light green).
3737
*pixel = 10
3838

3939
'' Unlock the screen.

examples/manual/math/randomize.bas

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ Randomize , 1
1313
For i As Integer = 1 To 10
1414
Print Rnd
1515
Next
16+

examples/manual/memory/callocate.bas

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,4 @@ Next
2121

2222
' Free the memory.
2323
Deallocate(p)
24+

examples/manual/memory/deallocate.bas

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,4 @@ End Sub
1919

2020
DeallocateExample1()
2121
End 0
22+

examples/manual/memory/deallocate2.bas

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,4 @@ End Sub
2727

2828
DeallocateExample2()
2929
End 0
30+

examples/manual/memory/deallocate3.bas

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,4 @@ End Sub
2828

2929
DeallocateExample3()
3030
End 0
31+

examples/manual/memory/reallocate.bas

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,4 @@ Else '' Reallocate failed, memory unchanged
4343
End If
4444

4545
Deallocate a ' Clean up
46+

examples/manual/procs/thicall.bas

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
'' examples/manual/procs/thicall.bas
2+
''
3+
'' NOTICE: This file is part of the FreeBASIC Compiler package and can't
4+
'' be included in other distributions without authorization.
5+
''
6+
'' See Also: https://www.freebasic.net/wiki/wikka.php?wakka=KeyPgThicsall
7+
'' --------
8+
9+
'' __thiscall only makes sense on windows 32-bit
10+
#if defined(__FB_WIN32__) And Not defined(__FB_64BIT__)
11+
#define thiscall __Thiscall
12+
#else
13+
#define thiscall
14+
#endif
15+
16+
Extern "c++"
17+
Type UDT
18+
value As Long
19+
'' fbc doesn't automatically add the __thiscall calling convention
20+
'' therefore, currently needs to be explicitly given where needed
21+
Declare Constructor thiscall ()
22+
Declare Destructor thiscall ()
23+
Declare Sub someproc thiscall ()
24+
'' etc
25+
End Type
26+
End Extern

examples/manual/proguide/procptrs/alias.bas

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,4 @@ Function DoOperation (a As Integer, b As Integer, op As operation) As Integer
1616
End Function
1717

1818
Print "3 + 4 = " & DoOperation(3, 4, @Add)
19+

examples/manual/proguide/procptrs/calling.bas

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@
1010
#include Once "pfunc.bi"
1111

1212
Print "3 + 4 = " & pFunc(3, 4)
13+

examples/manual/proguide/procptrs/dimptr.bas

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@
88

99
' declares a pointer to sub procedure that takes no arguments
1010
Dim pointerToProcedure As Sub
11+

examples/manual/proguide/procptrs/method-ptr.bas

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,4 @@ p = @T.test
3434
Dim As T obj
3535

3636
Print p(obj, 69) '' prints 489
37+

examples/manual/proguide/procptrs/passing.bas

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@ Function DoOperation (a As Integer, b As Integer, operation As Function (As Inte
1414
End Function
1515

1616
Print "3 + 4 = " & DoOperation(3, 4, @Add)
17+

examples/manual/proguide/procptrs/pfunc.bi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ Function Add (a As Integer, b As Integer) As Integer
1313
End Function
1414

1515
Dim pFunc As Function (As Integer, As Integer) As Integer = @Add
16+

examples/manual/proguide/procptrs/procptrs.bas

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,4 @@ While (*op <> 0)
3333
Wend
3434

3535
Print "Value of 'i' after all operations performed: " & i
36+
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
'' examples/manual/proguide/procptrs/typing-rule1.bas
2+
''
3+
'' NOTICE: This file is part of the FreeBASIC Compiler package and can't
4+
'' be included in other distributions without authorization.
5+
''
6+
'' See Also: https://www.freebasic.net/wiki/wikka.php?wakka=ProPgProcedurePointers
7+
'' --------
8+
9+
'Example of assigning to a function pointer a function with:
10+
' - a contravariant parameter by pointer,
11+
' - and a covariant result by pointer.
12+
13+
Type A
14+
Dim As Integer I
15+
Declare Constructor ()
16+
Declare Destructor ()
17+
End Type
18+
Constructor A ()
19+
Print " A instance constructed", @This
20+
End Constructor
21+
Destructor A ()
22+
Print " A instance destroyed", @This
23+
End Destructor
24+
25+
Type B Extends A
26+
Dim As Integer J
27+
Declare Constructor ()
28+
Declare Constructor (ByRef a0 As A)
29+
Declare Destructor ()
30+
End Type
31+
Constructor B ()
32+
Print " B instance constructed", @This
33+
End Constructor
34+
Constructor B (ByRef a0 As A)
35+
Cast(A, This) = a0
36+
Print " B instance constructed", @This
37+
End Constructor
38+
Destructor B ()
39+
Print " B instance destroyed", @This
40+
End Destructor
41+
42+
Function f (ByVal pa0 As A Ptr) As B Ptr
43+
Return New B(*pa0)
44+
End Function
45+
46+
Scope
47+
Dim As Function (ByVal As B Ptr) As A Ptr pf = @f
48+
Print "'Scope : Dim As B b0':"
49+
Dim As B b0
50+
Print
51+
Print "'Dim As A Ptr pab = pf(@b0)':"
52+
Dim As A Ptr pab = pf(@b0)
53+
Print
54+
Print "'Delete CPtr(B Ptr, pab)':"
55+
Delete CPtr(B Ptr, pab)
56+
Print
57+
Print "'End Scope':"
58+
End Scope
59+
60+
Sleep
61+
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
'' examples/manual/proguide/procptrs/typing-rule2.bas
2+
''
3+
'' NOTICE: This file is part of the FreeBASIC Compiler package and can't
4+
'' be included in other distributions without authorization.
5+
''
6+
'' See Also: https://www.freebasic.net/wiki/wikka.php?wakka=ProPgProcedurePointers
7+
'' --------
8+
9+
'Example of assigning to a function pointer a function with:
10+
' - a contravariant parameter by reference,
11+
' - and a covariant result by reference.
12+
13+
Type A Extends Object
14+
Dim As Integer I
15+
Declare Constructor ()
16+
Declare Virtual Destructor ()
17+
End Type
18+
Constructor A ()
19+
Print " A instance constructed", @This
20+
End Constructor
21+
Destructor A ()
22+
Print " A instance destroyed", @This
23+
End Destructor
24+
25+
Type B Extends A
26+
Dim As Integer J
27+
Declare Constructor ()
28+
Declare Constructor (ByRef a0 As A)
29+
Declare Virtual Destructor ()
30+
End Type
31+
Constructor B ()
32+
Print " B instance constructed", @This
33+
End Constructor
34+
Constructor B (ByRef a0 As A)
35+
Cast(A, This) = a0
36+
Print " B instance constructed", @This
37+
End Constructor
38+
Destructor B ()
39+
Print " B instance destroyed", @This
40+
End Destructor
41+
42+
Function f (ByRef a0 As A) ByRef As B
43+
Return *New B(a0)
44+
End Function
45+
46+
Scope
47+
Dim As Function (ByRef As B) ByRef As A pf = @f
48+
Print "'Scope : Dim As B b0':"
49+
Dim As B b0
50+
Print
51+
Print "'Dim Byref As A rab = pf(b0)':"
52+
Dim ByRef As A rab = pf(b0)
53+
Print
54+
Print "'Delete @rab':"
55+
Delete @rab
56+
Print
57+
Print "'End Scope':"
58+
End Scope
59+
60+
Sleep
61+

examples/manual/proguide/shared-lib/load.bas

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
'' Note we specify just "mydll" as library file name; this is to ensure
1717
'' compatibility between Windows and Linux, where a dynamic library
1818
'' has different file name and extension.
19-
Dim As Any Ptr library = DyLibLoad( "mydll" )
20-
If( library = 0 ) Then
19+
Dim As Any Ptr libhandle = DyLibLoad( "mydll" )
20+
If( libhandle = 0 ) Then
2121
Print "Failed to load the mydll dynamic library, aborting program..."
2222
End 1
2323
End If
@@ -26,7 +26,7 @@ End If
2626
'' the address has been found. Note: It must have the same calling
2727
'' convention and parameters.
2828
Dim AddNumbers As Function( ByVal As Integer, ByVal As Integer ) As Integer
29-
AddNumbers = DyLibSymbol( library, "AddNumbers" )
29+
AddNumbers = DyLibSymbol( libhandle, "AddNumbers" )
3030
If( AddNumbers = 0 ) Then
3131
Print "Could not retrieve the AddNumbers() function's address from the mydll library, aborting program..."
3232
End 1
@@ -45,5 +45,5 @@ Print x; " +"; y; " ="; AddNumbers( x, y )
4545
'' Remember that once you unload a previously loaded library, all the symbols
4646
'' you got from it via dylibsymbol will become invalid, and accessing them
4747
'' will cause the application to crash.
48-
DyLibFree( library )
48+
DyLibFree( libhandle )
4949

examples/manual/proguide/udt/polymorphism-graph.bas

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,14 @@ End Property
4646

4747
Static Function GraphicPoint.xValid (ByVal x0 As Integer) As Integer
4848
If ScreenPtr = 0 Then Return 0 '' no open graphic window
49-
Dim As Integer w
49+
Dim As Long w
5050
ScreenInfo(w)
5151
If x0 >= 0 And x0 <= w - 1 Then Return -1 Else Return 0
5252
End Function
5353

5454
Static Function GraphicPoint.yValid (ByVal y0 As Integer) As Integer
5555
If ScreenPtr = 0 Then Return 0 '' no open graphic window
56-
Dim As Integer h
56+
Dim As Long h
5757
ScreenInfo( , h)
5858
If y0 >= 0 And y0 <= h - 1 Then Return -1 Else Return 0
5959
End Function

0 commit comments

Comments
 (0)