Reads the `values` array of an enum param (entries are {value=, label=} or a bare string). Leaves the stack as found. `param_idx` is the param descriptor.
| 235 | // Reads the `values` array of an enum param (entries are {value=, label=} or a |
| 236 | // bare string). Leaves the stack as found. `param_idx` is the param descriptor. |
| 237 | void readEnumValues(lua_State* L, int param_idx, ParamSpec& spec) { |
| 238 | lua_rawgetfield(L, param_idx, "values"); |
| 239 | if (lua_istable(L, -1)) { |
| 240 | const int values_idx = lua_gettop(L); |
| 241 | const int count = arrayLen(L, values_idx); |
| 242 | for (int i = 1; i <= count; ++i) { |
| 243 | lua_rawgeti(L, values_idx, i); |
| 244 | const int entry = lua_gettop(L); |
| 245 | EnumValue ev; |
| 246 | if (lua_istable(L, entry)) { |
| 247 | lua_rawgetfield(L, entry, "value"); |
| 248 | ev.value = luaScalarToJson(L, lua_gettop(L)); |
| 249 | lua_pop(L, 1); |
| 250 | ev.label = stringField(L, entry, "label", jsonScalarToString(ev.value)); |
| 251 | } else { // a bare scalar entry: value == label |
| 252 | ev.value = luaScalarToJson(L, entry); |
| 253 | ev.label = jsonScalarToString(ev.value); |
| 254 | } |
| 255 | lua_pop(L, 1); // entry |
| 256 | if (!ev.value.is_null()) { |
| 257 | spec.values.push_back(std::move(ev)); |
| 258 | } |
| 259 | } |
| 260 | } |
| 261 | lua_pop(L, 1); // values |
| 262 | } |
| 263 | |
| 264 | // Parse the `parameters` array of the class table at `class_idx` into specs. |
| 265 | // Returns an error string on a malformed entry, empty on success. |
no test coverage detected