示例#1
0
  public static void main(String[] main_args) throws LuaException, ClassNotFoundException {
    LuaState L = LuaStateFactory.newLuaState();
    L.openBase();

    L.LdoString(str);

    LuaObject func = L.getLuaObject("imprime");
    Object[] teste = func.call(new Object[] {"TESTANDO"}, 2);
    System.out.println(teste[0]);
    System.out.println(teste[1]);

    System.out.println("PROXY TEST :");
    Printable p = new ObjPrint();
    p.print("TESTE 1");

    LuaObject o = L.getLuaObject("luaPrint");
    p = (Printable) o.createProxy("org.keplerproject.luajava.test.Printable");
    p.print("Teste 2");

    L.close();
  }
示例#2
0
  public void onServiceConnected(ComponentName name, IBinder iservice) {
    Log.d("lua", "setting activity");
    service = ((Lua.LocalBinder) iservice).getService();
    modTable = service.require(modName);
    if (modTable == null) {
      finish();
      return;
    }

    service.setGlobal("current_activity", this);

    Object res;
    Object arg = null;
    if (argRef != 0) {
      arg = LuaObject.fromReference(Lua.L, argRef);
    }
    try {
      if (modTable.isFunction()) {
        LuaObject android = service.require("android");
        LuaObject aNew = android.getField("new");
        res = aNew.call(new Object[] {modTable});
        modTable = (LuaObject) res;
      }
      res = service.invokeMethod(modTable, "onCreate", this, arg, state);
    } catch (LuaException e) {
      log("onCreate " + e.getMessage());
      res = null;
    }
    if (res == null) {
      finish();
      return;
    }
    if (res instanceof View) {
      setContentView((View) res);
    } else if (!(res instanceof Boolean)) {
      log("onCreate must return a View");
      finish();
      return;
    }

    service.invokeMethod(modTable, "onStart");
    if (state != null) {
      super.onRestoreInstanceState(state);
    }
    service.invokeMethod(modTable, "onResume");
  }