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

brian at westwoodsvcs.com brian at westwoodsvcs.com
Mon May 25 03:48:31 CEST 2020


More interested in how to access structure defs and variables from main module
--
Thanks
Brian Sunday, 24 May 2020, 04:58PM -07:00 from Bruce  adamnt42 at gmail.com :

>
>
>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
>
>----[  http://gambaswiki.org/wiki/doc/netiquette ]----
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.gambas-basic.org/pipermail/user/attachments/20200525/466e512e/attachment.html>


More information about the User mailing list