Found an issue in SpiderBasic ? Please report it here !
kingwolf71
 
Posts: 21
Joined: Wed May 01, 2019 10:14 am

compiler Include does not see globals

by kingwolf71 Wed May 20, 2020 11:01 am

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: 1298
Joined: Mon Feb 24, 2014 10:51 am

Re: compiler Include does not see globals

by Fred Wed May 20, 2020 1:28 pm

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

by kingwolf71 Fri May 22, 2020 1:55 am

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: 1298
Joined: Mon Feb 24, 2014 10:51 am

Re: compiler Include does not see globals

by Fred Fri May 22, 2020 7:46 am

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.
Return to Bugs Reports

Who is online

Users browsing this forum: No registered users and 2 guests