[Gambas-user] can i specify a path to my modules or libs please how?
Tobias Boege
taboege at gmail.com
Tue Apr 17 18:24:04 CEST 2018
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.)
Regards,
Tobi
--
"There's an old saying: Don't change anything... ever!" -- Mr. Monk
-------------- next part --------------
diff --git a/main/gbx/gbx_archive.c b/main/gbx/gbx_archive.c
index a446c27e3..7b587b291 100644
--- a/main/gbx/gbx_archive.c
+++ b/main/gbx/gbx_archive.c
@@ -268,6 +268,11 @@ void ARCHIVE_load(ARCHIVE *arch, bool load_exp)
name = &arch->path[1];
}
+ else if (*arch->path == '/')
+ {
+ ARCHIVE_path = STRING_new_zero(FILE_get_dir(arch->path));
+ name = FILE_get_name(arch->path);
+ }
else
name = FILE_get_name(arch->path);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: plugtest-0.0.1.tar.gz
Type: application/gzip
Size: 14556 bytes
Desc: not available
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20180417/98153bc3/attachment-0001.gz>
More information about the User
mailing list