Package party.iroiro.luajava.luaj
Class LuaJ
java.lang.Object
party.iroiro.luajava.AbstractLua
party.iroiro.luajava.luaj.LuaJ
- All Implemented Interfaces:
AutoCloseable,Lua,LuaThread
A thin wrapper around LuaJ to provide Lua C API-like API.
Please note that LuaJ bindings are limited in its capabilities. Other bindings provided by LuaJava utilizes JNI functions to provide functionalities like calling default methods in interfaces. However, LuaJ uses no JNI, and thus won't be able to do things beyond the Java reflection API.
-
Nested Class Summary
Nested classes/interfaces inherited from interface party.iroiro.luajava.Lua
Lua.Conversion, Lua.LuaType -
Field Summary
Fields inherited from class party.iroiro.luajava.AbstractLua
C, id, instances, L, loader, mainThread, recordedReferences, recyclableReferences, requireFunction, subThreadsFields inherited from interface party.iroiro.luajava.Lua
GLOBAL_THROWABLE -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionconvertError(int code) Converts a native error code to a LuaError enum value.convertType(int code) Converts a native type code to a LuaType enum value.protected AbstractLuanewThread(long L, int id, AbstractLua mainThread) Creates a new sub-thread attached to this main thread.protected booleanA method specifically for working around deadlocks caused by LuaJ.Methods inherited from class party.iroiro.luajava.AbstractLua
addSubThread, checkError, checkStack, close, concat, createProxy, createTable, dump, equal, error, error, eval, from, from, from, from, from, fromNull, gc, get, get, getField, getGlobal, getId, getJavaError, getLuaNatives, getMainState, getMetaField, getMetatable, getPointer, getRegisteredMetatable, getTable, getTop, insert, invokeSpecial, isBoolean, isClosed, isFunction, isInteger, isJavaObject, isNil, isNone, isNoneOrNil, isNumber, isString, isTable, isThread, isUserdata, lessThan, load, load, loadExternal, newRegisteredMetatable, newTable, newThread, next, openLibraries, openLibrary, pCall, pop, push, push, push, push, push, push, push, push, push, push, push, pushArray, pushJavaArray, pushJavaClass, pushJavaObject, pushJavaObjectOrArray, pushNil, pushThread, pushValue, rawEqual, rawGet, rawGetI, rawLength, rawSet, rawSetI, ref, ref, refGet, register, remove, replace, require, resume, run, run, set, setExternalLoader, setField, setGlobal, setMetatable, setTable, setTop, status, toAbsoluteIndex, toBoolean, toBuffer, toDirectBuffer, toInteger, toJavaObject, toList, toMap, toNumber, toObject, toObject, toString, type, unref, unRef, xMove, yield
-
Constructor Details
-
LuaJ
-
LuaJ
public LuaJ()
-
-
Method Details
-
newThread
Description copied from class:AbstractLuaCreates a new sub-thread attached to this main thread.- Specified by:
newThreadin classAbstractLua- Parameters:
L- the pointer to the new Lua stateid- the unique identifier for the new statemainThread- the main thread this state belongs to- Returns:
- the new sub-thread
-
convertError
Description copied from class:AbstractLuaConverts a native error code to a LuaError enum value.- Specified by:
convertErrorin classAbstractLua- Parameters:
code- the native error code- Returns:
- the corresponding LuaError value
-
convertType
Description copied from class:AbstractLuaConverts a native type code to a LuaType enum value.- Specified by:
convertTypein classAbstractLua- Parameters:
code- the native type code- Returns:
- the corresponding LuaType value
-
shouldSynchronize
protected boolean shouldSynchronize()Description copied from class:AbstractLuaA method specifically for working around deadlocks caused by LuaJ.In LuaJ bindings, without this work-around, deadlocks can happen when:
1. (Thread#A) The user synchronizes on mainThread as is required by LuaJava when used in multi-threaded environment. 2. (Thread#A) The user callsAbstractLua.run(String)for example, to run a Lua snippet. 3. The snippet creates a coroutine, mandating LuaJ to create a Java thread (#B). 4. Inside the coroutine (i.e., the Java thread#B), the code calls a Lua proxy object. 5. (Thread#B)LuaProxy.invoke(Object, Method, Object[])tries to synchronizes on mainThread. 6. Since thread#A is already inside a synchronization block, the two threads deadlocks.This work-around asks
LuaProxy.invoke(Object, Method, Object[])to avoid synchronization when it detects that it is called from a coroutine thread created by LuaJ.- Overrides:
shouldSynchronizein classAbstractLua- Returns:
falseonly when invoke within a coroutine thread created by LuaJ
-