Passing Java Enum type to a Lua function

Help
phoey01
2013-11-26
2013-12-05
  • phoey01
    phoey01
    2013-11-26

    Hello,

    I am trying to access a public static enum from one of my Java classes as a parameter in my Lua script.

    //JAVA
    //com.entities.java
          public static enum ACTIONS{
                LEAVE,
                LOOK,
                TURN;
          }
    //LUA
    function create(entity)
        local entities =  luajava.bindClass("com.entities")
        entity:addActionItemToBeginning(0,entities.ACTIONS.TURN)
    end
    

    Issue is with the "entity:addActionItemToBeginning(0,entities.ACTIONS.TURN)" line.
    I keep getting a "attempt to index ? (a nil value)" on the last line. I can't figure out how to access the scope of the enum.

    Any help would be appreciated.

     
  • Ian Farmer
    Ian Farmer
    2013-12-05

    Java enums are classes, so the argument to bindClass needs to be the fully qualified name of the enum. So if your ACTIONS enum is defined within a class named "entities" in the file com/entities.java, then you need to call luajava.bindClass("com.entities$ACTIONS")