本文整理了Java中org.luaj.vm2.LuaTable
类的一些代码示例,展示了LuaTable
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。LuaTable
类的具体详情如下:
包路径:org.luaj.vm2.LuaTable
类名称:LuaTable
[英]Subclass of LuaValue for representing lua tables.
Almost all API's implemented in LuaTable are defined and documented in LuaValue.
If a table is needed, the one of the type-checking functions can be used such as #istable(), #checktable(), or #opttable(LuaTable)
The main table operations are defined on LuaValue for getting and setting values with and without metatag processing:
To iterate over key-value pairs from Java, use
LuaValue k = LuaValue.NIL;
As with other types, LuaTable instances should be constructed via one of the table constructor methods on LuaValue:
LuaValue k = LuaValue.NIL;
与其他类型一样,LuaTable实例应通过LuaValue上的表构造函数方法之一构造:
*LuaValue#tableOf()空表
*LuaValue#tableOf(int,int)带容量的表
*LuaValue#listOf(LuaValue[])初始化数组部分
*LuaValue#listOf(LuaValue[],Varargs)初始化数组部分
*LuaValue#tableOf(LuaValue[])初始化命名哈希部分
*LuaValue#tableOf(Varargs,int)初始化命名哈希部分
*LuaValue#tableOf(LuaValue[],LuaValue[])初始化数组和命名部分
*LuaValue#tableOf(LuaValue[],LuaValue[],Varargs)初始化数组和命名部分
代码示例来源:origin: com.aerospike/aerospike-client
public LuaValue call(LuaValue env) {
LuaTable meta = new LuaTable();
meta.set("__index", new index());
LuaTable table = new LuaTable();
table.setmetatable(meta);
instance.registerPackage("aerospike", table);
return table;
}
代码示例来源:origin: artex-development/Lukkit
private HashMap<?, ?> convertToMap(LuaTable table) {
HashMap<Object, Object> map = new HashMap<>();
LuaValue[] rootKeys = table.keys();
for (LuaValue k : rootKeys) {
if (table.get(k).istable()) {
map.put(k, this.convertToMap(table.get(k).checktable()));
} else {
map.put(k, table.get(k).touserdata());
}
}
return map;
}
代码示例来源:origin: com.cloudera.kitten/kitten-common
private void step() {
this.varargs = array ? t.inext(currentKey) : t.next(currentKey);
currentKey = varargs.arg1();
}
}
代码示例来源:origin: M66B/XPrivacyLua
private void setLibInstance(LuaTable t) {
LuaValue[] k = t.keys();
for ( int i=0, n=k.length; i<n; i++ )
((IoLibV) t.get(k[i])).iolib = this;
}
代码示例来源:origin: info.bliki.wiki/bliki-core
@Override
public LuaValue getSetupOptions() {
LuaTable table = new LuaTable();
table.set("nowiki_protocols", new LuaTable());
table.set("comma", ", ");
table.set("and", " and ");
table.set("ellipsis", "...");
return table;
}
}
代码示例来源:origin: tonivade/claudb
private LuaValue createBinding(RedisBinding redis) {
LuaTable binding = LuaTable.tableOf();
binding.set("call", redis);
return binding;
}
代码示例来源:origin: Tencent/RapidView
private void setHeader(LuaTable header){
LuaValue key = LuaValue.NIL;
LuaValue value = LuaValue.NIL;
if( header != null && header.istable() ){
while(true){
Varargs argsItem = header.next(key);
key = argsItem.arg1();
if( key.isnil() ){
break;
}
value = argsItem.arg(2);
if( key.isstring() && value.isstring() ){
addHeader(key.toString(), value.toString());
}
}
}
}
代码示例来源:origin: info.bliki.wiki/bliki-core
private String replace(String msg, LuaTable params) {
for (int i=1; i<params.length()+1; i++) {
LuaValue param = params.get(i);
String actualParam;
if (param.istable()) {
if (!param.get("raw").isnil()) {
actualParam = param.get("raw").checkjstring();
} else if (!param.get("num").isnil()) {
if (param.get("num").isnumber()) {
LuaNumber number = param.get("num").checknumber();
NumberFormat nf = NumberFormat.getInstance(Locale.forLanguageTag(lang));
actualParam = nf.format(number.todouble());
} else {
actualParam = param.get("num").tojstring();
}
} else {
actualParam = "unknown";
}
} else {
actualParam = param.checkjstring();
}
msg = msg.replace("$"+i, actualParam);
}
return msg;
}
}
代码示例来源:origin: info.bliki.wiki/bliki-core
private String formatQuery(LuaValue page, LuaValue query) {
if (query.isstring()) {
return wgScript + "?title="+page.checkstring()+"&"+query.checkjstring();
} else if (query.istable()) {
LuaTable params = query.checktable();
String base = wgScript + "?title="+page.checkstring()+"&";
for (LuaValue key : params.keys()) {
base += (key.tojstring() + "=" + params.get(key).tojstring());
}
return base;
} else {
throw new AssertionError("unexpected type: "+query);
}
}
}
代码示例来源:origin: M66B/XPrivacyLua
/** caller must ensure key is not nil */
public void set( LuaValue key, LuaValue value ) {
if (!key.isvalidkey() && !metatag(NEWINDEX).isfunction())
typerror("table index");
if ( m_metatable==null || ! rawget(key).isnil() || ! settable(this,key,value) )
rawset(key, value);
}
代码示例来源:origin: M66B/XPrivacyLua
/** This may be deprecated in a future release.
* It is recommended to count via iteration over next() instead
* @return count of keys in the table
* */
public int keyCount() {
LuaValue k = LuaValue.NIL;
for ( int i=0; true; i++ ) {
Varargs n = next(k);
if ( (k = n.arg1()).isnil() )
return i;
}
}
代码示例来源:origin: M66B/XPrivacyLua
public LuaValue call(LuaValue modname, LuaValue env) {
globals = env.checkglobals();
// io lib functions
LuaTable t = new LuaTable();
bind(t, IoLibV.class, IO_NAMES );
// create file methods table
filemethods = new LuaTable();
bind(filemethods, IoLibV.class, FILE_NAMES, FILE_CLOSE );
// set up file metatable
LuaTable mt = new LuaTable();
bind(mt, IoLibV.class, new String[] { "__index" }, IO_INDEX );
t.setmetatable( mt );
// all functions link to library instance
setLibInstance( t );
setLibInstance( filemethods );
setLibInstance( mt );
// return the table
env.set("io", t);
env.get("package").get("loaded").set("io", t);
return t;
}
代码示例来源:origin: info.bliki.wiki/bliki-core
Message(LuaValue data) {
useDB = data.get("useDB").optboolean(false);
lang = data.get("lang").optjstring("en");
keys = data.get("keys").opttable(new LuaTable());
params = data.get("params").opttable(new LuaTable());
rawMessage = data.get("rawMessage").optstring(LuaString.valueOf(""));
}
代码示例来源:origin: hsllany/HtmlNative
static Map<String, String> luaTableToMap(LuaTable value) {
Map<String, String> params = new HashMap<>();
LuaValue[] keys = value.keys();
for (LuaValue k : keys) {
if (k.isstring()) {
LuaValue v = value.get(k);
if (v.isstring()) {
params.put(k.tojstring(), v.tojstring());
}
}
}
return params;
}
代码示例来源:origin: Tencent/RapidView
@Override
public LuaValue call(LuaValue var1, LuaValue var2) {
LuaTable functions = new LuaTable();
functions.set("getRapidView", new GetPhotonView());
functions.set("getJavaBridge", new GetJavaBridge());
functions.set("getEnvironment", new GetEnvironment());
var2.set("rapid", functions);
var2.get("package").get("loaded").set("rapid", functions);
return functions;
}
代码示例来源:origin: stackoverflow.com
LuaClosure closure = new LuaClosure(chunk.checkclosure().p, globals);
int l = table.length();
for (int i =1;i<=l;i++)
System.out.println("key1:"+table.rawget(i).get("key1"));
System.out.println("key2:"+table.rawget(i).get("key2"));
System.out.println("key3:"+table.rawget(i).get("key3"));
System.out.println("key4:"+table.rawget(i).get("key4"));
LuaValue key5 = table.rawget(i).get("key5");
if( !key5.isnil())
LuaValue[] keys = key5.checktable().keys();
for (int j = 0; j<keys.length; j++)
代码示例来源:origin: M66B/XPrivacyLua
/**
* Get the next element after a particular key in the
* contiguous array part of a table
* @return key,value or none
*/
public Varargs inext(LuaValue key) {
int k = key.checkint() + 1;
LuaValue v = rawget(k);
return v.isnil()? NONE: varargsOf(LuaInteger.valueOf(k),v);
}
代码示例来源:origin: mirkosertic/GameComposer
@Override
public LuaValue get( int key ) {
LuaValue v = rawget(key);
return v.isnil() && m_metatable!=null? gettable(this,valueOf(key)): v;
}
代码示例来源:origin: com.cloudera.kitten/kitten-common
public Map<String, String> asMap() {
Map<String, String> map = Maps.newHashMap();
for (LuaValue lv : env.keys()) {
map.put(lv.tojstring(), env.get(lv).tojstring());
}
return map;
}
代码示例来源:origin: info.bliki.wiki/bliki-core
public LuaValue getAllArguments() {
LuaTable table = new LuaTable();
for (Map.Entry<String, String> entry: templateParameters.entrySet()) {
try {
final int numberedParam = Integer.parseInt(entry.getKey());
table.set(LuaValue.valueOf(numberedParam), toLuaString(entry.getValue()));
} catch (NumberFormatException e) {
table.set(toLuaString(entry.getKey()), toLuaString(entry.getValue()));
}
}
return table;
}
内容来源于网络,如有侵权,请联系作者删除!