[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: is this valid?
- From: Tomas <tomas@...>
- Date: Tue, 12 Aug 2003 12:11:47 -0300 (BRT)
> I want to pass an array of userdata to a lua script, can I do it this way?
>
> In c:
> lua_newtable(l);
> lua_pushstring(l, "1"); //Index
> lua_pushlightuserdata(l,data);
> lua_settable(l,-3)
> ....
> lua_setglobal(l, "list");
> lua_pushnumber(l,number_of_values);
> lua_setglobal(l,"number");
>
> And then in lua script:
>
> for i=1,number do
> do something with list[i]....
You've pushed a string index, so you have to
index with strings:
do something with list[tostring(i)]
Or you can use number keys:
lua_newtable(l);
lua_pushnumber(l, 1); //Index
...
Tomas