Packages & Namespaces

Putting the SMC-generated classes into a specific Java package/C++ namespace/Tcl namespace/Groovy package/Perl package/Ruby module/Scala package is as easy placing the %package keyword at the top of your .sm file along with the %class keyword.

(Aside: Remember to place namespace import <::namespace::*> after sourcing in a *_sm.tcl file.)

To import a C++ namespace, Java class, Tcl package, VB.net, C# namespace, Groovy class, Lua module, Python module, Perl module, PHP file, Ruby module or Scala class, use the %import keyword:

%import <name>

(Note: There is no semicolon at the line's end.)

The %import is translated into the following syntax:

See examples/Java/EX4, C++/EX4, Tcl/EX4, VB/EX4, CSharp/EX4, Perl/EX4 and Ruby/EX4 for sample code which uses packages/namespaces with SMC.

Fully Qualified Class Names

If you are not able to place the SMC-generated classes into the same package/namespace as the %class context class, then you will need to specify the context class' fully qualified name. The SMC %class key supports Java, C++ and Tcl fully qualified name syntax. For example, the following are accepted:

// For a Java, VB.net and C# application %class com.acme.project.AppClass

and

// For a C++ or Tcl application %class ::acme::project::AppClass