예제 #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();
  }
  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;
  }