I have the following code:
lua_getglobal(L, "lgd");
lua_getfield(L, -1, "value_pos_x");
cr->value_pos_x = lua_tointeger(L, -1);
if (!lua_isinteger(L, -1))
printf("value_pos_x allows only numbers;");
lua_getfield(L, -2, "value_pos_y");
cr->value_pos_y = lua_tointeger(L, -1);
if (!lua_isinteger(L, -1))
printf("value_pos_y allows only numbers;");
lua_getfield(L, -3, "time");
cr->time = lua_tointeger(L, -1);
if (!lua_isinteger(L, -1))
printf("time allows only numbers;");
The code works perfectly. The question I wanted to know if it is possible to keep only one message and that would apply to each function for example:
lua_getglobal(L, "lgd");
lua_getfield(L, -1, "value_pos_x");
cr->value_pos_x = lua_tointeger(L, -1);
lua_getfield(L, -2, "value_pos_y");
cr->value_pos_y = lua_tointeger(L, -1);
lua_getfield(L, -3, "time");
cr->time = lua_tointeger(L, -1);
if (lua_tointeger(L, -1) != lua_isinteger(L, -1))
printf("The entry %s is invalid;", capture_lua_getfield_name);
See Question&Answers more detail:os