0

well I have a question, I was wondering if it is possible to count the settings that exist within a function lua_getglobal.

I have a file called define.lua he is as follows:

tbl {
     macro_enable = true;
     macro_value = 100;
     time_expire = 60;
     enable_mac = true;
};

What I'm trying to insert a message in my code to count the amount of existetes settings

code:

lua_getglobal(L, "tbl");

lua_getfield(L, -1, "macro_enable");
p->macro_enable = lua_toboolean(L, -1);

lua_getfield(L, -1, "macro_value");
p->macro_value = lua_tointeger(L, -1);

lua_getfield(L, -1, "time_expire");
p->time_expire = lua_tointeger(L, -1);

lua_getfield(L, -1, "enable_mac");
p->enable_mac = lua_toboolean(L, -1);

Want to add a message.

printf ("% d configurations have been read");

I tried to do a loop more without success

carolzinha
  • 101
  • 1
  • 7

1 Answers1

0

If you can't use a loop then start with

Int count=0;  

And on each line you read a config field:

Count+=1;  

Your printf statement should say:

printf ("% d configurations have been read",count);
swiley
  • 72
  • 4
  • wanted to use loop to avoid extra code, however the following error occurs: `PANIC: unprotected erro in call to lua API (attempt to index a bollean value)` – carolzinha Nov 13 '15 at 16:34