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

## org.luaj.vm2.compiler
Class LuaC

    java.lang.Object
      Constants
          org.luaj.vm2.compiler.LuaC

All Implemented Interfaces:
  Globals.Compiler, Globals.Loader

    public class LuaC

extends Constants
implements Globals.Compiler, Globals.Loader

Compiler for Lua.

Compiles lua source files into lua bytecode within a `Prototype`, loads lua binary files directly into a `Prototype`, and optionaly instantiates a `LuaClosure` around the result using a user-supplied environment.

Implements the `Globals.Compiler` interface for loading initialized chunks, which is an interface common to lua bytecode compiling and java bytecode compiling.

The `LuaC` compiler is installed by default by both the `JsePlatform` and `JmePlatform` classes, so in the following example, the default `LuaC` compiler will be used:

     Globals globals = JsePlatform.standardGlobals();
     globals.load(new StringReader("print 'hello'"), "main.lua" ).call();

To load the LuaC compiler manually, use the install method:

     LuaC.install(globals);

See Also:
  `install(Globals)`, `Globals.compiler`, `Globals.loader`, `LuaJC`, `JsePlatform`, `JmePlatform`, `BaseLib`, `LuaValue`, `Prototype`

Field Summary
`static LuaC` `instance` A sharable instance of the LuaC compiler.

Constructor Summary
`protected` `LuaC()`

Method Summary
`Prototype` `compile(java.io.InputStream stream, java.lang.String chunkname)` Compile lua source into a Prototype.
`static void` `install(Globals globals)` Install the compiler so that LoadState will first try to use it when handed bytes that are not already a compiled lua chunk.
`LuaValue` `load(java.io.InputStream stream, java.lang.String chunkname, Globals globals)` Deprecated. Use Globals.load(InputString, String, String) instead, or LuaC.compile(InputStream, String) and construct LuaClosure directly.
`LuaFunction` `load(Prototype prototype, java.lang.String chunkname, LuaValue env)` Convert the prototype into a LuaFunction with the supplied environment.

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

Field Detail

### instance

    public static final LuaC instance

  A sharable instance of the LuaC compiler.

Constructor Detail

### LuaC

    protected LuaC()

Method Detail

### install

    public static void install(Globals globals)

  Install the compiler so that LoadState will first try to use it when handed bytes that are not already a compiled lua chunk.

  Parameters:
    `globals` - the Globals into which this is to be installed.

### compile

    public Prototype compile(java.io.InputStream stream,
                             java.lang.String chunkname)
                      throws java.io.IOException

  Compile lua source into a Prototype.

  Specified by:
    `compile` in interface `Globals.Compiler`
  Parameters:
    `stream` - InputStream representing the text source conforming to lua source syntax.
    `chunkname` - String name of the chunk to use.
  Returns:
    Prototype representing the lua chunk for this source.
  Throws:
    `java.io.IOException`

### load

    public LuaFunction load(Prototype prototype,
                            java.lang.String chunkname,
                            LuaValue env)
                     throws java.io.IOException

  Description copied from interface: `Globals.Loader`
  Convert the prototype into a LuaFunction with the supplied environment.

  Specified by:
    `load` in interface `Globals.Loader`
  Throws:
    `java.io.IOException`

### load

    public LuaValue load(java.io.InputStream stream,
                         java.lang.String chunkname,
                         Globals globals)
                  throws java.io.IOException

  Deprecated. Use Globals.load(InputString, String, String) instead, or LuaC.compile(InputStream, String) and construct LuaClosure directly.

  Throws:
    `java.io.IOException`

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