Extern static members
Monkey Forums/Monkey Bug Reports/Extern static members
| ||
Hi, I've tried to extern a static member and I can't get its value. In my java file I have class MyClass { public final static int MY_MEMBER = 1; ... } In my monkey file I have Extern Class MyClass Const MY_MEMBER:Int ... End When I try to use my static member in my monkey's project, I call in a function the static member like this and the value is not present Print "member:"+MyClass.MY_MEMBER In the output file Monkey.java after preprocess, there's no trace of MyClass.MY_MEMBER, the expression was clean during the preprocessor processing. One solution to get it work is to change static member by static function I have in my java file class MyClass { public static int int MY_MEMBER { return 1; } ... } and in my monkey file Extern Class MyClass Function MY_MEMBER:Int() ... End This configuration works and I can make call like static member MyClass.MY_MEMBER I think there's a bug with Extern static member. I work with v79e release on android target. |
| ||
Try using 'Global', eg:Extern Class MyClass Global MY_MEMBER:Int ... End But yes, there are currently problems with Const in extern classes, the main issue being they trip up monkey's const optimizer/evaluator. Even when fixed, they could cause problems in java, eg: while( T.something ){ } blah.. ...where 'something' is a const bool may trigger the dreaded 'unreachable code' in java targets. I'll have a closer look at this when I get some time, but using 'Global' instead should do the trick in most situations. |