lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


I'm trying to create a Java array from Lua (or, probably more 
precisely, a Lua proxy for a Java array).  However, I am having
problems and wonder if anyone might have suggestions.

Not seeing a Lua method that provides for this directly, I thought I 
would try something like the following:

Array = javaBindClass("java.lang.reflect.Array")
Object = javaBindClass("java.lang.Object")
an_array = Array:newInstance(Object, 10)

This doesn't work.  It generally causes java to crash with the 
following message:

JNI panic: JNI received a null string
        at lua.API.doString(
        at Lua.main(

If I run java from within jdb, I can get this nice little stack

Uncaught exception: java.lang.VerifyError       at
        at lua.LuaWrapperBuilder.loadClass(
        at java.lang.ClassLoader.loadClass(
        at lua.ToLua.createLuaWrapper(
        at lua.ToLua.tryMatch(
        at lua.ToLua.getMatchingMethod(
        at lua.ToLua.access$12(
        at lua.ToLua$
        at lua.API.doString(
        at Lua.main(

In the lua.LuaWrapperBuilder.loadClass method, the code is following
the path that has it call buildWrapper(), and defineClass().  The
cls it is trying to build is ClassWrapperForLua.

With the java -v (verbose) switch I get the following output:

[Resolving ClassWrapperForLua]
Class ClassWrapperForLua is subclass of final class java/lang/Class

Could this be the problem?  The verifier is complaining because this
generated class is subclassing a final class?  (It certainly doesn't
have any problems with other classes - e.g., ActionListener.)

With java -noverify I get the following:

lua error: java.lang.reflect.Array.newInstance:
Active Stack:
  (C code)
  main of file `javaarray.lua'
  function `dofile' [(C code)]
  main of string `dofile "javaarray.lua"'

I would appreciate any pointers (e.g., the correct way to create arrays,
what is wrong with this method, why does the ClassLoader think
that this is an invalid class, how to work around this error, etc.).  



PS - BTW, I am using Lua 3.2.2 and JDK 1.1.8

PPS - This is my first post to the ML, so I need to mention that 
I think Lua is great!  Thanks!