lua-users home
lua-l archive

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


> What java API/bindings are you using to access Lua?
Its LuaJava: http://www.keplerproject.org/luajava/

> Those are numeric keys.
> That table will contain:
> {
> [3] = "3",
> [11] = "19",
> [12] = "25"
> }
>
> Also the return is using the wrong variable name.
Sorry for my mistake, i actually return the correct variable, i only copy wrong code here... and is numeric key, and i'd like to be like that.

> 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.
In LuaJava, the LuaState object has the same methods that is in C. If you know how to do is in C, i think we can do it with LuaState in java.
I try replace in lua script the line "t[03] = "3"" for "t["03"] = "3"" and really work, i get the number "3" (the value of key "03"), but i'd like to use numeric keys.

Thanks for reply.
 

2009/6/9 Robert G. Jakabosky <bobby@sharedrealm.com>
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