Hey List,
I've got a C function in which I want to fill two tables and return them both as result, however I'm a little stuck on the logic behind it. Here's some example code, but it only generates one table.
int multipleTables(lua_State *L) { int min = luaL_checkint(L, 1); int max = luaL_checkint(L, 2); // I want to fill two result tables in one loop lua_newtable(L); for(int i = 0; i < (DATA_SIZE - 1); i++) { lua_pushnumber(L, i + 1); lua_pushnumber(L, data[i]); lua_settable(L, -3); // if data[i] > min and < max, I want to add it to a second result table if(data[i] > min && data[i] < max) { // push to second result table } } return 2; }
How would I fill a second result table in that same loop? Looping through the data twice would be too slow, considering 'data' may have 10000 elements.
Cheers
--
Bas Groothedde Imagine Programming
|