* @brief Lua C closure for tableSet(table, reg, value). Cache-aware like tableGet. A nil value * (e.g. a failed tonumber()) is a safe no-op for parity with JS, which never raises here. */
| 2463 | * (e.g. a failed tonumber()) is a safe no-op for parity with JS, which never raises here. |
| 2464 | */ |
| 2465 | static int luaTableSet(lua_State* L) |
| 2466 | { |
| 2467 | auto* store = static_cast<DataModel::DataTableStore*>(lua_touserdata(L, lua_upvalueindex(1))); |
| 2468 | Q_ASSERT(store); |
| 2469 | |
| 2470 | const char* table = luaL_checkstring(L, 1); |
| 2471 | const char* reg = luaL_checkstring(L, 2); |
| 2472 | |
| 2473 | if (lua_isnoneornil(L, 3)) |
| 2474 | return 0; |
| 2475 | |
| 2476 | DataModel::RegisterValue rv; |
| 2477 | if (lua_isnumber(L, 3)) { |
| 2478 | rv.numericValue = lua_tonumber(L, 3); |
| 2479 | rv.isNumeric = true; |
| 2480 | } else { |
| 2481 | rv.stringValue = QString::fromUtf8(luaL_checkstring(L, 3)); |
| 2482 | rv.isNumeric = false; |
| 2483 | } |
| 2484 | |
| 2485 | store->setByInternedKey(table, reg, rv); |
| 2486 | return 0; |
| 2487 | } |
| 2488 | |
| 2489 | /** |
| 2490 | * @brief Lua C closure for tableHandle(table, reg) -> handle; resolve once, off the hot path. |
nothing calls this directly
no test coverage detected