Esempio n. 1
0
  /**
   * 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);
  }