[Gambas-user] How to call a function in a startup loaded module from a plugin loaded at runtime?
Bruce
adamnt42 at gmail.com
Mon May 25 01:58:29 CEST 2020
On 25/5/20 1:51 am, Brian G wrote:
>
> I am trying to access the methods in the main module not class from one of the loaded plugins.
>
>
OK! A couple of points:
1) In you main project the classes you want visible in the plugin must
be exported and
2) (Obviously) the methods you want to expose to the plugin must be public.
Here's what I think you are trying:
MAIN PROGRAM "Main" module
--------------------------
' Gambas module file
Export
Public Sub Main()
Dim hXXX As Object
Component.Load("ph.plugin")
' Print Class.IsLoaded("PluginA")
hXXX = Object.New("PluginA")
Catch
Error Subst("&1\nERR: &2 (&3)\n&4\n&1\n", String$(40, "-"),
Error.Text, Error.Code, Error.Backtrace.Join("\n"))
End
Public Function Addup(nums As Integer[]) As Integer
Dim iTot As Integer
For idx As Integer = 0 To nums.Max
iTot += nums[idx]
Next
Return iTot
End
PLUGIN COMPONENT "PluginA" class
--------------------------------
' Gambas class file
Export
Public Sub _new()
Dim cxx As Class = classes["Main"]
Print object.call(cxx, "Addup", [[1, 5, 2, 5, 9]])
End
b
More information about the User
mailing list