Author Topic: ScriptBasic namespace support  (Read 16345 times)

Support

  • Administrator
  • *****
  • Posts: 22
    • View Profile
ScriptBasic namespace support
« 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: [Select]
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>

Support

  • Administrator
  • *****
  • Posts: 22
    • View Profile
Re: ScriptBasic namespace support
« Reply #1 on: April 21, 2010, 02:46:15 PM »
Here is another example but using nested MODULEs or namespaces.

Code: [Select]
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>