Shared for Module

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
GPI
PureBasic Expert
PureBasic Expert
Posts: 1394
Joined: Fri Apr 25, 2003 6:41 pm

Shared for Module

Post by GPI »

sometimes it would be usefull to Share "Resources" from outside of a modul. For example

Code: Select all

#EnableLoging=#true
XIncludeFile "somefile.pbi"
Somefile.pbi

Code: Select all

DeclareModule Some
  Shared #EnableLoging
EndDeclareModule
Module some
  CompilerIf #EnableLoging 
  CompilerEndif
EndModule
"Shared" should support in this case Everything (inlcuding Interface, Arrays, Maps, Lists, Variables...)
User avatar
Sicro
Enthusiast
Enthusiast
Posts: 538
Joined: Wed Jun 25, 2014 5:25 pm
Location: Germany
Contact:

Re: Shared for Module

Post by Sicro »

What is bad when using a shared module and to include it in the other modules?

Code: Select all

DeclareModule CommonModule
  
  #test = 123456789
  
EndDeclareModule
Module CommonModule : EndModule


DeclareModule Whatever
  
  UseModule CommonModule
  Declare.i Get()
  
EndDeclareModule

Module Whatever
  
  Procedure.i Get()
    ProcedureReturn #test
  EndProcedure
  
EndModule


DeclareModule Whatever2
  
  UseModule CommonModule
  Declare.i Get()
  
EndDeclareModule

Module Whatever2
  
  Procedure.i Get()
    ProcedureReturn #test
  EndProcedure
  
EndModule


Debug Whatever::Get()
Debug Whatever2::Get()
Image
Why OpenSource should have a license :: PB-CodeArchiv-Rebirth :: Pleasant-Dark (syntax color scheme) :: RegEx-Engine (compiles RegExes to NFA/DFA)
Manjaro Xfce x64 (Main system) :: Windows 10 Home (VirtualBox) :: Newest PureBasic version
GPI
PureBasic Expert
PureBasic Expert
Posts: 1394
Joined: Fri Apr 25, 2003 6:41 pm

Re: Shared for Module

Post by GPI »

For example you want to use Code from diffrent users, like here in the "Tricks 'n' Tips" section. One call the Common-Module "Common", other "mCommon" or "CommonModule" that could be a problem. There is no default-name for the "common". Also a Module can only declared once. When you use (as in the example above) more includes with some control-variables, like here

Code: Select all

#something_dothis=#true
xincludefile "Something.pbi"

#this_dothat=#false
xincludefile "this.pbi"

#that_dosomething=#true
xincludefile "that.pbi"

is in my opinion better to read than that:

Code: Select all

DeclareModule Common
#something_dothis=#true
#this_dothat=#false
#that_dosomething=#true
EndDeclareModule
Module Common:EndModule

xincludefile "Something.pbi"
xincludefile "this.pbi"
xincludefile "that.pbi"
The controll constants are then near by the includefiles.
Post Reply