/** * Callback used during tail call processing to invoke the function once. * <p> * This may return a {@link TailcallVarargs} to be evaluated by the client. * <p> * This should not be called directly, instead use one of the call invocation functions. * * @param args the arguments to the call invocation. * @return Varargs the return values, possible a TailcallVarargs. * @see LuaValue#call() * @see LuaValue#invoke() * @see LuaValue#method(LuaValue) * @see LuaValue#invokemethod(LuaValue) */ public Varargs onInvoke(Varargs args) { return invoke(args); }
/** * Callback used during tail call processing to invoke the function once. * <p> * This may return a {@link TailcallVarargs} to be evaluated by the client. * <p> * This should not be called directly, instead use one of the call invocation functions. * * @param args the arguments to the call invocation. * @return Varargs the return values, possible a TailcallVarargs. * @see LuaValue#call() * @see LuaValue#invoke() * @see LuaValue#method(LuaValue) * @see LuaValue#invokemethod(LuaValue) */ public Varargs onInvoke(Varargs args) { return invoke(args); }
/** * Callback used during tail call processing to invoke the function once. * <p> * This may return a {@link TailcallVarargs} to be evaluated by the client. * <p> * This should not be called directly, instead use one of the call invocation functions. * * @param args the arguments to the call invocation. * @return Varargs the return values, possible a TailcallVarargs. * @see LuaValue#call() * @see LuaValue#invoke() * @see LuaValue#method(LuaValue) * @see LuaValue#invokemethod(LuaValue) */ public Varargs onInvoke(Varargs args) { return invoke(args); }
/** Call {@code this} with 0 arguments, including metatag processing, * and retain all return values in a {@link Varargs}. * <p> * If {@code this} is a {@link LuaFunction}, call it, and return all values. * Otherwise, look for the {@link #CALL} metatag and call that. * <p> * To get a particular return value, us {@link Varargs#arg(int)} * <p> * To call {@code this} as a method call, use {@link #invokemethod(LuaValue)} instead. * * @return All return values as a {@link Varargs} instance. * @throws LuaError if not a function and {@link #CALL} is not defined, * or the invoked function throws a {@link LuaError} * or the invoked closure throw a lua {@code error} * @see #call() * @see #invoke(Varargs) * @see #invokemethod(String) * @see #invokemethod(LuaValue) */ public Varargs invoke() { return invoke(NONE); }
/** Call {@code this} with 0 arguments, including metatag processing, * and retain all return values in a {@link Varargs}. * <p> * If {@code this} is a {@link LuaFunction}, call it, and return all values. * Otherwise, look for the {@link #CALL} metatag and call that. * <p> * To get a particular return value, us {@link Varargs#arg(int)} * <p> * To call {@code this} as a method call, use {@link #invokemethod(LuaValue)} instead. * * @return All return values as a {@link Varargs} instance. * @throws LuaError if not a function and {@link #CALL} is not defined, * or the invoked function throws a {@link LuaError} * or the invoked closure throw a lua {@code error} * @see #call() * @see #invoke(Varargs) * @see #invokemethod(String) * @see #invokemethod(LuaValue) */ public Varargs invoke() { return invoke(NONE); }
@Override public synchronized void run() { try { Varargs a = this.args; this.args = LuaValue.NONE; this.result = function.invoke(a); } catch (Throwable t) { this.error = t.getMessage(); } finally { this.status = LuaThread.STATUS_DEAD; } } }
public synchronized void run() { try { Varargs a = this.args; this.args = LuaValue.NONE; this.result = function.invoke(a); } catch (Throwable t) { this.error = t.getMessage(); } finally { this.status = LuaThread.STATUS_DEAD; this.notify(); } }
public synchronized void run() { try { Varargs a = this.args; this.args = LuaValue.NONE; this.result = function.invoke(a); } catch (Throwable t) { this.error = t.getMessage(); } finally { this.status = LuaThread.STATUS_DEAD; this.notify(); } }
public void call(String functionName, LuaValue[] args) { globals.get(functionName).invoke(args); }
public void call(String functionName, LuaValue[] args) { globals.get(functionName).invoke(args); }
private void execute(String when, MethodHookParam param) { Log.i(TAG, "Dynamic invoke " + param.method); List<LuaValue> values = new ArrayList<>(); values.add(LuaValue.valueOf(when)); values.add(CoerceJavaToLua.coerce(new XParam(context, param, settings))); for (int i = 4; i <= args.narg(); i++) values.add(args.arg(i)); args.arg(3).invoke(values.toArray(new LuaValue[0])); } });
public Varargs invoke(Varargs args) { LuaValue func = args.checkvalue(1); if (globals != null && globals.debuglib != null) globals.debuglib.onCall(this); try { return varargsOf(TRUE, func.invoke(args.subargs(2))); } catch ( LuaError le ) { final LuaValue m = le.getMessageObject(); return varargsOf(FALSE, m!=null? m: NIL); } catch ( Exception e ) { final String m = e.getMessage(); return varargsOf(FALSE, valueOf(m!=null? m: e.toString())); } finally { if (globals != null && globals.debuglib != null) globals.debuglib.onReturn(); } } }
public Varargs invoke(Varargs args) { LuaValue func = args.checkvalue(1); if (globals != null && globals.debuglib != null) { globals.debuglib.onCall(this); } try { return varargsOf(TRUE, func.invoke(args.subargs(2))); } catch (LuaError le) { final LuaValue m = le.getMessageObject(); return varargsOf(FALSE, m != null ? m : NIL); } catch (Exception e) { final String m = e.getMessage(); return varargsOf(FALSE, valueOf(m != null ? m : e.toString())); } finally { if (globals != null && globals.debuglib != null) { globals.debuglib.onReturn(); } } } }
@Test public void testLuaRunner() { String luaScript = Utils.toString(new File("lua_test/test.lua")); Globals globals = JsePlatform.standardGlobals(); LuaValue value = globals.load(luaScript); value.invoke(); }
@Override public Varargs invoke(Varargs args) { LuaValue func = args.checkvalue(1); if (globals != null && globals.debuglib != null) globals.debuglib.onCall(this); try { return varargsOf(TRUE, func.invoke(args.subargs(2))); } catch ( LuaError le ) { final String m = le.getMessage(); return varargsOf(FALSE, m!=null? valueOf(m): NIL); } catch ( Exception e ) { final String m = e.getMessage(); return varargsOf(FALSE, valueOf(m!=null? m: e.toString())); } finally { if (globals != null && globals.debuglib != null) globals.debuglib.onReturn(); } } }
/** * Simple wrapper for invoking a lua function with command line arguments. * The supplied function is first given a new Globals object, * then the program is run with arguments. */ public static void luaMain(LuaValue mainChunk, String[] args) { Globals g = standardGlobals(); int n = args.length; LuaValue[] vargs = new LuaValue[args.length]; for (int i = 0; i < n; ++i) vargs[i] = LuaValue.valueOf(args[i]); LuaValue arg = LuaValue.listOf(vargs); arg.set("n", n); g.set("arg", arg); mainChunk.initupvalue1(g); mainChunk.invoke(LuaValue.varargsOf(vargs)); } }
/** Simple wrapper for invoking a lua function with command line arguments. * The supplied function is first given a new Globals object as its environment * then the program is run with arguments. * @return {@link Varargs} containing any values returned by mainChunk. */ public static Varargs luaMain(LuaValue mainChunk, String[] args) { Globals g = standardGlobals(); int n = args.length; LuaValue[] vargs = new LuaValue[args.length]; for (int i = 0; i < n; ++i) vargs[i] = LuaValue.valueOf(args[i]); LuaValue arg = LuaValue.listOf(vargs); arg.set("n", n); g.set("arg", arg); mainChunk.initupvalue1(g); return mainChunk.invoke(LuaValue.varargsOf(vargs)); } }
public Varargs invoke(Varargs args) { args.argcheck(args.isstring(1) || args.isnil(1), 1, "filename must be string or nil"); String filename = args.isstring(1)? args.tojstring(1): null; Varargs v = filename == null? loadStream( globals.STDIN, "=stdin", "bt", globals ): loadFile( args.checkjstring(1), "bt", globals ); return v.isnil(1)? error(v.tojstring(2)): v.arg1().invoke(); } }
public Varargs invoke(Varargs args) { args.argcheck(args.isstring(1) || args.isnil(1), 1, "filename must be string or nil"); String filename = args.isstring(1) ? args.tojstring(1) : null; Varargs v = filename == null ? loadStream(globals.STDIN, "=stdin", "bt", globals) : loadFile(args.checkjstring(1), "bt", globals); return v.isnil(1) ? error(v.tojstring(2)) : v.arg1().invoke(); } }
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())); } }