[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Table + LuaJava
- From: "Robert G. Jakabosky" <bobby@...>
- Date: Mon, 8 Jun 2009 21:16:02 -0700
On Monday 08, Anselmo Junior wrote:
> Hello folks,
>
> I'm new in Lua and i need some help with tables in lua and java interchange
What java API/bindings are you using to access Lua?
> In Lua script I made like that:
>
> --init
> function init()
> local t = {}
> t[03] = "3"
> t[11] = "19"
> t[12] = "25"
> return trn
> end
Those are numeric keys.
That table will contain:
{
[3] = "3",
[11] = "19",
[12] = "25"
}
Also the return is using the wrong variable name.
>
> And java I made:
>
> public void test() {
> state.getGlobal("init");
> state.call(0, 1);
> LuaObject lo = state.getLuaObject(1);
> state.pop(1);
> try {
> lo.getField("03");
> System.out.println(lo.getField("03").getNumber());
> } catch (LuaException e) {
> e.printStackTrace();
> }
> }
>
> "state" is a LuaState object that have been instanciate in Class
> Constructor.
> "lo" returned a Lua Table, but if I pass getField("03") returned nil value
Here you are trying to get a string key "03" from a table that only has
numeric keys. I don't know what Java API you are using to access Lua, but
there should be a way to get numeric keys from the table.
> But i really need get not only the value of the table, but the keys too...
> because the keys will be random. Get the table's keys in java code it is
> possible?
>
> I will appreciate if anyone could help me...
--
Robert G. Jakabosky