/** Tests if argument i is a function. * @param i the index of the argument to test, 1 is the first argument * @return true if the argument exists and is a function or closure, false otherwise * @see LuaValue#TFUNCTION * */ public boolean isfunction(int i) { return arg(i).isfunction(); }
/** Tests if argument i is a function. * @param i the index of the argument to test, 1 is the first argument * @return true if the argument exists and is a function or closure, false otherwise * @see LuaValue#TFUNCTION * */ public boolean isfunction(int i) { return arg(i).isfunction(); }
/** Tests if argument i is a function. * @param i the index of the argument to test, 1 is the first argument * @return true if the argument exists and is a function or closure, false otherwise * @see LuaValue.TFUNCTION * */ public boolean isfunction(int i) { return arg(i).isfunction(); }
@Override public void rawset(LuaValue key, LuaValue value) { if (value.isfunction()) super.rawset(key, value); else error("Globals not allowed: " + key + "=" + value); } }
@Override public void set(int key, LuaValue value) { if (value.isfunction()) super.set(key, value); else error("Globals not allowed: set " + value); }
@Override public void rawset(int key, LuaValue value) { if (value.isfunction()) super.rawset(key, value); else error("Globals not allowed: rawset " + value); }
@Override public LuaValue call(LuaValue callback) { if (callback.isfunction()) { plugin.setLoadCB(callback.checkfunction()); } else { throw new LukkitPluginException("There was an issue registering the onLoad callback - was provided a " + callback.typename() + " instead of a function."); } return LuaValue.NIL; } });
@Override public LuaValue call(LuaValue callback) { if (callback.isfunction()) { plugin.setEnableCB(callback.checkfunction()); } else { throw new LukkitPluginException("There was an issue registering the onEnable callback - was provided a " + callback.typename() + " instead of a function."); } return LuaValue.NIL; } });
@Override public LuaValue call(LuaValue callback) { if (callback.isfunction()) { plugin.setDisableCB(callback.checkfunction()); } else { throw new LukkitPluginException("There was an issue registering the onDisable callback - was provided a " + callback.typename() + " instead of a function."); } return LuaValue.NIL; } });
public Varargs invoke(Varargs args) { String name = args.checkjstring(1); String classname = toClassname( name ); Class c = null; LuaValue v = null; try { c = Class.forName(classname); v = (LuaValue) c.newInstance(); if (v.isfunction()) ((LuaFunction)v).initupvalue1(globals); return varargsOf(v, globals); } catch ( ClassNotFoundException cnfe ) { return valueOf("\n\tno class '"+classname+"'" ); } catch ( Exception e ) { return valueOf("\n\tjava load failed on '"+classname+"', "+e ); } } }
public Varargs invoke(Varargs args) { String name = args.checkjstring(1); String classname = toClassname( name ); Class c = null; LuaValue v = null; try { c = Class.forName(classname); v = (LuaValue) c.newInstance(); if (v.isfunction()) ((LuaFunction)v).initupvalue1(globals); return varargsOf(v, globals); } catch ( ClassNotFoundException cnfe ) { return valueOf("\n\tno class '"+classname+"'" ); } catch ( Exception e ) { return valueOf("\n\tjava load failed on '"+classname+"', "+e ); } } }
/** 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); }
/** 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); }
/** caller must ensure key is not nil */ @Override 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); }
/** get value from metatable operations, or NIL if not defined by metatables */ protected static LuaValue gettable(LuaValue t, LuaValue key) { LuaValue tm; int loop = 0; do { if (t.istable()) { LuaValue res = t.rawget(key); if ((!res.isnil()) || (tm = t.metatag(INDEX)).isnil()) return res; } else if ((tm = t.metatag(INDEX)).isnil()) t.indexerror(); if (tm.isfunction()) return tm.call(t, key); t = tm; } while ( ++loop < MAXTAGLOOP ); error("loop in gettable"); return NIL; }
/** get value from metatable operations, or NIL if not defined by metatables */ protected static LuaValue gettable(LuaValue t, LuaValue key) { LuaValue tm; int loop = 0; do { if (t.istable()) { LuaValue res = t.rawget(key); if ((!res.isnil()) || (tm = t.metatag(INDEX)).isnil()) return res; } else if ((tm = t.metatag(INDEX)).isnil()) t.indexerror(); if (tm.isfunction()) return tm.call(t, key); t = tm; } while ( ++loop < MAXTAGLOOP ); error("loop in gettable"); return NIL; }
/** get value from metatable operations, or NIL if not defined by metatables */ protected static LuaValue gettable(LuaValue t, LuaValue key) { LuaValue tm; int loop = 0; do { if (t.istable()) { LuaValue res = t.rawget(key); if ((!res.isnil()) || (tm = t.metatag(INDEX)).isnil()) return res; } else if ((tm = t.metatag(INDEX)).isnil()) t.indexerror(); if (tm.isfunction()) return tm.call(t, key); t = tm; } while ( ++loop < MAXTAGLOOP ); error("loop in gettable"); return NIL; }
public Varargs invoke(Varargs args) { LuaValue ld = args.arg1(); args.argcheck(ld.isstring() || ld.isfunction(), 1, "ld must be string or function"); String source = args.optjstring(2, ld.isstring()? ld.tojstring(): "=(load)"); String mode = args.optjstring(3, "bt"); LuaValue env = args.optvalue(4, globals); return loadStream(ld.isstring()? ld.strvalue().toInputStream(): new StringInputStream(ld.checkfunction()), source, mode, env); } }
public Varargs invoke(Varargs args) { LuaValue ld = args.arg1(); args.argcheck(ld.isstring() || ld.isfunction(), 1, "ld must be string or function"); String source = args.optjstring(2, ld.isstring() ? ld.tojstring() : "=(load)"); String mode = args.optjstring(3, "bt"); LuaValue env = args.optvalue(4, globals); return loadStream(ld.isstring() ? ld.strvalue().toInputStream() : new StringInputStream(ld.checkfunction()), source, mode, env); } }
public Varargs invoke(Varargs args) { LuaString name = args.checkstring(1); InputStream is = null; // get package path LuaValue path = package_.get(_PATH); if ( ! path.isstring() ) return valueOf("package.path is not a string"); // get the searchpath function. Varargs v = package_.get(_SEARCHPATH).invoke(varargsOf(name, path)); // Did we get a result? if (!v.isstring(1)) return v.arg(2).tostring(); LuaString filename = v.arg1().strvalue(); // Try to load the file. v = globals.loadfile(filename.tojstring()); if ( v.arg1().isfunction() ) return LuaValue.varargsOf(v.arg1(), filename); // report error return varargsOf(NIL, valueOf("'"+filename+"': "+v.arg(2).tojstring())); } }