1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-06-15 00:05:02 +02:00

Less ugly API declarations

This commit is contained in:
AlexVinS
2021-02-16 17:07:30 +03:00
parent ec6f7b88fe
commit 6d245a7821
59 changed files with 693 additions and 827 deletions

View File

@ -27,96 +27,96 @@ namespace api
namespace netpacks
{
const std::vector<InfoWindowProxy::RegType> InfoWindowProxy::REGISTER =
{
{
"addReplacement",
&InfoWindowProxy::addReplacement
},
{
"addText",
&InfoWindowProxy::addText
},
{
"setPlayer",
&InfoWindowProxy::setPlayer
},
{
"toNetpackLight",
&PackForClientProxy<InfoWindowProxy>::toNetpackLight
},
};
const std::vector<InfoWindowProxy::CustomRegType> InfoWindowProxy::REGISTER_CUSTOM =
{
{"new", &Wrapper::constructor, true}
{"new", &Wrapper::constructor, true},
{"addReplacement", &InfoWindowProxy::addReplacement, false},
{"addText", &InfoWindowProxy::addText, false},
{"setPlayer", &InfoWindowProxy::setPlayer, false},
{"toNetpackLight", &PackForClientProxy<InfoWindowProxy>::toNetpackLight, false}
};
int InfoWindowProxy::addReplacement(lua_State * L, std::shared_ptr<InfoWindow> object)
int InfoWindowProxy::addReplacement(lua_State * L)
{
LuaStack S(L);
std::shared_ptr<InfoWindow> object;
if(!S.tryGet(1, object))
return S.retVoid();
int top = lua_gettop(L);
if(top == 1)
if(top == 2)
{
if(lua_isstring(L, 1))
if(lua_isstring(L, 2))
{
size_t len = 0;
auto raw = lua_tolstring(L, 1, &len);
auto raw = lua_tolstring(L, 2, &len);
std::string text(raw, len);
object->text.addReplacement(text);
}
else if(lua_isnumber(L, 1))
else if(lua_isnumber(L, 2))
{
object->text.addReplacement(lua_tointeger(L, 1));
object->text.addReplacement(lua_tointeger(L, 2));
}
}
else if(top >= 2)
else if(top >= 3)
{
if(lua_isnumber(L, 1) && lua_isnumber(L, 2))
object->text.addReplacement(lua_tointeger(L, 1), lua_tointeger(L, 2));
if(lua_isnumber(L, 2) && lua_isnumber(L, 3))
object->text.addReplacement(lua_tointeger(L, 2), lua_tointeger(L, 3));
}
lua_settop(L, 0);
return 0;
return S.retVoid();
}
int InfoWindowProxy::addText(lua_State * L, std::shared_ptr<InfoWindow> object)
int InfoWindowProxy::addText(lua_State * L)
{
LuaStack S(L);
std::shared_ptr<InfoWindow> object;
if(!S.tryGet(1, object))
return S.retVoid();
int top = lua_gettop(L);
if(top == 1)
if(top == 2)
{
if(lua_isstring(L, 1))
if(lua_isstring(L, 2))
{
size_t len = 0;
auto raw = lua_tolstring(L, 1, &len);
auto raw = lua_tolstring(L, 2, &len);
std::string text(raw, len);
object->text << text;
}
else if(lua_isnumber(L, 1))
else if(lua_isnumber(L, 2))
{
object->text << (lua_tointeger(L, 1));
object->text << (lua_tointeger(L, 2));
}
}
if(top >= 2)
if(top >= 3)
{
if(lua_isnumber(L, 1) && lua_isnumber(L, 2))
object->text.addTxt(lua_tointeger(L, 1), lua_tointeger(L, 2));
if(lua_isnumber(L, 2) && lua_isnumber(L, 3))
object->text.addTxt(lua_tointeger(L, 2), lua_tointeger(L, 3));
}
lua_settop(L, 0);
return 0;
return S.retVoid();
}
int InfoWindowProxy::setPlayer(lua_State * L, std::shared_ptr<InfoWindow> object)
int InfoWindowProxy::setPlayer(lua_State * L)
{
LuaStack S(L);
std::shared_ptr<InfoWindow> object;
if(!S.tryGet(1, object))
return S.retVoid();
PlayerColor value;
if(S.tryGet(1, value))
if(S.tryGet(2, value))
object->player = value;
return S.retVoid();