Class LuaFactory
public class LuaFactory extends Object
Lua factories can be used to create various
LuaInterpreter
objects without the need of recompiling.
This can be created using any of the Lua.factory(java.io.Reader, java.lang.String)
methods.
Once the factory is created, compile()
can be used to
parse the reader and close it. Once compiled, the build()
method retrieves a new LuaInterpreter every time.
Prior to building any interpreters, handlers can be attached
which are called before the interpreter is returned by
build()
. Libraries can also be added which would be
injected into each interpreter built.
- Author:
- theKayani
-
Method Summary
Modifier and Type Method Description void
addHandler(Consumer<LuaInterpreter> handler)
Handlers are called on each interpreter built before they are returned.void
addLibrary(LuaLibrary<?> lib)
Add a library to be injected into each built interpreter.LuaInterpreter
build()
Build and return a newLuaInterpreter
object containing the given libraries as well as executing the handlers that were added previously.void
compile()
Fully read the reader and attempt to compile the Lua source into an executable chunk.void
removeHandler(Consumer<LuaInterpreter> handler)
Remove a handler from this factory.void
removeLibrary(LuaLibrary<?> lib)
Remove a specific library if it was previously added using theaddLibrary(LuaLibrary)
method.
-
Method Details
-
addLibrary
Add a library to be injected into each built interpreter. This means that the retrieved interpreter does not need this library added to it.
- Parameters:
lib
- aLuaLibrary
-
addHandler
Handlers are called on each interpreter built before they are returned. This happens after libraries are injected.
- Parameters:
handler
- aConsumer
object
-
removeLibrary
Remove a specific library if it was previously added using the
addLibrary(LuaLibrary)
method. If the given library doesn't exist, this doesn't do anything.- Parameters:
lib
- aLuaLibrary
object
-
removeHandler
Remove a handler from this factory. The handler would only be removed if it was previously added using the
addHandler(Consumer)
method.- Parameters:
handler
- aConsumer
object
-
compile
Fully read the reader and attempt to compile the Lua source into an executable chunk. If there are any issues during compilation, this method will throw them.
This must be called before
build()
can be called.- Throws:
IOException
- if any.
-
build
Build and return a new
LuaInterpreter
object containing the given libraries as well as executing the handlers that were added previously.- Returns:
- a
LuaInterpreter
object
-