Java Code Examples for org.luaj.vm2.LuaValue#call()
The following examples show how to use
org.luaj.vm2.LuaValue#call() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CollectingOrphanedCoroutines.java From luaj with MIT License | 6 votes |
public static void main(String[] args) throws InterruptedException { // This timer controls how often each Java thread wakes up and checks if // it has been orhaned or not. A large number here will produce a long // delay between orphaning and colleciton, and a small number here will // consumer resources polling for orphaned status if there are many threads. LuaThread.thread_orphan_check_interval = 500; // Should work with standard or debug globals. Globals globals = JsePlatform.standardGlobals(); // Globals globals = JsePlatform.debugGlobals(); // Should work with plain compiler or lua-to-Java compiler. // org.luaj.vm2.luajc.LuaJC.install(globals);; // Load and run the script, which launches coroutines over and over forever. LuaValue chunk = globals.load(script, "main"); chunk.call(); }
Example 2
Source File: LuaUtil.java From VideoOS-Android-SDK with GNU General Public License v3.0 | 6 votes |
public static Varargs callFunction(LuaValue target, Object... objs) { if (target != null && target.isfunction()) { LuaValue[] args = null; if (objs != null && objs.length > 0) { args = new LuaValue[objs.length]; for (int i = 0; i < objs.length; i++) { args[i] = CoerceJavaToLua.coerce(objs[i]); } } if (args != null) { return target.invoke(LuaValue.varargsOf(args)); } else { return target.call(); } } return LuaValue.NIL; }
Example 3
Source File: SimpleTests.java From luaj with MIT License | 5 votes |
private void doTest( String script ) { try { LuaValue c = globals.load(script, "script"); c.call(); } catch ( Exception e ) { fail("i/o exception: "+e ); } }
Example 4
Source File: LuajView.java From luaj with MIT License | 5 votes |
public void draw(Canvas canvas) { LuaValue f = globals.get("draw"); if (!f.isnil()) try { f.call(CoerceJavaToLua.coerce(canvas)); } catch (Exception e) { e.printStackTrace(); } else super.draw(canvas); }
Example 5
Source File: LuajavaClassMembersTest.java From luaj with MIT License | 5 votes |
public void testUniqueFactoryUncoercible() { JavaClass f = JavaClass.forClass(B.class); LuaValue constr = f.get("new"); assertEquals( JavaConstructor.class, constr.getClass() ); try { LuaValue v = constr.call(LuaValue.userdataOf(new Object())); Object b = v.touserdata(); // fail( "did not throw lua error as expected" ); assertEquals( 0, ((B)b).m_int_field ); } catch ( LuaError e ) { } }
Example 6
Source File: App.java From luaj with MIT License | 5 votes |
public static void main( String[] args ) { String script = "print('hello, world', _VERSION)"; // create an environment to run in Globals globals = JsePlatform.standardGlobals(); // Use the convenience function on the globals to load a chunk. LuaValue chunk = globals.load(script, "maven-exmaple"); // Use any of the "call()" or "invoke()" functions directly on the chunk. chunk.call(); }
Example 7
Source File: ScriptTest.java From HtmlNative with Apache License 2.0 | 5 votes |
@Test public void execute() throws Exception { Globals globals = JsePlatform.standardGlobals(); // globals.set("LCallback", new LCallback()); LuaValue value = globals.load(helloWorldScript); value.call(); }
Example 8
Source File: LuaRunner.java From HtmlNative with Apache License 2.0 | 5 votes |
@Override public void runFunction(String functionName) { LuaValue v = mGlobals.get(functionName); if (v != null) { v.call(); } }
Example 9
Source File: LuajavaClassMembersTest.java From luaj with MIT License | 5 votes |
public void testUniqueFactoryCoercible() { JavaClass c = JavaClass.forClass(B.class); assertEquals( JavaClass.class, c.getClass() ); LuaValue constr = c.get("new"); assertEquals( JavaConstructor.class, constr.getClass() ); LuaValue v = constr.call(NUMS); Object b = v.touserdata(); assertEquals( B.class, b.getClass() ); assertEquals( 123, ((B)b).m_int_field ); Object b0 = constr.call().touserdata(); assertEquals( B.class, b0.getClass() ); assertEquals( 0, ((B)b0).m_int_field ); }
Example 10
Source File: SampleJseMain.java From luaj with MIT License | 5 votes |
public static void main(String[] args) throws Exception { String script = "examples/lua/hello.lua"; // create an environment to run in Globals globals = JsePlatform.standardGlobals(); // Use the convenience function on Globals to load a chunk. LuaValue chunk = globals.loadfile(script); // Use any of the "call()" or "invoke()" functions directly on the chunk. chunk.call( LuaValue.valueOf(script) ); }
Example 11
Source File: BaseLib.java From XPrivacyLua with GNU General Public License v3.0 | 5 votes |
public LuaValue call(LuaValue arg) { LuaValue h = arg.metatag(TOSTRING); if ( ! h.isnil() ) return h.call(arg); LuaValue v = arg.tostring(); if ( ! v.isnil() ) return v; return valueOf(arg.tojstring()); }
Example 12
Source File: LuaUtil.java From VideoOS-Android-SDK with GNU General Public License v3.0 | 5 votes |
public static LuaValue getOrCallFunction(LuaValue target, LuaValue arg1, LuaValue arg2) { try { return (target != null && target.isfunction()) ? target.call(arg1, arg2) : target; } catch (Exception e) { return LuaValue.NIL; } }
Example 13
Source File: LuaUtil.java From VideoOS-Android-SDK with GNU General Public License v3.0 | 5 votes |
public static LuaValue getOrCallFunction(LuaValue target, LuaValue arg1) { try { return (target != null && target.isfunction()) ? target.call(arg1) : target; } catch (Exception e) { return LuaValue.NIL; } }
Example 14
Source File: LuaUtil.java From VideoOS-Android-SDK with GNU General Public License v3.0 | 5 votes |
/** * 调用方法或者直接取数据 * * @param target * @return */ public static LuaValue getOrCallFunction(LuaValue target) { try { return (target != null && target.isfunction()) ? target.call() : target; } catch (Exception e) { return LuaValue.NIL; } }
Example 15
Source File: BaseLib.java From luaj with MIT License | 5 votes |
public LuaValue call(LuaValue arg) { LuaValue h = arg.metatag(TOSTRING); if ( ! h.isnil() ) return h.call(arg); LuaValue v = arg.tostring(); if ( ! v.isnil() ) return v; return valueOf(arg.tojstring()); }
Example 16
Source File: LuaUtil.java From VideoOS-Android-SDK with GNU General Public License v3.0 | 5 votes |
public static LuaValue callFunction(LuaValue target, LuaValue arg1, LuaValue arg2) { try { return (target != null && target.isfunction()) ? target.call(arg1, arg2) : LuaValue.NIL; } catch (Exception e) { e.printStackTrace(); return LuaValue.NIL; } }
Example 17
Source File: LuaUtil.java From VideoOS-Android-SDK with GNU General Public License v3.0 | 5 votes |
public static LuaValue callFunction(LuaValue target, LuaValue arg1) { try { return (target != null && target.isfunction()) ? target.call(arg1) : LuaValue.NIL; } catch (Exception e) { e.printStackTrace(); return LuaValue.NIL; } }
Example 18
Source File: LuaUtil.java From VideoOS-Android-SDK with GNU General Public License v3.0 | 5 votes |
/** * call lua function * * @param target * @return */ public static LuaValue callFunction(LuaValue target) { try { return (target != null && target.isfunction()) ? target.call() : LuaValue.NIL; } catch (Exception e) { e.printStackTrace(); return LuaValue.NIL; } }
Example 19
Source File: BaseLib.java From VideoOS-Android-SDK with GNU General Public License v3.0 | 5 votes |
public LuaValue call(LuaValue arg) { LuaValue h = arg.metatag(TOSTRING); if (!h.isnil()) return h.call(arg); LuaValue v = arg.tostring(); if (!v.isnil()) return v; return valueOf(arg.tojstring()); }
Example 20
Source File: SampleUsingClassLoader.java From luaj with MIT License | 4 votes |
public Object[] launch(Reader script, Object[] arg) { LuaValue chunk = g.load(script, "main"); return new Object[] { chunk.call(LuaValue.valueOf(arg[0].toString())) }; }