| 11 | } |
| 12 | |
| 13 | Maybe<Color> LuaConverter<Color>::to(LuaEngine& engine, LuaValue const& v) { |
| 14 | if (auto t = v.ptr<LuaTable>()) { |
| 15 | Color c = Color::rgba(0, 0, 0, 255); |
| 16 | Maybe<int> r = engine.luaMaybeTo<int>(t->get(1)); |
| 17 | Maybe<int> g = engine.luaMaybeTo<int>(t->get(2)); |
| 18 | Maybe<int> b = engine.luaMaybeTo<int>(t->get(3)); |
| 19 | if (!r || !g || !b) |
| 20 | return {}; |
| 21 | |
| 22 | c.setRed(*r); |
| 23 | c.setGreen(*g); |
| 24 | c.setBlue(*b); |
| 25 | |
| 26 | if (Maybe<int> a = engine.luaMaybeTo<int>(t->get(4))) { |
| 27 | if (!a) |
| 28 | return {}; |
| 29 | c.setAlpha(*a); |
| 30 | } |
| 31 | |
| 32 | return c; |
| 33 | } else if (auto s = v.ptr<LuaString>()) { |
| 34 | try { |
| 35 | return Color(s->ptr()); |
| 36 | } catch (ColorException const&) {} |
| 37 | } |
| 38 | |
| 39 | return {}; |
| 40 | } |
| 41 | |
| 42 | LuaValue LuaConverter<LuaCallbacks>::from(LuaEngine& engine, LuaCallbacks const& c) { |
| 43 | auto table = engine.createTable(0, c.callbacks().size()); |