Page 1 of 1

can someone explain to me what userlib is ?

Posted: Tue Dec 24, 2024 2:45 pm
by marc_256
Hi,

I see we can now [PB6.20x] create userlibs.

I'm only a designer so, :oops: :?
can someone explain to me,

- What is a userlib ?
- Where is it used ?
- Where is used for ?
- What are the benefits ?


Thanks,
marc

Re: can someone explain to me what userlib is ?

Posted: Tue Dec 24, 2024 3:11 pm
by STARGĂ…TE
marc_256 wrote: Tue Dec 24, 2024 2:45 pm - What is a userlib ?
- Where is it used ?
- Where is used for ?
- What are the benefits ?
A user library is a pre-compiled version of a bunch of procedure, like the libraries of pure basic.
You can use it in your own codes, when you want to have a faster compiling time or no use of includes.
It is similar to a Module, but already compiled.

Here is my example for additional random functions: PB 6.20 - UserLibrary - Random extension

Re: can someone explain to me what userlib is ?

Posted: Tue Dec 24, 2024 4:35 pm
by skywalk
Pros:
+ Compile time reduced by lib code amount.
+ Statically loaded instead of shipping and loading external dll.

Cons:
- You cannot debug an error within your user created lib.
- Complicated compilerifs required to allow user lib code to be used as both inline and lib. Else you have to maintain duplicate code.
- User lib code must be flat, not module based.
- All functions are loaded into memory, even if never called.
- Unsure if lib code is backward and forward compatible?
- Unsure where lib constants and structures are created?
- Sharing lib as binary opens potential threats.

Re: can someone explain to me what userlib is ?

Posted: Tue Dec 24, 2024 5:25 pm
by mk-soft
Never use third-party user libraries without source code !!!

Re: can someone explain to me what userlib is ?

Posted: Tue Dec 24, 2024 6:38 pm
by Fred
Yes source code is mandatory, a userlib must be compiled with the same PB version to work flawlessly. I will made be a check to disallow the loading of a lib not compiled with the same version to enforce that.

Re: can someone explain to me what userlib is ?

Posted: Tue Dec 24, 2024 8:19 pm
by mk-soft
Fred wrote: Tue Dec 24, 2024 6:38 pm Yes source code is mandatory, a userlib must be compiled with the same PB version to work flawlessly. I will made be a check to disallow the loading of a lib not compiled with the same version to enforce that.
But please not with every small change ...

Re: can someone explain to me what userlib is ?

Posted: Tue Dec 24, 2024 8:54 pm
by Little John
In normal PureBasic code, procedure parameters must be of a specific type. For instance, when I want to write a routine which does something with arrays, I have to write a separate procedure for each array type that I want to handle:

Code: Select all

Procedure HandleArrayI (Array foo.i(1))
EndProcedure

Procedure HandleArrayF (Array foo.f(1))
EndProcedure

Procedure HandleArrayD (Array foo.d(1))
EndProcedure

Procedure HandleArrayS (Array foo.s(1))
EndProcedure
In contrast, built-in PureBasic functions for arrays can handle arrays of any data type or at least of any basic data type.

My question is:
Can I write a user library with a procedure that can take arrays of different types as parameter, like the built-in PureBasic functions do?

Re: can someone explain to me what userlib is ?

Posted: Wed Dec 25, 2024 9:32 am
by jacdelad
mk-soft wrote: Tue Dec 24, 2024 8:19 pm
Fred wrote: Tue Dec 24, 2024 6:38 pm Yes source code is mandatory, a userlib must be compiled with the same PB version to work flawlessly. I will made be a check to disallow the loading of a lib not compiled with the same version to enforce that.
But please not with every small change ...
How about an automate regeneration process, like you put all your userlibs in a defined folder and there's an option in the ide "create userlibs", which automatically creates them for/with the desired compiler? With more than one compiler you need some version handling anyway.

Re: can someone explain to me what userlib is ?

Posted: Wed Dec 25, 2024 10:50 am
by Denis
Fred wrote: Tue Dec 24, 2024 6:38 pm Yes source code is mandatory, a userlib must be compiled with the same PB version to work flawlessly. I will made be a check to disallow the loading of a lib not compiled with the same version to enforce that.
It will be easier not to have PB lib but rather to have includefile, won't it?

I have several personnal asm PB lib i wrote a while ago, and all is correct (x86-x64 windows only).
Am I going to have to recompile everything, knowing that it's in asm ?

mk-soft wrote: Tue Dec 24, 2024 8:19 pm
Fred wrote: Tue Dec 24, 2024 6:38 pm Yes source code is mandatory, a userlib must be compiled with the same PB version to work flawlessly. I will made be a check to disallow the loading of a lib not compiled with the same version to enforce that.
But please not with every small change ...
+1

Re: can someone explain to me what userlib is ?

Posted: Thu Dec 26, 2024 12:07 am
by marc_256
WOW,
thanks for the tips and the reactions.

I learn from this, as long I use it in my own program it will be OK.

Marc

Re: can someone explain to me what userlib is ?

Posted: Thu Dec 26, 2024 10:34 am
by Bisonte
marc_256 wrote: Thu Dec 26, 2024 12:07 am WOW,
thanks for the tips and the reactions.

I learn from this, as long I use it in my own program it will be OK.

Marc
it only means: If you don't have the source, you are fixed to the current
version of the compiler as long as the author does not make updates available!

Re: can someone explain to me what userlib is ?

Posted: Thu Dec 26, 2024 11:49 am
by Caronte3D
Also... if you don't have the code, it can cause a security hole if the author is someone with malicious intentions.

Re: can someone explain to me what userlib is ?

Posted: Mon Dec 30, 2024 2:35 pm
by threedslider
*Edit : Ok I have seen userlib from PB and it is a part in PB itself so now I understand that :D

Happy coding !