| 1076 | } |
| 1077 | |
| 1078 | int |
| 1079 | get_table_boolean(lua_State *L, const char *name) |
| 1080 | { |
| 1081 | static const char *const boolstr[] = { |
| 1082 | "true", "false", "yes", "no", NULL |
| 1083 | }; |
| 1084 | /* static const int boolstr2i[] = { TRUE, FALSE, TRUE, FALSE, -1 }; */ |
| 1085 | int ltyp; |
| 1086 | int ret = -1; |
| 1087 | |
| 1088 | lua_getfield(L, -1, name); |
| 1089 | ltyp = lua_type(L, -1); |
| 1090 | if (ltyp == LUA_TSTRING) { |
| 1091 | ret = luaL_checkoption(L, -1, NULL, boolstr); |
| 1092 | /* nhUse(boolstr2i[0]); */ |
| 1093 | } else if (ltyp == LUA_TBOOLEAN) { |
| 1094 | ret = lua_toboolean(L, -1); |
| 1095 | } else if (ltyp == LUA_TNUMBER) { |
| 1096 | ret = (int) luaL_checkinteger(L, -1); |
| 1097 | if (ret < 0 || ret > 1) |
| 1098 | ret = -1; |
| 1099 | } |
| 1100 | lua_pop(L, 1); |
| 1101 | if (ret == -1) |
| 1102 | nhl_error(L, "Expected a boolean"); |
| 1103 | return ret; |
| 1104 | } |
| 1105 | |
| 1106 | int |
| 1107 | get_table_boolean_opt(lua_State *L, const char *name, int defval) |
no test coverage detected