Menu

#29 CoerceJavaToLua.coerce of LuaTables return userdata

v3.0-beta1
closed-fixed
nobody
None
2
2015-01-28
2014-04-27
bonustree
No

In my current project I have a java class that contains methods that return LuaTables.

Like so.

public LuaTable getTable() {
    return myTable;
}

The problem is that when I call this method from Lua I get a userdata version of the table and need to access it the same way I would in Java.

function myLuaFunction(udata)
    print(type(udata:getTable())) -- userdata
end

I modified a few lines in CoerceJavaToLua and came up with a simple fix like this within the static initializer.

static {
    // ...
    Coercion luaValueCoercion = new Coercion() {
        public LuaValue coerce( Object javaValue ) {
            return (LuaValue) javaValue;
        }
    } ;
    // ...
    COERCIONS.put( LuaTable.class, luaValueCoercion );
}

I assume the same could be done for LuaFunction and other lua types too.

Discussion

  • James Roseborough

    • status: open --> closed-fixed
     
  • James Roseborough

    This should be fixed in the 3.0 release. Any value that inherits form LuaValue will now be passed through from Java to Lua without any modification.

     

Log in to post a comment.