compiler Include does not see globals

Just starting out? Need help? Post your questions and find answers here.
kingwolf71
Posts: 21
Joined: Wed May 01, 2019 10:14 am

compiler Include does not see globals

Post 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


Fred
Site Admin
Posts: 1506
Joined: Mon Feb 24, 2014 10:51 am

Re: compiler Include does not see globals

Post by Fred »

A module can't access global procedure.
kingwolf71
Posts: 21
Joined: Wed May 01, 2019 10:14 am

Re: compiler Include does not see globals

Post 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
Fred
Site Admin
Posts: 1506
Joined: Mon Feb 24, 2014 10:51 am

Re: compiler Include does not see globals

Post 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.
Fred
Site Admin
Posts: 1506
Joined: Mon Feb 24, 2014 10:51 am

Re: compiler Include does not see globals

Post by Fred »

I just checked, it's the same in PB, you can't access main procedure in your module.
Post Reply