Exemplo n.º 1
0
  /** @param args */
  public Page(String name) {
    LuaState mLuaState = LuaStateFactory.newLuaState();
    pagename = name;

    mLuaState.openLibs();
    luastate = mLuaState;
  }
Exemplo n.º 2
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();
  }
Exemplo n.º 3
0
 @Override
 public void onDestroy() {
   luastate.close();
   root.Ondestroy();
   System.gc();
 }
  private List<ICompletionProposal> getInternalProposals(LuaVariableDetector wordPart) {
    LuaState L = LuaScriptsSpecs.getDefault().getLuaState();

    if (L == null) {
      return Collections.emptyList();
    }

    try {
      if (wordPart.getVariable() != null) {
        L.LdoString("return " + wordPart.getVariable());
      } else {
        L.getGlobal("_G");
      }
    } catch (Throwable e) {
      e.printStackTrace();
      return Collections.emptyList();
    }

    if (!L.isTable(-1)) {
      L.pop(1);
      return Collections.emptyList();
    }

    String stem = wordPart.getString();
    int wordOffset = wordPart.getOffset();

    ImageRegistry imageRegistry = BaseExtsPlugin.getDefault().getImageRegistry();

    ArrayList<ICompletionProposal> internalList = new ArrayList<ICompletionProposal>();

    L.pushNil();
    while (L.next(-2) != 0) {
      String key = L.toString(-2);

      if (!key.startsWith(wordPart.getString())) {

        String contextKey = null;
        if (wordPart.getVariable() != null) {
          contextKey = wordPart.getVariable() + "." + key;
        } else {
          contextKey = key;
        }

        String strLuaType = L.typeName(L.type(-1));
        // load function.gif, table.gif or string.gif
        Image image = imageRegistry.get(strLuaType);

        int cursorLocation = key.length();

        // To functions, use de ().
        if (FUNCTION_TYPE_NAME.equals(strLuaType)) {
          key += "()";
          cursorLocation += 1; // Put cursor inside "()"
        }

        IContextInformation info;
        info = new ContextInformation(contextKey, getContentInfoString(contextKey));

        ICompletionProposal proposal =
            new CompletionProposal(
                key, // Replacement string
                wordOffset,
                stem.length(), // Replacement offset & length
                cursorLocation, // Cursor location relative to offset
                image, // Display image
                key, // Display string
                info, // Context information
                getContentInfoString(key)); // Extra string information

        internalList.add(proposal);
      }
      L.pop(1); // removes `value'; keeps `key' for next iteration
    }
    L.pop(1);

    return internalList;
  }
  @Override
  public void onCreate(Bundle savedInstanceState) {

    // System.loadLibrary("luajava-1.1");

    // 設定橫向螢幕
    this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

    this.getWindow()
        .setFlags(
            WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);

    this.getWindow()
        .setFlags(
            WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON,
            WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

    this.requestWindowFeature(Window.FEATURE_NO_TITLE);

    this.registerReceiver(this.mBatInfoReceiver, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));

    L = LuaStateFactory.newLuaState();
    L.pushJavaObject(this);
    L.setGlobal("activity");

    res = getResources();
    conf = res.getConfiguration();

    conf.locale = Locale.TAIWAN;
    res.updateConfiguration(conf, null);

    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    appobject = this.getApplicationContext();

    surfaceView = (SurfaceView) findViewById(R.id.surfaceView1);
    surfaceHolder = surfaceView.getHolder();
    surfaceHolder.addCallback(this);
    surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);

    ////////////////////////////////////////////////////////////////////////////////////////////

    /*bitmap2 = BitmapFactory.decodeResource(  getResources()    , R.raw.line  );

          surfaceView2 = (SurfaceView)findViewById(R.id.surface_level );
          surfaceHolder2 = surfaceView2.getHolder();

          SurfaceHolder.Callback  level_callback  = new SurfaceHolder.Callback()
          {

    	public void surfaceChanged(SurfaceHolder holder, int format,
    			int width, int height) {
    		//需要
    		 on_level_change(new float[3]);
    	}

    	public void surfaceCreated(SurfaceHolder holder) {
    	}

    	public void surfaceDestroyed(SurfaceHolder holder) {
    	}

          };

    surfaceHolder2.addCallback(  level_callback  );
          surfaceHolder2.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);  */

    //////////////////////////////////////////////////////////////////////////////////////////

    /*  sensormanager = (SensorManager) getSystemService(SENSOR_SERVICE);
         sensors =  sensormanager.getSensorList(Sensor.TYPE_ORIENTATION);

         SensorEventListener sl =new SensorEventListener ()
         {
    public void onAccuracyChanged(Sensor sensor, int accuracy) {
    	//不需要
    }
    public void onSensorChanged(SensorEvent event) {
    	 on_level_change(event.values);
    }

         };
         sensormanager.registerListener  (   sl   ,  sensors.get(0) ,  SensorManager.SENSOR_DELAY_GAME  );
         */

    /////////////////////////////////////////////////////////////////////

    Button run_script = (Button) this.findViewById(R.id.run_script);
    run_script.setOnClickListener(
        new Button.OnClickListener() {
          public void onClick(View v) {

            if (is_video == true) {
              print_screen(res.getString(R.string.video_rec_ing));
              return;
            }

            if (is_audio == true) {
              print_screen(res.getString(R.string.audio_rec_ing));
              return;
            }

            if (lua_file == "") {
              print_screen(res.getString(R.string.file_load_no));
              return;
            }

            File f = new File("/sdcard/ez_Lua_Script_Camera/lua_scripts/" + lua_file);
            if (f.exists() == false) {
              print_screen(res.getString(R.string.file_load_fail));
              return;
            }
            ((TextView) findViewById(R.id.lua_file_screen)).setText(lua_file);
            all_pics = 0;
            ((TextView) findViewById(R.id.shutter_times_screen)).setText("拍攝張數 : 00000");
            (new lua_run()).start();
          }
        });

    Button about = (Button) this.findViewById(R.id.about);
    about.setOnClickListener(
        new Button.OnClickListener() {
          public void onClick(View v) {

            if (is_video == true) {
              print_screen(res.getString(R.string.video_rec_ing));
              return;
            }

            if (is_audio == true) {
              print_screen(res.getString(R.string.audio_rec_ing));
              return;
            }

            if (is_script_running == true) {
              print_screen(res.getString(R.string.script_running));
              return;
            }

            Intent i =
                new Intent(
                    Intent.ACTION_VIEW,
                    Uri.parse("http://dl.dropbox.com/u/61164954/homepage/ez_LSC/index.htm"));
            startActivity(i);
          }
        });

    Button audio_c = (Button) this.findViewById(R.id.audio);
    audio_c.setOnClickListener(
        new Button.OnClickListener() {
          public void onClick(View v) {

            if (is_script_running == true) {
              print_screen(res.getString(R.string.script_running));
              return;
            }

            if (is_video == true) {
              print_screen(res.getString(R.string.video_rec_ing));
              return;
            }

            if (is_audio == false) {
              print_screen(res.getString(R.string.audio_rec_start));
              CharSequence cs = res.getString(R.string.stop);
              Button keepa = (Button) findViewById(R.id.audio);
              keepa.setText(cs);
              is_audio = true;
              (new audio()).start();
            } else {
              arecorder.stop();
              is_audio = false;
              print_screen(res.getString(R.string.audio_rec_end));
              CharSequence xcs = res.getString(R.string.audio_rec);
              Button keepax = (Button) findViewById(R.id.audio);
              keepax.setText(xcs);
              camera.startPreview();
            }
          }
        });

    Button movie = (Button) this.findViewById(R.id.movie);
    movie.setOnClickListener(
        new Button.OnClickListener() {
          public void onClick(View v) {

            if (is_script_running == true) {
              print_screen(res.getString(R.string.script_running));
              return;
            }

            if (is_audio == true) {
              print_screen(res.getString(R.string.audio_rec_ing));
              return;
            }

            if (is_video == false) {
              print_screen(res.getString(R.string.video_rec_start));
              CharSequence cs = res.getString(R.string.stop);
              Button keepa = (Button) findViewById(R.id.movie);
              keepa.setText(cs);
              parameters.setFocusMode("continuous-video");
              camera.setParameters(parameters);
              is_video = true;
              (new video()).start();
            } else {
              recorder.stop();
              is_video = false;
              print_screen(res.getString(R.string.video_rec_end));
              CharSequence xcs = res.getString(R.string.video_rec);
              Button keepax = (Button) findViewById(R.id.movie);
              keepax.setText(xcs);
              camera.lock();
              camera.release();
              camera = Camera.open();
              parameters = camera.getParameters();
              parameters.setPreviewSize(640, 480);
              parameters.setPreviewFrameRate(30);
              parameters.setJpegQuality(100);
              parameters.setFocusMode("continuous-video");
              parameters.setPictureSize(2048, 1536);
              camera.setParameters(parameters);
              try {
                camera.setPreviewDisplay(surfaceHolder);
              } catch (IOException e) {
              }
              camera.startPreview();
            }
          }
        });

    Button lua = (Button) this.findViewById(R.id.lua);
    lua.setOnClickListener(
        new Button.OnClickListener() {
          public void onClick(View v) {

            if (is_script_running == true) {
              print_screen(res.getString(R.string.script_running));
              return;
            }

            if (is_audio == true) {
              print_screen(res.getString(R.string.audio_rec_ing));
              return;
            }

            if (is_video == true) {
              print_screen(res.getString(R.string.video_rec_ing));
              return;
            }
            show_choose_Dialog();
          }
        });

    test_caller();
    load_config();

    try {
      player.setDataSource("/sdcard/ez_Lua_Script_Camera/sound/shuttersound.ogg");
    } catch (IllegalArgumentException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (IllegalStateException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }

    try {
      shutter_trigger.setDataSource("/sdcard/ez_Lua_Script_Camera/sound/trigger.wav");
    } catch (IllegalArgumentException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (IllegalStateException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }