public class CoerceJavaToLua extends Object
This class is primarily used by the LuajavaLib,
but can also be used directly when working with Java/lua bindings.
To coerce scalar types, the various, generally the valueOf(type) methods
on LuaValue may be used:
LuaValue.valueOf(boolean)LuaValue.valueOf(byte[])LuaValue.valueOf(double)LuaValue.valueOf(int)LuaValue.valueOf(String)
To coerce arrays of objects and lists, the listOf(..) and tableOf(...) methods
on LuaValue may be used:
LuaValue.listOf(LuaValue[])LuaValue.listOf(LuaValue[], org.luaj.vm2.Varargs)LuaValue.tableOf(LuaValue[])LuaValue.tableOf(LuaValue[], LuaValue[], org.luaj.vm2.Varargs)coerce(Object) looks as the type and dimesioning
of the argument and tries to guess the best fit for corrsponding lua scalar,
table, or table of tables.coerce(Object),
LuajavaLibpublic static LuaValue coerce(Object o)
Integral types boolean, byte, char, and int
will become LuaInteger;
long, float, and double will become LuaDouble;
String and byte[] will become LuaString;
types inheriting from LuaValue will be returned without coercion;
other types will become LuaUserdata.
o - Java object needing conversionLuaValue corresponding to the supplied Java value.LuaValue,
LuaInteger,
LuaDouble,
LuaString,
LuaUserdataCopyright © 2020. All rights reserved.