Is there any way to force an integer type using LuaJava? I am attempting, in LuaJ 3.0 beta 1 (luaj-jse-3.0-beta1.jar)
, to create an instance of a java.awt.Color
. You wouldn't think this would be such an issue, given the Java API availability of constructors (JavaAPI). The reason I am interested in forcing an integer into the constructor is that the Color
constructors available take three and four arguments of either int
or float
. Since Lua's number type is double
, LuaJ (or LuaJava) calls the float
versions of the constructors.
At first, I thought this wasn't going to be a problem, but after trying to use it, I noticed that I was receiving an errant Color
. The values were not being passed properly into the constructor, and Color
object was essentially broken, with no discernible error (it didn't crash anything, it just didn't display).
Here's a quick example:
local j_color = luajava.newInstance( "java.awt.Color", r, g, b );
print( j_color );
If I pass r = 1.0
, g = 0.2
, b = 0.2
to this constructor, and then print j_color
, I will see
java.awt.Color[r=0,g=0,b=1]
in the output. In fact, I can use anything I want in r
and g
as long as b = 0
, with no problem, but otherwise, it causes pain and suffering.
I am a little curious to know if anyone else has encountered this problem. If it doesn't resolve, I will contact the PI on the LuaJ project about it, and report back.
As a side note: it would be a simple matter to construct a solution by which I use a custom-made Java function to be responsible for creating the Color
. I am more concerned that this problem exists, and whether there is some way to either specify which constructor you want to use, or to explicitly tell LuaJava to use integers, rather than doubles.
Update
I have also attempted to use the four-float constructor, and the same issue appears. If I pass in one of the following values: alpha=0, 0.5, 1
the constructor functions properly. Anything else will yield the result above.