# LuajClassLoader (Luaj API)
Date: 2015-04-29

## org.luaj.vm2.server
Class LuajClassLoader

    java.lang.Object
      java.lang.ClassLoader
          org.luaj.vm2.server.LuajClassLoader

    public class LuajClassLoader

extends java.lang.ClassLoader

Class loader that can be used to launch a lua script in a Java VM that has a unique set of classes for org.luaj classes.

Note: This class is experimental and subject to change in future versions.

By using a custom class loader per script, it allows the script to have its own set of globals, including static values such as shared metatables that cannot access lua values from other scripts because their classes are loaded from different class loaders. Thus normally unsafe libraries such as luajava can be exposed to scripts in a server environment using these techniques.

All classes in the package "org.luaj.vm2." are considered user classes, and loaded into this class loader from their bytes in the class path. Other classes are considered systemc classes and loaded via the system loader. This class set can be extended by overriding `isUserClass(String)`.

The `Launcher` interface is loaded as a system class by exception so that the caller may use it to launch lua scripts.

By default `NewLauncher()` creates a subclass of `Launcher` of type `DefaultLauncher` which creates debug globals, runs the script, and prints the return values. This behavior can be changed by supplying a different implementation class to `NewLauncher(Class)` which must extend `Launcher`.

Since:
  luaj 3.0.1
See Also:
  `Launcher`, `NewLauncher()`, `NewLauncher(Class)`, `DefaultLauncher`

Constructor Summary
`LuajClassLoader()`

Method Summary
`static boolean` `isUserClass(java.lang.String classname)` Test if a class name should be considered a user class and loaded by this loader, or a system class and loaded by the system loader.
`java.lang.Class<?>` `loadClass(java.lang.String classname)`
`static Launcher` `NewLauncher()` Construct a default `Launcher` instance that will load classes in its own `LuajClassLoader` using the default implementation class `DefaultLauncher`.
`static Launcher` `NewLauncher(java.lang.Class<? extends Launcher> launcher_class)` Construct a `Launcher` instance that will load classes in its own `LuajClassLoader` using a user-supplied implementation class that implements `Launcher`.

Methods inherited from class java.lang.ClassLoader

`clearAssertionStatus, defineClass, defineClass, defineClass, defineClass, definePackage, findClass, findLibrary, findLoadedClass, findResource, findResources, findSystemClass, getPackage, getPackages, getParent, getResource, getResourceAsStream, getResources, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, loadClass, resolveClass, setClassAssertionStatus, setDefaultAssertionStatus, setPackageAssertionStatus, setSigners`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### LuajClassLoader

    public LuajClassLoader()

Method Detail

### NewLauncher

    public static Launcher NewLauncher()
                                throws java.lang.InstantiationException,
                                       java.lang.IllegalAccessException,
                                       java.lang.ClassNotFoundException

  Construct a default `Launcher` instance that will load classes in its own `LuajClassLoader` using the default implementation class `DefaultLauncher`.

  The `Launcher` that is returned will be a pristine luaj vm whose classes are loaded into this loader including static variables such as shared metatables, and should not be able to directly access variables from other Launcher instances.

  Returns:
    `Launcher` instance that can be used to launch scripts.
  Throws:
    `java.lang.InstantiationException`
    `java.lang.IllegalAccessException`
    `java.lang.ClassNotFoundException`

### NewLauncher

    public static Launcher NewLauncher(java.lang.Class<? extends Launcher> launcher_class)
                                throws java.lang.InstantiationException,
                                       java.lang.IllegalAccessException,
                                       java.lang.ClassNotFoundException

  Construct a `Launcher` instance that will load classes in its own `LuajClassLoader` using a user-supplied implementation class that implements `Launcher`.

  The `Launcher` that is returned will be a pristine luaj vm whose classes are loaded into this loader including static variables such as shared metatables, and should not be able to directly access variables from other Launcher instances.

  Returns:
    instance of type 'launcher_class' that can be used to launch scripts.
  Throws:
    `java.lang.InstantiationException`
    `java.lang.IllegalAccessException`
    `java.lang.ClassNotFoundException`

### isUserClass

    public static boolean isUserClass(java.lang.String classname)

  Test if a class name should be considered a user class and loaded by this loader, or a system class and loaded by the system loader.

  Parameters:
    `classname` - Class name to test.
  Returns:
    true if this should be loaded into this class loader.

### loadClass

    public java.lang.Class<?> loadClass(java.lang.String classname)
                                 throws java.lang.ClassNotFoundException

  Overrides:
    `loadClass` in class `java.lang.ClassLoader`
  Throws:
    `java.lang.ClassNotFoundException`

Copyright © 2007-2015 Luaj.org. All Rights Reserved.