ScriptBasic
February 09, 2012, 08:16:32 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: The ScriptBasic User, Developer and extension module guides are available at the WIKI.
 
   Home   Wiki Help Search Login Register  
Pages: [1]
  Print  
Author Topic: ScriptBasic namespace support  (Read 1186 times)
support
Administrator
*****
Posts: 369


« on: October 08, 2009, 10:53:56 AM »

SB supports namespaces using the MODULE / END MODULE statements. All variables, function and subs are localized to the module and the :: syntax must be use to access the modules resources from your main:: program (or other modules) namespace.

Code:
bar = 1

MODULE foo

PRINT bar,"\n"

bar = 2

FUNCTION modfunc
  LOCAL bar
  bar = 3
  modfunc = bar
END FUNCTION

END MODULE

PRINT bar, "\n"

PRINT foo::bar, "\n"

PRINT foo::modfunc(), "\n"

C:\scriptbasic\test>module
undef
1
2
3

C:\scriptbasic\test>
Logged
support
Administrator
*****
Posts: 369


« Reply #1 on: April 21, 2010, 02:46:15 PM »

Here is another example but using nested MODULEs or namespaces.

Code:
MODULE One
  a = 1
  MODULE ::Two
    a = 2
    MODULE ::Three
      SUB UOut
        LOCAL a
        a = "You're Out!\n"
        PRINT a
      END SUB
      a = 3
    END MODULE
  END MODULE
END MODULE

PRINT a,"\n"
PRINT One::a,"\n"
PRINT One::Two::a,"\n"
PRINT One::Two::Three::a,"\n"
One::Two::Three::UOut
PRINT a

C:\scriptbasic\test>emod
undef
1
2
3
You're Out!
undef
C:\scriptbasic\test>
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.16 | SMF © 2011, Simple Machines Valid XHTML 1.0! Valid CSS!