ScriptBasic
ScriptBasic => Tutorials => Topic started by: 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.
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>
-
Here is another example but using nested MODULEs or namespaces.
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>