MLF : Make Lib Factory (For PureBasic)

Share your advanced PureBasic knowledge/code with the community.
User avatar
falsam
Enthusiast
Enthusiast
Posts: 632
Joined: Wed Sep 21, 2011 9:11 am
Location: France
Contact:

MLF : Make Lib Factory (For PureBasic)

Post by falsam »

[PB 5.60 +] [x86] [x64] [Mode Admin]

Still as a young project, MLF (Make Lib Factory) is an utility for creating user libraries for the PureBasic language.

Image

■ How it works
MLF provides a link between three utilities that you will find in the PureBasic installation folder.
- pbcompiler. exe with the /COMMENTED option for creating the ASM file
- fasm. exe for creating the OBJ file
- polib.exe for creating the LIB file
- LibraryMaker. exe to create the user library from the previous OBJ/LIB file and a description file that will be created by MLF.

  The code processing is as follows:
  -List the dependencies of the procedures.
  -List public procedures. (ProcedureDLL).
  -For each procedure, define the type (String, Long,...).
  -For each parameter, define the type (String, long,...).
  -Extract the help associated with each ProcedureDLL.

GitHub
https://github.com/MLF4PB/MLF-Dev

Wiki
https://github.com/MLF4PB/MLF-Dev/wiki

Direct download
https://github.com/MLF4PB/MLF-Dev/archive/master.zip

Functionality.
- Create resident
- Create users libs
- Interface (Example InterfaceLib.pb)
- API (Example GetCPUNameLib.pb)
- Pass a list in parameters (Examples ListLib1.pb & ListLib2.pb)
- AttachProcess() and DetachProcess() (Example ProcessLib.pb)
  Wiki : https://github.com/MLF4PB/MLF-Dev/wiki/ ... ic-Trigger.

- Add optional parameters (Example : StrMaskLib.pb)

■ Restrictions.
- No map in parameters.
- No array in parameters.

The ASM, DESC, Log files are created in the MLF folder. With the next version, I think I'm going to create some pre-compile folders.

Thanks to Bisonte and Mestnyi for their contributions to the translation (German and Russian).


Good tests :wink:
Last edited by falsam on Fri Oct 27, 2017 1:18 pm, edited 3 times in total.

➽ Windows 11 64-bit - PB 6.21 x64 - AMD Ryzen 7 - NVIDIA GeForce GTX 1650 Ti

Sorry for my bad english and the Dunning–Kruger effect 🤪
GPI
PureBasic Expert
PureBasic Expert
Posts: 1394
Joined: Fri Apr 25, 2003 6:41 pm

Re: MLF : Make Lib Factory (For PureBasic)

Post by GPI »

When you parse the "ASM"-File with this

Code: Select all

    ForEach ASMExtract()
      ASMContent = ReplaceString(ASMContent, ASMExtract()\ASMName, "PB_" + ASMExtract()\Name)   
    Next
and you have more than 11 procedures. Let _procedure1 in the list with PB-Procedure-Name "DoSomething" and _procedure10 with "somethingelse"

it will rename "_Procedure10" in "DoSomething0" (expect "somethingelse").

You create the res-file by bypass the complete PB-Source-File with all Procedures and so on? This could be a Problem. A Prototype cause a invalid res, which crash the pbcompiler instant.
Also you should pass the compiler a "/IGNORERESIDENT"-flag with the res-file-name to prevent conflicts.

You can reduce the PBCompiler-output with /QUITE to a minimum.

Also your code doesn't handle compilerifs, macros, includefiles for more complex libraries.
I solved this problem with the creation of a "/PREPROCESS"-File. Then you have a easy to scan file with no compilerifs, includefiles, no macros (ok, the macro-definition is in the file and should be removed, because they can produce errors) and only one statment in on line. Only problem: all comments are gone.

I solved this Problem with constants (and a res file):

Code: Select all

Macro __c34__
  "
EndMacro
Macro PreCompilerCommand(cmd)
  #__PreCompilerCommand__AutoGenerated#MacroExpandedCount=__c34__#cmd#__c34__
EndMacro
Macro ResidentExport
  PreCompilerCommand(ExportStart)
EndMacro
Macro EndResidentExport
  PreCompilerCommand(ExportEnd)
EndMacro
Macro ProcedureDLLDescription(Proc,desc)
  PreCompilerCommand(Description:Proc;desc)
EndMacro
This will produce many constants like "#__PreCompilerCommand__...="Command"" - i scan for a constant with beginn with "__PreCompilerCommand__" to get the command. PB will remove in the final execute every Constant, which is't used. It should be gone also in the asm-file (doesn't tested). You can also define a block with the resident-Data (ResidentExport and EndResidentExport) to allow "private" structures and so on.

But does i understand your Code right: You simple use the asm-output, rename the procedure-labels, mark them as public and create a obj-file without any future changings?
initfunction and endfunction should be added, if present - right?

edit: Why do i always read "milf"?
User avatar
falsam
Enthusiast
Enthusiast
Posts: 632
Joined: Wed Sep 21, 2011 9:11 am
Location: France
Contact:

Re: MLF : Make Lib Factory (For PureBasic)

Post by falsam »

GPI wrote:You simple use the asm-output, rename the procedure-labels, mark them as public and create a obj-file without any future changings?
yes The ASM file is the parsing source. I only read the PureBasic file to extract help from each function
GPI wrote:initfunction and endfunction should be added, if present - right?
I hope I understand your question. the answer is no. Look at this example

Code: Select all

; This function is called automatically when program starts
ProcedureDLL AttachProcess()
  MessageRequester("Info", "This is our init function")
EndProcedure

;This function is called automatically when program ends
ProcedureDLL DetachProcess()
  MessageRequester("Information", "This is our End function")
EndProcedure

;Your public procedures
ProcedureDLL Add(x, y) ;- Simple Add 
  ProcedureReturn x+y
EndProcedure

ProcedureDLL Sub(x, y) ;- Simple Sub
  ProcedureReturn x-y
EndProcedure

;Test
;Call AttachProcess()
; Debug "Start" 
; Delay(2000)
; Debug Add(2, 3)
; Delay(2000)
; Debug Sub(20, 10)
; Delay(2000)
; Debug "fin"
; Delay(2000)
;Call DetachProcess()
initfunction and endfunction will be automatically placed in the DESC file.

Wiki : https://github.com/MLF4PB/MLF-Dev/wiki/ ... ic-Trigger.

Thank you for your interest in MLF

➽ Windows 11 64-bit - PB 6.21 x64 - AMD Ryzen 7 - NVIDIA GeForce GTX 1650 Ti

Sorry for my bad english and the Dunning–Kruger effect 🤪
User avatar
falsam
Enthusiast
Enthusiast
Posts: 632
Joined: Wed Sep 21, 2011 9:11 am
Location: France
Contact:

Re: MLF : Make Lib Factory (For PureBasic)

Post by falsam »


➽ Windows 11 64-bit - PB 6.21 x64 - AMD Ryzen 7 - NVIDIA GeForce GTX 1650 Ti

Sorry for my bad english and the Dunning–Kruger effect 🤪
User avatar
gurj
Enthusiast
Enthusiast
Posts: 693
Joined: Thu Jan 22, 2009 3:48 am
Location: china
Contact:

Re: MLF : Make Lib Factory (For PureBasic)

Post by gurj »

thanks you!
falsam!
my pb for chinese:
http://ataorj.ys168.com
User avatar
gurj
Enthusiast
Enthusiast
Posts: 693
Joined: Thu Jan 22, 2009 3:48 am
Location: china
Contact:

Re: MLF : Make Lib Factory (For PureBasic)

Post by gurj »

1 not support ProcedureDLL.q
ProcedureDLL.q Add(x.q, y.q)
ProcedureReturn x + y
EndProcedure

2 name not support Add1(x, y)
ProcedureDLL Add1(x, y)
ProcedureReturn x + y
EndProcedure

3 ok:
ProcedureDLL Add(x, y)
ProcedureReturn x + y
EndProcedure

4 purebasic.ico should use Grays color, for no confusion and pb' s IDE
my pb for chinese:
http://ataorj.ys168.com
User avatar
Bisonte
Addict
Addict
Posts: 1305
Joined: Tue Oct 09, 2007 2:15 am

Re: MLF : Make Lib Factory (For PureBasic)

Post by Bisonte »

2 name not support Add1(x, y)
ProcedureDLL Add1(x, y)
ProcedureReturn x + y
EndProcedure
This is a special behaviour to handle optional parameters...

If you have a procedure with 2 optional parameters you have to make it like this....

Code: Select all

Procedure Intern_Add(x, y, a = 1, b = 2)
ProcedureReturn x+y+a+b
EndProcedure

ProcedureDLL Add(x, y) ; Only the First 2 params
ProcedureReturn Intern_Add(x, y)
Endprocedure
ProcedureDLL Add2(x, y, a) ; now with 3 params
ProcedureReturn Intern_Add(x, y, a)
Endprocedure
ProcedureDLL Add3(x, y, a, b) ; now all params
ProcedureReturn Intern_Add(x, y, a, b)
Endprocedure
Then you have one Function with 2 optional parameter.

Code: Select all

Add(x, y [,a] [,b])
PureBasic 6.21 (Windows x64) | Windows 11 Pro | AsRock B850 Steel Legend Wifi | R7 9800x3D | 64GB RAM | RTX 5080 | ThermaltakeView 270 TG ARGB | build by vannicom​​
English is not my native language... (I often use DeepL.)
User avatar
gurj
Enthusiast
Enthusiast
Posts: 693
Joined: Thu Jan 22, 2009 3:48 am
Location: china
Contact:

Re: MLF : Make Lib Factory (For PureBasic)

Post by gurj »

2 name not support Add1(x, y)
now not support use '1' in name
my pb for chinese:
http://ataorj.ys168.com
User avatar
falsam
Enthusiast
Enthusiast
Posts: 632
Joined: Wed Sep 21, 2011 9:11 am
Location: France
Contact:

Re: MLF : Make Lib Factory (For PureBasic)

Post by falsam »

Hello gurj

Thank for your feedback.
gurj wrote:1 not support ProcedureDLL.q
Tracking Ticket TD011
:arrow: https://github.com/MLF4PB/MLF-Dev/issues/4
name not support Add1(x, y)
Bisonte gave the right explanations. It's a PureBasic convention explained by Fred.

Look at the Readme. txt help file in the SDK folder of your PureBasic installation.
2. Examples of variable parameters
- - - - - - - - - - - - - - - -

2.1 One, two or tree parameters

CustomBox, String, [Long], [Long], (Title$ [, Flags [, Hidden]]) - My Custom box
Long

Now, you have to create 3 PB functions, named like this:
PB_CustomBox (char *String)
PB_CustomBox2(char *String, Long)
PB_CustomBox3(char *String, Long, Long)
and the MLF Wiki
:arrow: https://github.com/MLF4PB/MLF-Dev/wiki/ ... -parameter.
gurj wrote:purebasic.ico should use Grays color, for no confusion and pb' s IDE
Done for next version.

➽ Windows 11 64-bit - PB 6.21 x64 - AMD Ryzen 7 - NVIDIA GeForce GTX 1650 Ti

Sorry for my bad english and the Dunning–Kruger effect 🤪
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4946
Joined: Sun Apr 12, 2009 6:27 am

Re: MLF : Make Lib Factory (For PureBasic)

Post by RASHAD »

While I never used any user lib and I will not do it in the future but I like the good idea

Thanks falsam
Egypt my love
User avatar
Lunasole
Addict
Addict
Posts: 1091
Joined: Mon Oct 26, 2015 2:55 am
Location: UA
Contact:

Re: MLF : Make Lib Factory (For PureBasic)

Post by Lunasole »

Looks very interesting. Time ago I though about making some user libs (instead of different templates, etc), should try your stuff.

Lookin on it now I had small idea - maybe you can make automatically generated descriptions, like using inline comments for this:

Code: Select all

ProcedureDLL Test() ; this comment will be procedure description used in resident
"W̷i̷s̷h̷i̷n̷g o̷n a s̷t̷a̷r"
User avatar
falsam
Enthusiast
Enthusiast
Posts: 632
Joined: Wed Sep 21, 2011 9:11 am
Location: France
Contact:

Re: MLF : Make Lib Factory (For PureBasic)

Post by falsam »

@RASHAD : I rarely use user libraries. Many libraries for PureBasic don't work because the creators are no longer there to maintain the codes.

But sometimes it's necessary for some includes that I use all the time. For tests it is easier to have a library than to make a copy of the include to perform a test.

A few days ago, I provided a library create with MLL, but also gives the code because I am not eternal.

@Lunasole : That's a very good idea. But it's already coded. You will not get your tracking ticket :wink:
https://github.com/MLF4PB/MLF-Dev/wiki/ ... procedures.

Thank you for your feedback.

➽ Windows 11 64-bit - PB 6.21 x64 - AMD Ryzen 7 - NVIDIA GeForce GTX 1650 Ti

Sorry for my bad english and the Dunning–Kruger effect 🤪
User avatar
falsam
Enthusiast
Enthusiast
Posts: 632
Joined: Wed Sep 21, 2011 9:11 am
Location: France
Contact:

Re: MLF : Make Lib Factory (For PureBasic)

Post by falsam »

New version 1.34
- Add : Alert message when a resident exists.
- Add : Grays color icon :wink:
- BugFix : ProcedureDLL.q is solved

:arrow: https://github.com/MLF4PB/MLF-Dev/archive/master.zip

➽ Windows 11 64-bit - PB 6.21 x64 - AMD Ryzen 7 - NVIDIA GeForce GTX 1650 Ti

Sorry for my bad english and the Dunning–Kruger effect 🤪
User avatar
gurj
Enthusiast
Enthusiast
Posts: 693
Joined: Thu Jan 22, 2009 3:48 am
Location: china
Contact:

Re: MLF : Make Lib Factory (For PureBasic)

Post by gurj »

has a lib MathBigInteger,not true work when pb>v4.0
so hope has their codes....
my pb for chinese:
http://ataorj.ys168.com
User avatar
falsam
Enthusiast
Enthusiast
Posts: 632
Joined: Wed Sep 21, 2011 9:11 am
Location: France
Contact:

Re: MLF : Make Lib Factory (For PureBasic)

Post by falsam »

I need your help.

I create a userlib with this code

Code: Select all

ProcedureDLL.s Dummy()
  Protected Buffer.s = "bug"
  ProcedureReturn Buffer
EndProcedure
no problem the userlib is created. But if I test this userlib with this code

Code: Select all

Debug "no " + Dummy()
the debug returns
bug
instead of
no bug

➽ Windows 11 64-bit - PB 6.21 x64 - AMD Ryzen 7 - NVIDIA GeForce GTX 1650 Ti

Sorry for my bad english and the Dunning–Kruger effect 🤪
Post Reply