Refine search
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; }
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; }
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()); } } } }
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; } }
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); } } }
/** 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); }
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; }
@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; }
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++)
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; }