Wiki improvements

Forum for discussion about the documentation project.
Post Reply
dodicat
Posts: 7976
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: Wiki improvements

Post by dodicat »

For fun.

strings.bas compile -dll

Code: Select all

'strings.bas compile with -dll switch
Enum
    up
    down
End Enum
type strings
    as string original
    as string sorted
    as byte direction
    declare constructor
    declare constructor(as string, as byte,as long,as long)
    declare function sort(as strings,as long,as long) as string
end type

constructor strings export
end constructor

constructor strings(tosort as string, dirn as byte,l as long,u as long) export
original=tosort
direction=dirn
sorted=sort(this,l,u)
end constructor

function strings.sort(ss As strings,begin As Long,Finish As Long) as string
    static as strings s:s=ss
    Dim As Long i=begin,j=finish
    Dim As ubyte x =S.original[(I+J)\2]
    While  I <= J
    if direction=down then
        While S.original[I] > X:I+=1:Wend
        While S.original[J] < X:J-=1:Wend
    else
        While S.original[I] < X:I+=1:Wend
        While S.original[J] > X:J-=1:Wend
    end if
    If I<=J Then Swap S.original[I],S.original[J]: I+=1:J-=1  
    wend
    If J > begin Then sort(S,begin,J)
    If I < Finish Then sort(S,I,Finish)
    return s.original
End function

 
testfile (in same folder as the dll)

Code: Select all


#inclib "strings"

Enum
    up
    down
End Enum

type strings
    as string original
    as string sorted
    as byte direction
    declare constructor
    declare constructor(as string, as byte,as long,as long)
end type


dim as string f="FreeBASIC example of dynamic library file for exported constructors (.dll)"

dim as strings g


g=type(f,up,0,len(f)-1)
print g.original
print g.sorted
print
g=type(f,down,0,len(f)-1)
print g.original
print g.sorted
print
g=type("0123456789",down,0,9)
print g.sorted
print "Done"


sleep
dodicat
Posts: 7976
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: Wiki improvements

Post by dodicat »

Here is the .def file for strings.dll (above post)
. . .
;
; Definition file of strings.dll
; Automatic generated by gendef
; written by Kai Tietz 2008
;
LIBRARY "strings.dll"
EXPORTS
_ZN7STRINGSC1ER8FBSTRINGaii
_ZN7STRINGSC1Ev
. . .
So it looks like you can convert constructors to functions (OOP to procedural)

Code: Select all

#inclib "strings"

Enum
    up
    down
End Enum

type udt
    as string original
    as string sorted
    as byte direction
end type


declare function sort cdecl alias"_ZN7STRINGSC1ER8FBSTRINGaii"(as string, as byte=up,as long=0,as long=0) as udt


dim as string f="FreeBASIC example of dynamic library file for exported constructors (.dll)"



print f
print sort(f,up,0,len(f)-1).sorted
print sort(f,down,0,len(f)-1).sorted
print sort(f).original
print sort("0123456789",down,0,9).sorted
print "Done"


sleep 
fxm
Moderator
Posts: 12081
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Wiki improvements

Post by fxm »

D.J.Peters wrote:A short OOP example for static and shared lib's would be a nice to have :-)
fxm wrote:For example:
viewtopic.php?p=236630#p236630

Perhaps a similar example could be added in the 'Static Libraries' or/and 'Shared Libraries (DLLs)' pages of the 'Programmer's Guide' ?
Usage proposal for Type/Class in a library, showing that exhaustive declarations in the user code are mandatory for overload operators (otherwise the prebuilt-in Len operator is called and applied on the object variable providing the length of its member data):

Code: Select all

'' header file: 'varZstring.bi'

Type varZstring Extends Zstring
    Public:
        Declare Constructor (Byref z As Const Zstring)
        Declare Operator Cast () Byref As Zstring
        Declare Operator Let (Byref z As Const Zstring)
        Declare Property allocated () As Integer
        Declare Destructor ()
    Private:
        Dim As Zstring Ptr _p
        Dim As Uinteger _allocated
End Type

Declare Operator Len (Byref v As varZstring) As Integer  '' mandatory for the user code to call
                                                         ''    the overload Len operator and
                                                         ''    not the prebuilt-in Len operator

Code: Select all

'' library module: 'varZstring.bas'

#include "varZstring.bi"

Constructor varZstring (Byref z As Const Zstring)
    If This._p <> 0 Then
        Deallocate(This._p)
    End If
    This._allocated = Len(z) + 1
    This._p = Callocate(This._allocated, Sizeof(Zstring))
    *This._p = z
End Constructor

Operator varZstring.Cast () Byref As Zstring
    Return *This._p
End Operator

Operator varZstring.Let (Byref z As Const Zstring)
    If This._allocated < Len(z) + 1 Then
    Deallocate(This._p)
    This._allocated = Len(z) + 1
    This._p = Callocate(This._allocated, Sizeof(Zstring))
  End If
  *This._p = z
End Operator

Property varZstring.allocated () As Integer
    Return This._allocated
End Property

Destructor varZstring ()
    Deallocate(This._p)
    This._p = 0
End Destructor

Operator Len (Byref v As varZstring) As Integer
    Return Len(Type<String>(v))  '' found nothing better than this
End Operator                     ''     (or: 'Return Len(Str(v))')

Code: Select all

'' test program: 'varZstringTest.bas'

#include "varZstring.bi"  '' must contain also the overload Len operator declaration,
                          ''    otherwise the prebuilt-in Len operator is called and applied
                          ''    on the object variable (providing the length of its member data)
#inclib "varZstring"

Print "VARIABLE",,, "|     LEN|  SIZEOF|"
Print "------------------------------------------|--------|--------|"

Dim As varZstring v = "FreeBASIC"  '' adjusts memory allocation to minimum
Print "varZstring v:", "'" & v & "'",, "|"; Using "########|"; Len(v); v.allocated

Dim As Zstring * 256 z
z = v
Print "Zstring    z:", "'" & z & "'",, "|"; Using "########|"; Len(z); Sizeof(z)

v = z & " & SourceForge"  '' only increases memory allocation if necessazy
Print "varZstring v:", "'" & v & "'", "|"; Using "########|"; Len(v); v.allocated

v = z & " & Wiki" '' only increases memory allocation if necessazy
Print "varZstring v:", "'" & v & "'", "|"; Using "########|"; Len(v); v.allocated

v.Constructor(v)  '' readjusts memory allocation to minimum
Print "varZstring v:", "'" & v & "'", "|"; Using "########|"; Len(v); v.allocated

Sleep
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Re: Wiki improvements

Post by D.J.Peters »

I self know how to use oop in lib's but I was thinking would be a nice have "Wiki improvment"
to add this missing oop library topic to the wiki = help file.

My last FB OOP library are 31 classes = *.bi files and ~300 constructors,methods,functions,properties in 245 *.bas files !

Joshy
fxm
Moderator
Posts: 12081
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Wiki improvements

Post by fxm »

Done (according to my post above):
ProPgStaticLibraries → fxm [added advanced example of OOP static library]
badidea
Posts: 2586
Joined: May 24, 2007 22:10
Location: The Netherlands

Re: Wiki improvements

Post by badidea »

fxm wrote:The simplest would it not be to put one single constant link to the topic "News" of the forum:
News forum
and just add a comment saying to refer to the "Documentation" paragraph of the post for the version considered?
I gave the page (https://freebasic.net/wiki/wikka.php?wa ... iDownloads) a makeover.

For some reason, this wiki software wants to make links of "SourceForge", "KchmViewer" and "WikkaWiki". I dont know why.
Ah, CamelCase. Fixed now.
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Re: Wiki improvements

Post by D.J.Peters »

The description of RGB(), RGBA() macros are a little bit confused.

For example: The COLOR command you can read:

Code: Select all

Declare Function Color ( ByVal foreground As ULong , ByVal background As ULong ) As ULong
This looks right for me.
Same for the parameter color: pset, line, circle, paint, point etc.

But the description of RGB and RGBA and it''is examples used INTEGER / CUINT() !

Should be ULONG / CULNG() on 32/64-bit right ?

Joshy

edit: and a macro for 16 bit color are missed also.

Code: Select all

#define RGB16(r,g,b) ((((r) shr 3) shl 11) or (((g) shr 2) shl 5) or ((b) shr 3))
fxm
Moderator
Posts: 12081
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Wiki improvements

Post by fxm »

Do you work with the latest version of the documentation (or with the wiki)?
paul doe recently updated the 2 pages (less than a month ago).

Otherwise, specify your remark better.
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Re: Wiki improvements

Post by D.J.Peters »

Sorry looks like my compiled help file was out of date and firefox showed me the old wiki from cache.

After a site refresh the wiki content changed !

Joshy
fxm
Moderator
Posts: 12081
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Wiki improvements

Post by fxm »

fxm wrote:If you search a good resolution to make for the New Year 2020:
fxm wrote:
fxm wrote:If someone else could fill in the last two remaining pages "Graphics / External Graphics File Formats" and "Making Binaries / Executables" (it's outside of my skills), it would be nice to finally have a complete Programmer's Guide.
coderJeff wrote:- For executables topic: I think this should describe the components: (object modules and/or import library and/or library) => executable.
- For external graphics file formats topic: what is supported by BLOAD & BSAVE. To be cross platform, the QB/BMP formats that can be loaded/saved are hard coded in the rtlib. So, this is will be a description of what is specifically supported by the rtlib.
No volunteers for these 2 pages?
Still, it seems to me that there are skills on these two topics on the forum and that they could (by taking a little bit of their personal time) easily produce at worst a draft that I could then incorporate into the Programmer's Guide.
I wrote a beginning of the page 'Programmer's Guide / Making Binaries / Executables'.
A volunteer to improve / complete ?
Imortis
Moderator
Posts: 1923
Joined: Jun 02, 2005 15:10
Location: USA
Contact:

Re: Wiki improvements

Post by Imortis »

I can take a look at the Executables page. I am not sure when I will get to it, but I am pretty sure I can fill out the needed info.
fxm
Moderator
Posts: 12081
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Wiki improvements

Post by fxm »

Thanks in advance.
fxm
Moderator
Posts: 12081
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Wiki improvements

Post by fxm »

Added a page in documentation: Programmer's Guide / Other Topics / Dynamic memory management in FreeBASIC
ProPgDynamicMemory → fxm [new page created]
fxm
Moderator
Posts: 12081
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Wiki improvements

Post by fxm »

Added a page in documentation: Programmer's Guide / User Defined Types / Variable-length member data
ProPgVariableLengthData → fxm [new page created]
fxm
Moderator
Posts: 12081
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Wiki improvements

Post by fxm »

fxm wrote: I wrote a beginning of the page 'Programmer's Guide / Making Binaries / Executables'.
A volunteer to improve / complete ?
Imortis wrote:I can take a look at the Executables page. I am not sure when I will get to it, but I am pretty sure I can fill out the needed info.
Maybe a little free time during the summer?
Post Reply