コード例 #1
0
ファイル: EventHelper.java プロジェクト: nadar71/Corona
  static void dispatchEvent(
      final LuaValueProxy listener, final String event, final String message) {
    if (listener == null || runtime == null || runtime.wasDisposed()) {
      return;
    }

    LuaState luaState = runtime.getLuaState();
    if (!luaState.isOpen()) {
      return;
    }

    final CoronaRuntimeTaskDispatcher dispatcher = new CoronaRuntimeTaskDispatcher(luaState);
    CoronaEnvironment.getCoronaActivity()
        .runOnUiThread(
            new Runnable() {
              @Override
              public void run() {
                CoronaRuntimeTask task =
                    new CoronaRuntimeTask() {
                      @Override
                      public void executeUsing(CoronaRuntime runtime) {
                        try {
                          LuaState luaState = runtime.getLuaState();
                          if (!luaState.isOpen() || listener == null) {
                            return;
                          }

                          listener.pushValue();

                          try {
                            luaState.checkType(-1, com.naef.jnlua.LuaType.FUNCTION);
                          } catch (Exception ex) {
                            ex.printStackTrace();
                            return;
                          }

                          int luaFunctionReferenceKey =
                              luaState.ref(com.naef.jnlua.LuaState.REGISTRYINDEX);
                          luaState.rawGet(
                              com.naef.jnlua.LuaState.REGISTRYINDEX, luaFunctionReferenceKey);
                          luaState.unref(
                              com.naef.jnlua.LuaState.REGISTRYINDEX, luaFunctionReferenceKey);
                          luaState.newTable();
                          luaState.pushString("plugin.tapfortap.event");
                          luaState.setField(-2, "name");
                          luaState.pushString(event);
                          luaState.setField(-2, "event");
                          luaState.pushString(message);
                          luaState.setField(-2, "message");

                          luaState.call(1, 0);
                        } catch (Exception ex) {
                          ex.printStackTrace();
                        }
                      }
                    };
                dispatcher.send(task);
              }
            });
  }
コード例 #2
0
 public final int invoke(LuaState luaState) {
   CoronaActivity coronaActivity = CoronaEnvironment.getCoronaActivity();
   int checkInteger = luaState.checkInteger(1);
   String checkString = luaState.checkString(2);
   if (checkInteger != 0) {
     coronaActivity.runOnUiThread(new p(this, coronaActivity, checkString, checkInteger));
   }
   return 0;
 }
コード例 #3
0
ファイル: LuaConsole.java プロジェクト: robinzheng/koneki.ldt
 /** Runs a chunk of Lua code from an input stream. */
 protected void runChunk(InputStream in) throws IOException {
   try {
     long start = System.nanoTime();
     luaState.setTop(0);
     luaState.load(in, "console");
     luaState.call(0, LuaState.MULTRET);
     long stop = System.nanoTime();
     for (int i = 1; i <= luaState.getTop(); i++) {
       if (i > 1) {
         System.out.print(", ");
       }
       switch (luaState.type(i)) {
         case BOOLEAN:
           System.out.print(Boolean.valueOf(luaState.toBoolean(i)));
           break;
         case NUMBER:
         case STRING:
           System.out.print(luaState.toString(i));
           break;
         default:
           System.out.print(luaState.typeName(i));
       }
     }
     System.out.print("\t#msec=");
     System.out.print(String.format("%.3f", (stop - start) / 1000000.0));
     System.out.println();
   } catch (LuaRuntimeException e) {
     e.printLuaStackTrace();
     e.printStackTrace();
   } catch (LuaException e) {
     System.err.println(e.getMessage());
   }
 }
コード例 #4
0
 public int invoke(LuaState luaState) {
   String checkString = luaState.checkString(1);
   String checkString2 = luaState.checkString(2);
   if (!(checkString == null
       || checkString2 == null
       || i.a.equals(checkString)
       || i.a.equals(checkString2))) {
     if (CoronaLtvManager.a == null) {
       CoronaLtvManager.a = new HashMap();
     }
     CoronaLtvManager.a.put(checkString, checkString2);
     Log.d("SendLtvConversion", "AddParam key : " + checkString + ", value : " + checkString2);
   }
   return 0;
 }
コード例 #5
0
ファイル: LuaConsole.java プロジェクト: robinzheng/koneki.ldt
  /**
   * Creates a new instance with the specified command line arguments. The arguments are passed to
   * Lua as the <code>argv</code> global variable.
   *
   * @param args
   */
  public LuaConsole(String[] args) {
    luaState = new LuaState();

    // Process arguments
    luaState.newTable(args.length, 0);
    for (int i = 0; i < args.length; i++) {
      luaState.pushString(args[i]);
      luaState.rawSet(-2, i + 1);
    }
    luaState.setGlobal("argv");

    // Open standard libraries
    luaState.openLibs();

    // Set buffer mode
    luaState.load("io.stdout:setvbuf(\"no\")", "setvbuf");
    luaState.call(0, 0);
    luaState.load("io.stderr:setvbuf(\"no\")", "setvbuf");
    luaState.call(0, 0);
  }
コード例 #6
0
 public int invoke(LuaState luaState) {
   CoronaActivity coronaActivity = CoronaEnvironment.getCoronaActivity();
   coronaActivity.runOnUiThread(new q(this, coronaActivity, luaState.checkString(1)));
   return 0;
 }