[Gambas-user] How to call a function in a startup loaded module from a plugin loaded at runtime?

Brian G brian at westwoodsvcs.com
Sun May 24 18:21:16 CEST 2020


(Inline)

On 24/5/20 9:03 am, Brian G wrote:
> Is it possible to call a function from a module at run-time that was not originally linked?
>>Yes, I'm pretty sure that this is how the GUI switchers and the database 
>>switchers work.
I have found the answer partly to this question.

> 
> I am trying to call a function in a module loaded at application start-up from a plugin compiled and loaded at run-time.
>>Not quite sure what you mean here. What's a "plugin"? What do you mean 
>>by "compiled and loaded"?
In this instance a plugin is a component which is compiled and archived from a Gambas project. 
The component.load("xx") is used to load the archive into memory then the class.load("xx") is loaded from that.
This class I am calling a plugin. The code I am using to do this is evolved from an example I found online.(I can not remember the author's name)
I attach the code file maybe the author can speak up.

> 
> I can see the modules i want to call the function in, in the list of classes.
>>How are you "Seeing" this list of classes? From within the code itself?
classes in a native class that is a collection of all loaded classes, so just list this to see what is loaded.

> 
> But if i try to access the function in the class it says not found, how to find the object or such that is the module I want to call the function in?
>>What is "it" that is saying "not found"? In fact what is the full 
>>message? I can't understand the last half of this sentence at all.
OK here is a good example

my loaded class xx wants to access a function in the main module of my application, It was not linked as compile time.

so the following gives me access to the module lets call it xx

dim cxx as class = classes["xx"] ' modules are not really classes but reside in the class table, this class can be used as an object

to call the function lets call it yyy  I need to do.

object.call(cxx, "yyy")

This calls the function

I was trying to use cxx.yyy - but that was never found returns error unknown method 

and Getproperty and SetProperty don't seem to work for modules... lol don't suppose they should in a module.

But would like to use structures and such from main module...... That's where I am having issues



>>We can't guess your code.Which makes it hard to be helpful.

Work in progress, Would like to figure out how to access tables etc in the module. but for now extra functions seem to work.
I have attached an example of the code I am using to create and load a plugin

I am trying to access the methods in the main module not class from one of the loaded plugins.


rgrds
b

-------------- next part --------------
A non-text attachment was scrubbed...
Name: plugin example
Type: application/octet-stream
Size: 7606 bytes
Desc: not available
URL: <https://lists.gambas-basic.org/pipermail/user/attachments/20200524/8849d806/attachment-0001.obj>


More information about the User mailing list