Class 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 org.luaj.vm2.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 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:
  • Field Details

    • instance

      public static final LuaC instance
      A sharable instance of the LuaC compiler.
  • Constructor Details

    • LuaC

      public LuaC()
  • Method Details

    • 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(InputStream stream, String chunkname) throws 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:
      IOException
    • load

      public LuaFunction load(Prototype prototype, String chunkname, LuaValue env) throws 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:
      IOException
    • load

      public LuaValue load(InputStream stream, String chunkname, Globals globals) throws IOException
      Deprecated.
      Use Globals.load(InputString, String, String) instead, or LuaC.compile(InputStream, String) and construct LuaClosure directly.
      Throws:
      IOException