ScriptBasic > Tutorials

ScriptBasic namespace support

(1/1)

Support:
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"

--- End code ---

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

C:\scriptbasic\test>

Support:
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

--- End code ---

C:\scriptbasic\test>emod
undef
1
2
3
You're Out!
undef
C:\scriptbasic\test>

Navigation

[0] Message Index

Go to full version