how to load dialogs from multiple libraries / containers

I have these objects

My Macros & Dialogs
   lib1
      dlg1

LibreOffice Macros & Dialogs
   Tools
   [etc...]
    
doc.ods
   lib2
      subA
      dlg2

in subA I have

	globalscope.basiclibraries.loadlibrary("Tools")
    dlg = loaddialog("libraryname", "dlg2")

so far all i can figure out is that depending on what i put for “libraryname”, the loaddialog call will either not find dlg2 or fail altogether. the only way i have found to make anything work is to cut and paste the loaddialog code from Tools into subA, which is ungood.

[edit : forgot to indicate subA is of course in a module in lib2]

solution:
the args to loaddialog are library_name$, dialog_name$, optional container as object

The global variable dialoglibraries is a container object but contains references to different libraries depending on where it is used. In subs in doc.ods it contains a reference to lib2. but when i call loaddialog without this optional container arg, loaddialog grabs its own copy of dialoglibraries, which in that context refers to the libraries NOT in doc.ods.

so if i wanted to run both both dialogs from subA, the correct code is

dim firstdialog as object, seconddialog as object

globalscope.basiclibraries.loadlibrary("Tools")    ' for access to sub loaddialog()

firstdialog = loaddialog("lib1", "dlg1")
seconddialog = loaddialog("lib2", "dlg2", dialoglibraries)