Page 1 of 4

MLF : Make Lib Factory (For PureBasic)

Posted: Thu Oct 05, 2017 3:36 am
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:

Re: MLF : Make Lib Factory (For PureBasic)

Posted: Thu Oct 05, 2017 10:22 am
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"?

Re: MLF : Make Lib Factory (For PureBasic)

Posted: Thu Oct 05, 2017 11:26 am
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

Re: MLF : Make Lib Factory (For PureBasic)

Posted: Thu Oct 05, 2017 11:43 am
by falsam

Re: MLF : Make Lib Factory (For PureBasic)

Posted: Sat Oct 07, 2017 8:02 am
by gurj
thanks you!
falsam!

Re: MLF : Make Lib Factory (For PureBasic)

Posted: Sat Oct 07, 2017 12:57 pm
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

Re: MLF : Make Lib Factory (For PureBasic)

Posted: Sat Oct 07, 2017 1:35 pm
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])

Re: MLF : Make Lib Factory (For PureBasic)

Posted: Sat Oct 07, 2017 2:06 pm
by gurj
2 name not support Add1(x, y)
now not support use '1' in name

Re: MLF : Make Lib Factory (For PureBasic)

Posted: Sat Oct 07, 2017 2:27 pm
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.

Re: MLF : Make Lib Factory (For PureBasic)

Posted: Sat Oct 07, 2017 2:58 pm
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

Re: MLF : Make Lib Factory (For PureBasic)

Posted: Sat Oct 07, 2017 4:49 pm
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

Re: MLF : Make Lib Factory (For PureBasic)

Posted: Sat Oct 07, 2017 7:13 pm
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.

Re: MLF : Make Lib Factory (For PureBasic)

Posted: Sat Oct 07, 2017 10:49 pm
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

Re: MLF : Make Lib Factory (For PureBasic)

Posted: Sun Oct 08, 2017 12:15 am
by gurj
has a lib MathBigInteger,not true work when pb>v4.0
so hope has their codes....

Re: MLF : Make Lib Factory (For PureBasic)

Posted: Tue Oct 10, 2017 7:26 pm
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