I am trying to create a moon reading that can read this table below, the table should only accept values and if they add string, it warns the location of the error.
Table = {
1000, 2000, 3000, 4000, 5000,
6000, 7000, 8000, 9000, 10000,
11111, 12000, 13000, 14000, 15000,..
}
I'm code is as follows:
void read_table(void) {
int var1;
long double var2;
lua_State *L;
L = = luaL_newstate();
luaL_openlibs(L);
if (luaL_loadfile(L, "table.lua") || lua_pcall(L, 0, 0, 0)) {
printf("cannot run cofig file: %s\n");
return;
}
else {
lua_getfield(L, -1, "Table");
if (lua_type(L, -1) == 5) {
var1 = 1;
while (1)
{
lua_pushnumber(L, var2);
lua_gettable(L, -2);
if (!lua_isnumber(L, -1))
break;
lua_tonumber(L, -1);
lua_settop(L, -2);
++var1;
lua_close(L);
}
printf("table %d invalid\n", var1);
}
else {
printf("table should be a table\n");
}
}
printf("Reading %d numbers\n", var1);
}
How can I read this table, I'm starting to learn the moon now.