lua-users home
lua-l archive

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


Hi Christian,

Thanks for your immediate repy

>unfortunately, there does not seem to be any other documentation
>available. I could provide some examples from my own application, if
>you think that they would help.

Oh yes, that would be fine, thanks in advance!
>
>>    - Java methods will only show up if they have been expli-
>>      citly accessed before
>
>Yes, that is the intended behavior. The lua tables cache the
>references to the Java methods, because obtaining them with the Java
>reflection API is a fairly expensive operation. As far as I can see,
>this is the only reason why these tables are there in the first
>place.

Well, as my idea is to present an interface  (to the Lua program-
mer) which maps a single (Lua) table index (e.g. LuaVar[Slot]) on
appropriate (Java)  set/get-methods  (such as JavaObj.setSlot and 
JavaObj.getSlot) I'm not really unhappy about this behaviour.

Currently,  I plan to use  "gettable" and "settable"  tag methods
for that purpose.  Is it possible to assign a "tag"  to Java pro-
xies (sorry for that silly question - I'll find it out myself)

Instead of letting the Lua programmer accessing Java directly,  I
will therefore offer a "library" of Lua objects which perform the
necessary interfacing themselves in an optimized way (the Lua ob-
ject will "know" anything about the underlying Java object)

Real question (plain Lua) now: how can I achieve,  that (Lua) ta-
ble indices which I have "simulated"  using gettable/settable tag
methods appear in a "for key,value in table" loop?

>>    - even then, I sometimes get a "LuaException" (e.g., if
>>      I try to examine a jawa.AWT.Frame object)
>
>I have never seen anything like that, unless there was some kind of
>programmer error. Could you please be more specific?

Oh yes, here is the code (typed in manually as the code has been tes-
ted on a different machine):

  local Window = javaNewInstance("java.awt.Frame","(test)");
  Window:show();

  print(type(Window));
  print("Title = "..Window:getTitle());

  local Key,Value;
  for Key,Value in Window do
    print("  "..Key..": "..Value);   -- throws an exception!
  end;

  Window:dispose(); -- will not be reached

Printing the "Key" within the "for" loop works fine, however, try-
ing to access the "Window" object yields a LuaException... (I also
tried Window[Key] with the same result)

>P.S. I have not forgotten about your other message re hash tables. I
>need a little time to think it over, and to compose my reply with a
>detailed explnation, because the whole situation is actually pretty
>complicated.

Oh well,  anything which prevents me  from having to do some work is
welcome ;-)

Kind regards,

Andreas Rozek         Phone:  ++49 (7031) 222305
Bunsenstraße 82       Fax:    -
D-71032 Böblingen     EMail:  A.Rozek@GMX.De
Germany               URL:    http://www.Andreas-Rozek.de