Technology Article

Using the Import Command

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

Import

This command plays a different role. It brings the definition of the given package into the currently running script's environment so it can be accessed without having to prefix the package name. An example of a Luster package is luster.display. The classes defined in that package are often used, and in a large script the need to prefix these classes with the package name "luster.display" can be tedious. Import allows you to drop these prefixes as such:

local obj = luster.display.DisplayObject()

will become

local obj = DisplayObject()

You can see how this can be useful. In order to take advantage of this shortcut you must import the package, preferably at the top of the script. This will achieve the desired effect:

import "luster.display.*"

That import command brings in all definitions of the luster.display package. Individual classes can be import by replacing the "*" with a class name like this:

import "luster.display.DisplayObject"

Be careful about conflicting definitions. For example, if the script you are working in defines a DisplayObject then importing the luster.display package would be a bad idea. The definitions would conflict with each other. In case of conflicts you should not import the given package and continue to prefix the desired class with its package name.