// fiko.ayar.* Lua bağlama katmanı — merkezi ayar sistemi makro erişimi (mimari ilke: // her sistem doğduğu an makro+plugin+olay erişilebilir). Kayıt: apiKur() içinde // lua_createtable(L_, 0, 4); // fonksiyon("al", l_ayarAl); fonksiyon("ata", l_ayarAta); // fonksiyon("liste", l_ayarListe); fonksiyon("sifirla", l_ayarSifirla); // lua_setfield(L_, -2, "ayar"); // (bkz. entegrasyon kontratı — bu TU betik CMake'ine eklenince aktifleşir). #include "fiko/ayar/ayar_sistemi.hpp" #include "fiko/betik/makro_motor.hpp" extern "C" { #include "lauxlib.h" #include "lua.h" } namespace fiko::betik { namespace { using ayar::AyarDeger; using ayar::AyarTanim; using ayar::AyarTip; const char* tipAdi(AyarTip t) { switch (t) { case AyarTip::Bool: return "bool"; case AyarTip::Int: return "int"; case AyarTip::F32: return "f32"; case AyarTip::F64: return "f64"; case AyarTip::Renk: return "renk"; case AyarTip::Secenek: return "secenek"; default: return "metin"; } } // AyarDeger → Lua değeri (renk = {r,g,b} tablosu). void degerIt(lua_State* L, const AyarTanim& t, const AyarDeger& d) { switch (t.tip) { case AyarTip::Bool: lua_pushboolean(L, d.b); break; case AyarTip::Int: lua_pushinteger(L, static_cast(d.i)); break; case AyarTip::F32: case AyarTip::F64: lua_pushnumber(L, d.f); break; case AyarTip::Renk: lua_createtable(L, 3, 0); lua_pushnumber(L, d.renk.x); lua_rawseti(L, -2, 1); lua_pushnumber(L, d.renk.y); lua_rawseti(L, -2, 2); lua_pushnumber(L, d.renk.z); lua_rawseti(L, -2, 3); break; default: lua_pushlstring(L, d.metin.c_str(), d.metin.size()); break; } } // Lua argümanı (idx) → AyarDeger (tanımın tipine göre). false = tip uyumsuz. bool degerAl(lua_State* L, int idx, const AyarTanim& t, AyarDeger& d) { switch (t.tip) { case AyarTip::Bool: d.b = lua_toboolean(L, idx) != 0; return true; case AyarTip::Int: if (!lua_isnumber(L, idx)) return false; d.i = static_cast(lua_tonumber(L, idx)); return true; case AyarTip::F32: case AyarTip::F64: if (!lua_isnumber(L, idx)) return false; d.f = lua_tonumber(L, idx); return true; case AyarTip::Renk: { if (!lua_istable(L, idx)) return false; f32 rgb[3]; for (int i = 0; i < 3; ++i) { lua_rawgeti(L, idx, i + 1); if (!lua_isnumber(L, -1)) { lua_pop(L, 1); return false; } rgb[i] = static_cast(lua_tonumber(L, -1)); lua_pop(L, 1); } d.renk = {rgb[0], rgb[1], rgb[2]}; return true; } default: { const char* s = lua_tostring(L, idx); if (!s) return false; d.metin = s; return true; } } } } // namespace // fiko.ayar.al("kimlik") → değer (yoksa nil). int MakroMotor::l_ayarAl(lua_State* L) { const char* k = luaL_checkstring(L, 1); const AyarTanim* t = ayar::sistem().bul(k); if (!t) { lua_pushnil(L); return 1; } degerIt(L, *t, t->al()); return 1; } // fiko.ayar.ata("kimlik", deger) → true (undo dışı; anında uygular + kalıcı köprü). int MakroMotor::l_ayarAta(lua_State* L) { const char* k = luaL_checkstring(L, 1); ayar::AyarSistemi& s = ayar::sistem(); const AyarTanim* t = s.bul(k); if (!t) { lua_pushnil(L); return 1; } AyarDeger d = t->al(); if (!degerAl(L, 2, *t, d)) { lua_pushboolean(L, 0); return 1; } lua_pushboolean(L, s.degerAta(k, d) ? 1 : 0); return 1; } // fiko.ayar.liste() → { {kimlik,kategori,ad,tip,degisti}, ... }. int MakroMotor::l_ayarListe(lua_State* L) { ayar::AyarSistemi& s = ayar::sistem(); const auto& tanimlar = s.hepsi(); lua_createtable(L, static_cast(tanimlar.size()), 0); int i = 1; for (const AyarTanim& t : tanimlar) { lua_createtable(L, 0, 5); lua_pushlstring(L, t.kimlik.c_str(), t.kimlik.size()); lua_setfield(L, -2, "kimlik"); lua_pushlstring(L, t.kategori.c_str(), t.kategori.size()); lua_setfield(L, -2, "kategori"); lua_pushlstring(L, t.ad.c_str(), t.ad.size()); lua_setfield(L, -2, "ad"); lua_pushstring(L, tipAdi(t.tip)); lua_setfield(L, -2, "tip"); lua_pushboolean(L, s.degistiMi(t) ? 1 : 0); lua_setfield(L, -2, "degisti"); lua_rawseti(L, -2, i++); } return 1; } // fiko.ayar.sifirla("kimlik") → true (varsayılana dön; yoksa nil). int MakroMotor::l_ayarSifirla(lua_State* L) { const char* k = luaL_checkstring(L, 1); if (!ayar::sistem().bul(k)) { lua_pushnil(L); return 1; } lua_pushboolean(L, ayar::sistem().sifirla(k) ? 1 : 0); return 1; } } // namespace fiko::betik