MCPcopy Create free account
hub / github.com/OpenStarbound/OpenStarbound / to

Method to

source/core/StarLuaConverters.cpp:13–40  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

11}
12
13Maybe<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
42LuaValue LuaConverter<LuaCallbacks>::from(LuaEngine& engine, LuaCallbacks const& c) {
43 auto table = engine.createTable(0, c.callbacks().size());

Callers

nothing calls this directly

Calls 7

ColorClass · 0.85
setRedMethod · 0.80
setGreenMethod · 0.80
setBlueMethod · 0.80
setAlphaMethod · 0.80
getMethod · 0.45
ptrMethod · 0.45

Tested by

no test coverage detected