本文整理匯總了Java中org.luaj.vm2.LuaValue.tableOf方法的典型用法代碼示例。如果您正苦於以下問題:Java LuaValue.tableOf方法的具體用法?Java LuaValue.tableOf怎麽用?Java LuaValue.tableOf使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.luaj.vm2.LuaValue
的用法示例。
在下文中一共展示了LuaValue.tableOf方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: createMetatable
import org.luaj.vm2.LuaValue; //導入方法依賴的package包/類
/**
* create metatable for libs
*
* @return
*/
public static LuaTable createMetatable(Class<? extends LibFunction> libClass) {
LuaTable result = AppCache.getCache(CACHE_METATABLES).get(libClass);//get from cache
if (result == null) {
LuaTable libTable = null;
if (LuaViewConfig.isUseNoReflection()) {
final List<String> methodNames = getMapperMethodNames(libClass);
libTable = LuaViewManager.bind(libClass, methodNames);
} else {
final List<Method> methods = getMapperMethods(libClass);
libTable = LuaViewManager.bindMethods(libClass, methods);
}
result = LuaValue.tableOf(new LuaValue[]{LuaValue.INDEX, libTable, LuaValue.NEWINDEX, new NewIndexFunction(libTable)});
//update cache
AppCache.getCache(CACHE_METATABLES).put(libClass, result);
}
return result;
}
示例2: call
import org.luaj.vm2.LuaValue; //導入方法依賴的package包/類
/** Perform one-time initialization on the library by creating a table
* containing the library functions, adding that table to the supplied environment,
* adding the table to package.loaded, and returning table as the return value.
* Creates a metatable that uses __INDEX to fall back on itself to support string
* method operations.
* If the shared strings metatable instance is null, will set the metatable as
* the global shared metatable for strings.
* <P>
* All tables and metatables are read-write by default so if this will be used in
* a server environment, sandboxing should be used. In particular, the
* {@link LuaString#s_metatable} table should probably be made read-only.
* @param modname the module name supplied if this is loaded via 'require'.
* @param env the environment to load into, typically a Globals instance.
*/
public LuaValue call(LuaValue modname, LuaValue env) {
LuaTable string = new LuaTable();
string.set("byte", new byte_());
string.set("char", new char_());
string.set("dump", new dump());
string.set("find", new find());
string.set("format", new format());
string.set("gmatch", new gmatch());
string.set("gsub", new gsub());
string.set("len", new len());
string.set("lower", new lower());
string.set("match", new match());
string.set("rep", new rep());
string.set("reverse", new reverse());
string.set("sub", new sub());
string.set("upper", new upper());
LuaTable mt = LuaValue.tableOf(
new LuaValue[] { INDEX, string });
env.set("string", string);
env.get("package").get("loaded").set("string", string);
if (LuaString.s_metatable == null)
LuaString.s_metatable = mt;
return string;
}
示例3: toLuaTable
import org.luaj.vm2.LuaValue; //導入方法依賴的package包/類
/**
* Transforming a collection of strings to a LUA value table.
*
* @param collection
* Collection of strings.
* @return
* LUA value table.
*/
public static LuaValue toLuaTable(Collection<String> collection) {
LuaValue table = LuaValue.tableOf();
int i = 1;
for (String s : collection) {
table.set(i, LuaValue.valueOf(s));
i++;
}
return table;
}