1
Well I’m trying to create a moon reading that can read this table below, the table should only accept values and if add string, it warns the error location.
Table = {
1000, 2000, 3000, 4000, 5000,
6000, 7000, 8000, 9000, 10000,
11111, 12000, 13000, 14000, 15000,..
}
I am the 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 moon now.
I don’t understand your question right. What is the problem you are having with your current code?
– hugomg
The following error appears at reading time, PANIC: unprotected error in call to Lua API
– carolzinha
In which line does the error occur? (if you do not know, you can run the C program in a debugger to find out)
– hugomg
Doesn’t say what line.
– carolzinha
You know how to use some debugger for C, they tell you the error line for you. Which operating system / IDE you are using?
– hugomg
I used here and pointed me here.
lua_getfield(L, -1, "Table");
So this code Table = ae is inside the table.lua file, I’m trying to get it to read the values from the table there.– carolzinha
See if this helps in any way: http://answall.com/q/55230/101
– Maniero
I tried using this most unsuccessful
– carolzinha