[Gambas-user] can i specify a path to my modules or libs please how?

Tobias Boege taboege at gmail.com
Tue Apr 17 21:46:21 CEST 2018


On Tue, 17 Apr 2018, PICCORO McKAY Lenz wrote:
> 2018-04-17 12:24 GMT-04:00 Tobias Boege <taboege at gmail.com>:
> 
> > On Tue, 17 Apr 2018, PICCORO McKAY Lenz wrote:
> > > i want to made my ow daemon and need to load/use others dinamically made
> > > modules/programs inside that deamon
> > >
> > > how can i set that from the code? the library path or module?
> > >
> >
> > I don't know if there is a good way to do this now, but I'll tell you
> > how I did this three years ago. It's not for the faint of heart, but
> > up to the occasional svn/git merge conflict, it has been working here.
> >
> > About the scope: In some projects, I wanted to allow plugins written
> > in Gambas, which the user can store in standalone text files or .tar.gz
> > source archives somewhere under $HOME/.config. These can be loaded
> > dynamically and interact with the main program through a monolithic
> > Context object which is passed to the plugin constructor.
> >
> > First you need to enable loading of components by absolute paths.
> > I attach a patch which should apply to git master, then you have to
> > recompile Gambas. IIRC Benoit considers this a security risk, so
> > it's not in the official Gambas source tree.
> >
> > Next, look at the Plugins.module in the attached sample project.
> > This is where the fun starts. You can pass a text file or project
> > source archive to Plugins.Add(). In both cases, the Plugins module
> > copies the source code into a temporary location, vamps it up into
> > a component project and builds that (you need to have gbc3 and gba3
> > installed). Thanks to the patched interpreter, this component can
> > be loaded via Component.Load() now. The standalone class file or
> > the startup class of the .tar.gz project is instantiated with the
> > Context object, and that's it.
> >
> > If you can get the attached project to run, you will see the spinning
> > triangle in the DrawingArea from the main program as well as the current
> > time being displayed in the top-left corner via the plugin.
> >
> > That said, I wouldn't recommend this way, obviously. I just wanted to
> > show that it can be done in a way that's adequate if you make a hobby
> > project, like I did in 2015. (And that code hasn't been touched since.)
> >
> umm interesting way Tobias .. i get that mail and read it too!
> 
> umm in conclusion "it cannot be", but now i ask something about gambas
> library/modules
> 
> if i have in my project only module sources and in last step i poin that
> use library, this mix can be done?
> 
> i mean, that the  final product due the sources are "linked" or not real in
> the project will use the library?
> 

Oh right, I left out listing the easier solutions because they weren't
satisfying for me.

But if you want to use standard Gambas features, you have to put your
library into the Gambas library search path. This is $XDG_DATA_HOME/gambas3/lib
or $HOME/.local/share/gambas3/lib (if XDG_DATA_HOME isn't set).
If you develop a library project in the IDE and make an executable
out of it, a copy of your library is automatically saved into that
directory by the IDE.

In your main project, you can now add your libraries via the
Properties > Libraries menu. This is probably not what you meant
by "dynamic", as you have to do this while developing your main
program. The most dynamic you get is using

  Component.Load(":<vendor>/<library>:<version>")

For example if you have a library "testlib" with version 0.0 and
vendor "tboege", there will be a corresponding file

  $XDG_DATA_HOME/gambas3/lib/tboege/testlib:0.0.gambas

and you can load it at runtime with:

  Component.Load(":tboege/testlib:0.0")

This loads the library into your Gambas process. Note that since the
compiler didn't know that you will load this library, you can't use
class names exported by it directly in your main project. Either forward-
declare them or look it up using Class.Load().

The only requirement to this method is that the library is compiled
into a .gambas file and installed in the appropriate search directory.

[ There is a comment in the source code that says you can also place
the libraries inside the project directory without a vendor. Those will
be found too. This is apparently for backwards compatibility and isn't
"dynamic" anyway, I think. ]

Regards,
Tobi

-- 
"There's an old saying: Don't change anything... ever!" -- Mr. Monk


More information about the User mailing list