lua-users home
lua-l archive

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

> 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_pushnumber(l, 1);	//Index