Page 1 of 1

compiler Include does not see globals

Posted: Wed May 20, 2020 11:01 am
by kingwolf71
inc.sbi

Code: Select all

 CompilerIf Not Defined( PB_Compiler_Unicode, #PB_Constant )
      #PB_Compiler_Unicode       = #True
      #PB_Compiler_Thread        = #True
      #SB_Compiler_SpiderBasic   = 230
      debug "Using Spiderbasic " + #SB_Compiler_SpiderBasic
 CompilerEndIf
 
 
 CompilerIf Defined(SB_Compiler_SpiderBasic, #PB_Constant)
   Procedure      myFormat()
      debug "my format"
   EndProcedure
   
 CompilerEndIf

;main.sb

Code: Select all

XIncludeFile "./inc.sbi"

DeclareModule test
   Declare  myfun()
EndDeclareModule

Module test
   
   Procedure         myfun()
      myFormat()  ;<--- compiler error is not a function
      debug #SB_Compiler_SpiderBasic      
   EndProcedure
   
EndModule



Re: compiler Include does not see globals

Posted: Wed May 20, 2020 1:28 pm
by Fred
A module can't access global procedure.

Re: compiler Include does not see globals

Posted: Fri May 22, 2020 1:55 am
by kingwolf71
In PureBasic it works fine; is this a difference between the 2 compilers?
But what about modules?

main.sb

Code: Select all


XIncludeFile "./inc.sbi"


DeclareModule test
   Declare  myfun()
EndDeclareModule

Module test
   
   UseModule test
   
   Procedure         myfun()
      test2::myFormat()  <--- this should be seen...but I get compiler error
      debug #SB_Compiler_SpiderBasic      
   EndProcedure
   
EndModule


inc.sbi

Code: Select all

ilerIf Not Defined( PB_Compiler_Unicode, #PB_Constant )
      #PB_Compiler_Unicode       = #True
      #PB_Compiler_Thread        = #True
      #SB_Compiler_SpiderBasic   = 230
      debug "Using Spiderbasic " + #SB_Compiler_SpiderBasic
 CompilerEndIf
 
 
 DeclareModule test2
    
    CompilerIf Defined(SB_Compiler_SpiderBasic, #PB_Constant)
       declare    myFormat()
    CompilerEndIf
 EndDeclareModule
 
 Module test2
    CompilerIf Defined(SB_Compiler_SpiderBasic, #PB_Constant)
      Procedure      myFormat()
         debug "my format"
      EndProcedure
      
   CompilerEndIf
EndModule

If there is a documented way, somewhere, how to make include files which can isolate or pre-process code for the different compilers (SpiderBasic and Purebasic) it should be shown as after all this is the main advantage of having 2 compiler with the same syntax and functions

Re: compiler Include does not see globals

Posted: Fri May 22, 2020 7:46 am
by Fred
You can do like this:

Code: Select all

CompilerIf #PB_Compiler_OS = #PB_OS_Web
  Debug "SpiderBasic"
CompilerElse
  Debug "PureBasic"
CompilerEndIf
To Ease the thing, you could just declare a new #PB_SpiderBasic constant in both case, so you can test it easily:

Code: Select all

CompilerIf #PB_Compiler_OS = #PB_OS_Web
  #PB_SpiderBasic = 1
CompilerElse
  #PB_SpiderBasic = 0
CompilerEndIf

CompilerIf #PB_SpiderBasic
  ; SpiderBasic specific code
  Debug "Spider"
CompilerEndIf

CompilerIf Not #PB_SpiderBasic
  ; PureBasic specific code
  Debug "Pure"
CompilerEndIf

About your issue, I will take a look, if it works in PB it should in SB as well.

Re: compiler Include does not see globals

Posted: Fri Oct 07, 2022 12:22 pm
by Fred
I just checked, it's the same in PB, you can't access main procedure in your module.