Răsfoiți Sursa

Less ugly API declarations

AlexVinS 4 ani în urmă
părinte
comite
6d245a7821
59 a modificat fișierele cu 698 adăugiri și 832 ștergeri
  1. 159 147
      scripting/lua/LuaCallWrapper.h
  2. 1 42
      scripting/lua/LuaWrapper.h
  3. 13 15
      scripting/lua/api/Artifact.cpp
  4. 0 1
      scripting/lua/api/Artifact.h
  5. 38 23
      scripting/lua/api/BattleCb.cpp
  6. 3 4
      scripting/lua/api/BattleCb.h
  7. 85 62
      scripting/lua/api/BonusSystem.cpp
  8. 15 18
      scripting/lua/api/BonusSystem.h
  9. 30 34
      scripting/lua/api/Creature.cpp
  10. 0 1
      scripting/lua/api/Creature.h
  11. 5 7
      scripting/lua/api/Faction.cpp
  12. 0 1
      scripting/lua/api/Faction.h
  13. 7 9
      scripting/lua/api/GameCb.cpp
  14. 0 1
      scripting/lua/api/GameCb.h
  15. 4 6
      scripting/lua/api/HeroClass.cpp
  16. 0 1
      scripting/lua/api/HeroClass.h
  17. 2 4
      scripting/lua/api/HeroInstance.cpp
  18. 0 1
      scripting/lua/api/HeroInstance.h
  19. 4 6
      scripting/lua/api/HeroType.cpp
  20. 0 1
      scripting/lua/api/HeroType.h
  21. 5 7
      scripting/lua/api/ObjectInstance.cpp
  22. 0 1
      scripting/lua/api/ObjectInstance.h
  23. 0 4
      scripting/lua/api/Player.cpp
  24. 0 2
      scripting/lua/api/Player.h
  25. 29 20
      scripting/lua/api/ServerCb.cpp
  26. 2 4
      scripting/lua/api/ServerCb.h
  27. 14 54
      scripting/lua/api/Services.cpp
  28. 0 8
      scripting/lua/api/Services.h
  29. 4 6
      scripting/lua/api/Skill.cpp
  30. 0 1
      scripting/lua/api/Skill.h
  31. 19 23
      scripting/lua/api/Spell.cpp
  32. 0 1
      scripting/lua/api/Spell.h
  33. 2 7
      scripting/lua/api/StackInstance.cpp
  34. 0 1
      scripting/lua/api/StackInstance.h
  35. 6 29
      scripting/lua/api/battle/UnitProxy.cpp
  36. 0 2
      scripting/lua/api/battle/UnitProxy.h
  37. 5 27
      scripting/lua/api/events/AdventureEvents.cpp
  38. 0 1
      scripting/lua/api/events/AdventureEvents.h
  39. 20 19
      scripting/lua/api/events/BattleEvents.cpp
  40. 0 1
      scripting/lua/api/events/BattleEvents.h
  41. 0 1
      scripting/lua/api/events/EventBusProxy.cpp
  42. 0 1
      scripting/lua/api/events/EventBusProxy.h
  43. 11 17
      scripting/lua/api/events/GenericEvents.cpp
  44. 0 3
      scripting/lua/api/events/GenericEvents.h
  45. 0 1
      scripting/lua/api/events/SubscriptionRegistryProxy.cpp
  46. 0 1
      scripting/lua/api/events/SubscriptionRegistryProxy.h
  47. 14 19
      scripting/lua/api/netpacks/BattleLogMessage.cpp
  48. 1 2
      scripting/lua/api/netpacks/BattleLogMessage.h
  49. 28 33
      scripting/lua/api/netpacks/BattleStackMoved.cpp
  50. 4 6
      scripting/lua/api/netpacks/BattleStackMoved.h
  51. 35 35
      scripting/lua/api/netpacks/BattleUnitsChanged.cpp
  52. 4 5
      scripting/lua/api/netpacks/BattleUnitsChanged.h
  53. 11 17
      scripting/lua/api/netpacks/EntitiesChanged.cpp
  54. 1 2
      scripting/lua/api/netpacks/EntitiesChanged.h
  55. 45 45
      scripting/lua/api/netpacks/InfoWindow.cpp
  56. 3 4
      scripting/lua/api/netpacks/InfoWindow.h
  57. 7 1
      scripting/lua/api/netpacks/PackForClient.h
  58. 55 29
      scripting/lua/api/netpacks/SetResources.cpp
  59. 7 8
      scripting/lua/api/netpacks/SetResources.h

+ 159 - 147
scripting/lua/LuaCallWrapper.h

@@ -12,7 +12,6 @@
 
 #include "api/Registry.h"
 #include "LuaStack.h"
-#include "LuaFunctor.h"
 
 namespace scripting
 {
@@ -20,8 +19,83 @@ namespace scripting
 namespace detail
 {
 
+template<int ...>
+struct Seq {};
+
+template<int N, int ...S>
+struct Gens : Gens<N-1, N-1, S...> {};
+
+template<int ...S>
+struct Gens<0, S...>
+{
+	typedef Seq<S...> type;
+};
+
+template <typename R, typename ... Args>
+class LuaArgumentsTuple
+{
+public:
+	using TupleData = std::tuple<Args ...>;
+	using Functor = R(*)(Args ...);
+
+	TupleData args;
+	Functor f;
+
+	LuaArgumentsTuple(Functor _f)
+		:f(_f),
+		args()
+	{
+	}
+
+
+	STRONG_INLINE int invoke(lua_State * L)
+	{
+		return callFunc(L, typename Gens<sizeof...(Args)>::type());
+	}
+private:
+	template<int ...N>
+	int callFunc(lua_State * L, Seq<N...>)
+	{
+		LuaStack S(L);
+
+		bool ok[sizeof...(Args)] = {(S.tryGet(N+1, std::get<N>(args)))...};
+
+		if(std::count(std::begin(ok), std::end(ok), false) > 0)
+			return S.retVoid();
+
+
+		R ret = f(std::get<N>(args) ...);
+		S.clear();
+		S.push(ret);
+		return 1;
+	}
+};
+
+
+class LuaFunctionInvoker
+{
+public:
+	template<typename R, typename ... Args>
+	static STRONG_INLINE int invoke(lua_State * L, R(*f)(Args ...))
+	{
+		LuaArgumentsTuple<R, Args ...> args(f);
+		return args.invoke(L);
+	}
+};
+
 }
 
+template <typename F, F f>
+class LuaFunctionWrapper
+{
+public:
+	static int invoke(lua_State * L)
+	{
+		return detail::LuaFunctionInvoker::invoke(L, f);
+	}
+};
+
+
 //TODO: this should be the only one wrapper type
 //
 template <typename U, typename M, M m>
@@ -50,6 +124,26 @@ public:
 	}
 };
 
+template <typename U, typename T, typename R, R(T:: * method)()>
+class LuaMethodWrapper <U, R(T:: *)(), method>
+{
+public:
+	static int invoke(lua_State * L)
+	{
+		LuaStack S(L);
+		U * obj = nullptr;
+
+		if(!S.tryGet(1,obj))
+			return S.retVoid();
+
+		static auto functor = std::mem_fn(method);
+
+		S.clear();
+		S.push(functor(obj));
+		return S.retPushed();
+	}
+};
+
 template <typename U, typename T, void(T:: * method)()const>
 class LuaMethodWrapper <U, void(T:: *)()const, method>
 {
@@ -69,6 +163,25 @@ public:
 	}
 };
 
+template <typename U, typename T, void(T:: * method)()>
+class LuaMethodWrapper <U, void(T:: *)(), method>
+{
+public:
+	static int invoke(lua_State * L)
+	{
+		LuaStack S(L);
+		U * obj = nullptr;
+
+		if(!S.tryGet(1,obj))
+			return S.retVoid();
+
+		static auto functor = std::mem_fn(method);
+		S.clear();
+		functor(obj);
+		return 0;
+	}
+};
+
 template <typename U, typename T, typename R, typename P1, R(T:: * method)(P1)const>
 class LuaMethodWrapper <U, R(T:: *)(P1)const, method>
 {
@@ -92,6 +205,29 @@ public:
 	}
 };
 
+template <typename U, typename T, typename R, typename P1, R(T:: * method)(P1)>
+class LuaMethodWrapper <U, R(T:: *)(P1), method>
+{
+public:
+	static int invoke(lua_State * L)
+	{
+		LuaStack S(L);
+		U * obj = nullptr;
+
+		if(!S.tryGet(1,obj))
+			return S.retVoid();
+
+		P1 p1;
+		if(!S.tryGet(2, p1))
+			return S.retVoid();
+
+		static auto functor = std::mem_fn(method);
+		S.clear();
+		S.push(functor(obj, p1));
+		return S.retPushed();
+	}
+};
+
 template <typename U, typename T, typename P1, void(T:: * method)(P1)const>
 class LuaMethodWrapper <U, void(T:: *)(P1)const, method>
 {
@@ -115,6 +251,28 @@ public:
 	}
 };
 
+template <typename U, typename T, typename P1, void(T:: * method)(P1)>
+class LuaMethodWrapper <U, void(T:: *)(P1), method>
+{
+public:
+	static int invoke(lua_State * L)
+	{
+		LuaStack S(L);
+		U * obj = nullptr;
+
+		if(!S.tryGet(1,obj))
+			return S.retVoid();
+
+		P1 p1;
+		if(!S.tryGet(2, p1))
+			return S.retVoid();
+
+		static auto functor = std::mem_fn(method);
+		S.clear();
+		functor(obj, p1);
+		return 0;
+	}
+};
 
 template <typename U, typename T, typename R, typename P1, typename P2, R(T:: * method)(P1, P2)const>
 class LuaMethodWrapper <U, R(T:: *)(P1, P2)const, method>
@@ -170,150 +328,4 @@ public:
 	}
 };
 
-
-//deprecated, should use LuaMethodWrapper instead, once implemented
-template <typename T>
-class LuaCallWrapper
-{
-public:
-	using Wrapped = typename std::remove_const<T>::type;
-
-	static std::function<int(lua_State *, T *)> createFunctor(void (Wrapped::* method)())
-	{
-		auto functor = std::mem_fn(method);
-		auto ret = [=](lua_State * L, T * object)->int
-		{
-			LuaStack S(L);
-			functor(object);
-			return S.retVoid();
-		};
-
-		return ret;
-	}
-
-	static std::function<int(lua_State *, T *)> createFunctor(void (Wrapped::* method)() const)
-	{
-		auto functor = std::mem_fn(method);
-		auto ret = [=](lua_State * L, T * object)->int
-		{
-			LuaStack S(L);
-			functor(object);
-			return S.retVoid();
-		};
-
-		return ret;
-	}
-
-	template <typename R>
-	static std::function<int(lua_State *, T *)> createFunctor(R (Wrapped::* method)())
-	{
-		auto functor = std::mem_fn(method);
-		auto ret = [=](lua_State * L, T * object)->int
-		{
-			LuaStack S(L);
-			S.clear();
-			S.push(functor(object));
-			return S.retPushed();
-		};
-
-		return ret;
-	}
-
-	template <typename R>
-	static std::function<int(lua_State *, T *)> createFunctor(R (Wrapped::* method)() const)
-	{
-		auto functor = std::mem_fn(method);
-		auto ret = [=](lua_State * L, T * object)->int
-		{
-			LuaStack S(L);
-			S.clear();
-			S.push(functor(object));
-			return S.retPushed();
-		};
-
-		return ret;
-	}
-
-	template <typename P1>
-	static std::function<int(lua_State *, T *)> createFunctor(void (Wrapped::* method)(P1))
-	{
-		auto functor = std::mem_fn(method);
-		auto ret = [=](lua_State * L, T * object)->int
-		{
-			LuaStack S(L);
-			P1 p1;
-			if(S.tryGet(1, p1))
-			{
-				functor(object, p1);
-			}
-
-			return S.retVoid();
-		};
-
-		return ret;
-	}
-
-	template <typename P1>
-	static std::function<int(lua_State *, T *)> createFunctor(void (Wrapped::* method)(P1) const)
-	{
-		auto functor = std::mem_fn(method);
-		auto ret = [=](lua_State * L, T * object)->int
-		{
-			LuaStack S(L);
-			P1 p1;
-			if(S.tryGet(1, p1))
-			{
-				functor(object, p1);
-			}
-
-			return S.retVoid();
-		};
-
-		return ret;
-	}
-
-	template <typename R, typename P1>
-	static std::function<int(lua_State *, T *)> createFunctor(R (Wrapped::* method)(P1))
-	{
-		auto functor = std::mem_fn(method);
-		auto ret = [=](lua_State * L, T * object)->int
-		{
-			LuaStack S(L);
-			P1 p1;
-			if(S.tryGet(1, p1))
-			{
-				S.push(functor(object, p1));
-				return 1;
-			}
-
-			return S.retVoid();
-		};
-
-		return ret;
-	}
-
-	template <typename R, typename P1>
-	static std::function<int(lua_State *, T *)> createFunctor(R (Wrapped::* method)(P1) const)
-	{
-		auto functor = std::mem_fn(method);
-		auto ret = [=](lua_State * L, T * object)->int
-		{
-			LuaStack S(L);
-			P1 p1;
-			if(S.tryGet(1, p1))
-			{
-				S.push(functor(object, p1));
-				return 1;
-			}
-
-			return S.retVoid();
-		};
-
-		return ret;
-	}
-
-};
-
-
-
 }

+ 1 - 42
scripting/lua/LuaWrapper.h

@@ -10,9 +10,7 @@
 
 #pragma once
 
-#include "api/Registry.h"
-#include "LuaFunctor.h"
-#include "LuaStack.h"
+#include "LuaCallWrapper.h"
 
 /*
  * Original code is LunaWrapper by nornagon.
@@ -27,13 +25,6 @@ namespace scripting
 
 namespace detail
 {
-	template<typename T>
-	struct RegType
-	{
-		const char * name;
-		std::function<int(lua_State *, T)> functor;
-	};
-
 	struct CustomRegType
 	{
 		const char * name;
@@ -47,40 +38,11 @@ namespace detail
 		using ProxyType = P;
 		using UDataType = U;
 
-		static int invoke(lua_State * L)
-		{
-			static auto KEY = api::TypeRegistry::get()->getKey<UDataType>();
-
-			int i = (int)lua_tonumber(L, lua_upvalueindex(1));
-
-			void * raw = luaL_checkudata(L, 1, KEY);
-
-			if(!raw)
-			{
-				lua_settop(L, 0);
-				return 0;
-			}
-
-			lua_remove(L, 1);
-
-			auto obj = *(static_cast<UDataType *>(raw));
-			return (ProxyType::REGISTER[i].functor)(L, obj);
-		}
-
 		static void setIndexTable(lua_State * L)
 		{
 			lua_pushstring(L, "__index");
 
 			lua_newtable(L);
-			lua_Integer index = 0;
-			for(auto & reg : ProxyType::REGISTER)
-			{
-				lua_pushstring(L, reg.name);
-				lua_pushnumber(L, index);
-				lua_pushcclosure(L, &invoke, 1);
-				lua_rawset(L, -3);
-				index++;
-			}
 
 			for(auto & reg : ProxyType::REGISTER_CUSTOM)
 			{
@@ -164,7 +126,6 @@ public:
 	using UDataType = ObjectType *;
 	using CUDataType = const ObjectType *;
 
-	using RegType = detail::RegType<UDataType>;
 	using CustomRegType = detail::CustomRegType;
 
 	void pushMetatable(lua_State * L) const override final
@@ -202,7 +163,6 @@ class SharedWrapper : public RegistarBase
 public:
 	using ObjectType = typename std::remove_cv<T>::type;
 	using UDataType = std::shared_ptr<T>;
-	using RegType = detail::RegType<UDataType>;
 	using CustomRegType = detail::CustomRegType;
 
 	static int constructor(lua_State * L)
@@ -248,7 +208,6 @@ class UniqueOpaqueWrapper : public api::Registar
 public:
 	using ObjectType = typename std::remove_cv<T>::type;
 	using UDataType = std::unique_ptr<T>;
-	using RegType = detail::RegType<UDataType>;
 	using CustomRegType = detail::CustomRegType;
 
 	void pushMetatable(lua_State * L) const override final

+ 13 - 15
scripting/lua/api/Artifact.cpp

@@ -24,23 +24,21 @@ namespace api
 
 VCMI_REGISTER_CORE_SCRIPT_API(ArtifactProxy, "Artifact");
 
-const std::vector<ArtifactProxy::RegType> ArtifactProxy::REGISTER = {};
-
 const std::vector<ArtifactProxy::CustomRegType> ArtifactProxy::REGISTER_CUSTOM =
 {
-	{"getIconIndex", LuaMethodWrapper<Artifact, int32_t(Entity:: *)()const, &Entity::getIconIndex>::invoke, false},
-	{"getIndex", LuaMethodWrapper<Artifact, int32_t(Entity:: *)()const, &Entity::getIndex>::invoke, false},
-	{"getJsonKey", LuaMethodWrapper<Artifact, const std::string &(Entity:: *)()const, &Entity::getJsonKey>::invoke, false},
-	{"getName", LuaMethodWrapper<Artifact, const std::string &(Entity:: *)()const, &Entity::getName>::invoke, false},
-
-	{"getId", LuaMethodWrapper<Artifact, ArtifactID(EntityT<ArtifactID>::*)()const, &EntityT<ArtifactID>::getId>::invoke, false},
-	{"accessBonuses", LuaMethodWrapper<Artifact, const IBonusBearer *(EntityWithBonuses<ArtifactID>:: *)()const, &EntityWithBonuses<ArtifactID>::accessBonuses>::invoke, false},
-
-	{"getDescription", LuaMethodWrapper<Artifact, const std::string &(Artifact:: *)()const, &Artifact::getDescription>::invoke, false},
-	{"getEventText", LuaMethodWrapper<Artifact, const std::string &(Artifact:: *)()const, &Artifact::getEventText>::invoke, false},
-	{"isBig", LuaMethodWrapper<Artifact, bool(Artifact:: *)()const, &Artifact::isBig>::invoke, false},
-	{"isTradable", LuaMethodWrapper<Artifact, bool(Artifact:: *)()const, &Artifact::isTradable>::invoke, false},
-	{"getPrice", LuaMethodWrapper<Artifact, uint32_t(Artifact:: *)()const, &Artifact::getPrice>::invoke, false},
+	{"getIconIndex", LuaMethodWrapper<Artifact, decltype(&Entity::getIconIndex), &Entity::getIconIndex>::invoke, false},
+	{"getIndex", LuaMethodWrapper<Artifact, decltype(&Entity::getIndex), &Entity::getIndex>::invoke, false},
+	{"getJsonKey", LuaMethodWrapper<Artifact, decltype(&Entity::getJsonKey), &Entity::getJsonKey>::invoke, false},
+	{"getName", LuaMethodWrapper<Artifact, decltype(&Entity::getName), &Entity::getName>::invoke, false},
+
+	{"getId", LuaMethodWrapper<Artifact, decltype(&EntityT<ArtifactID>::getId), &EntityT<ArtifactID>::getId>::invoke, false},
+	{"accessBonuses", LuaMethodWrapper<Artifact, decltype(&EntityWithBonuses<ArtifactID>::accessBonuses), &EntityWithBonuses<ArtifactID>::accessBonuses>::invoke, false},
+
+	{"getDescription", LuaMethodWrapper<Artifact, decltype(&Artifact::getDescription), &Artifact::getDescription>::invoke, false},
+	{"getEventText", LuaMethodWrapper<Artifact, decltype(&Artifact::getEventText), &Artifact::getEventText>::invoke, false},
+	{"isBig", LuaMethodWrapper<Artifact, decltype(&Artifact::isBig), &Artifact::isBig>::invoke, false},
+	{"isTradable", LuaMethodWrapper<Artifact, decltype(&Artifact::isTradable), &Artifact::isTradable>::invoke, false},
+	{"getPrice", LuaMethodWrapper<Artifact, decltype(&Artifact::getPrice), &Artifact::getPrice>::invoke, false},
 };
 
 

+ 0 - 1
scripting/lua/api/Artifact.h

@@ -24,7 +24,6 @@ class ArtifactProxy : public OpaqueWrapper<const Artifact, ArtifactProxy>
 public:
 	using Wrapper = OpaqueWrapper<const Artifact, ArtifactProxy>;
 
-	static const std::vector<typename Wrapper::RegType> REGISTER;
 	static const std::vector<typename Wrapper::CustomRegType> REGISTER_CUSTOM;
 };
 

+ 38 - 23
scripting/lua/api/BattleCb.cpp

@@ -24,75 +24,90 @@ namespace api
 
 VCMI_REGISTER_CORE_SCRIPT_API(BattleCbProxy, "Battle");
 
-const std::vector<BattleCbProxy::RegType> BattleCbProxy::REGISTER =
+const std::vector<BattleCbProxy::CustomRegType> BattleCbProxy::REGISTER_CUSTOM =
 {
 	{
 		"getBattlefieldType",
-		&BattleCbProxy::getBattlefieldType
+		&BattleCbProxy::getBattlefieldType,
+		false
 	},
 	{
 		"getNextUnitId",
-		LuaCallWrapper<const BattleCb>::createFunctor(&BattleCb::battleNextUnitId)
+		LuaMethodWrapper<BattleCb, decltype(&BattleCb::battleNextUnitId), &BattleCb::battleNextUnitId>::invoke,
+		false
 	},
 	{
 		"getTacticDistance",
-		LuaCallWrapper<const BattleCb>::createFunctor(&BattleCb::battleTacticDist)
+		LuaMethodWrapper<BattleCb, decltype(&BattleCb::battleTacticDist), &BattleCb::battleTacticDist>::invoke,
+		false
 	},
 	{
 		"getTerrainType",
-		&BattleCbProxy::getTerrainType
+		&BattleCbProxy::getTerrainType,
+		false
 	},
 	{
 		"getUnitById",
-		LuaCallWrapper<const BattleCb>::createFunctor(&BattleCb::battleGetUnitByID)
+		LuaMethodWrapper<BattleCb, decltype(&BattleCb::battleGetUnitByID), &BattleCb::battleGetUnitByID>::invoke,
+		false
 	},
 	{
 		"getUnitByPos",
-		&BattleCbProxy::getUnitByPos
+		&BattleCbProxy::getUnitByPos,
+		false
 	},
 	{
 		"isFinished",
-		LuaCallWrapper<const BattleCb>::createFunctor(&BattleCb::battleIsFinished)
+		LuaMethodWrapper<BattleCb, decltype(&BattleCb::battleIsFinished), &BattleCb::battleIsFinished>::invoke,
+		false
 	}
 };
 
-
-const std::vector<BattleCbProxy::CustomRegType> BattleCbProxy::REGISTER_CUSTOM =
+int BattleCbProxy::getBattlefieldType(lua_State * L)
 {
+	LuaStack S(L);
 
-};
-
+	const BattleCb * object;
+	if(!S.tryGet(1, object))
+		return S.retVoid();
 
-int BattleCbProxy::getBattlefieldType(lua_State * L, const BattleCb * object)
-{
-	LuaStack S(L);
 	auto ret = object->battleGetBattlefieldType();
-	S.push(static_cast<si32>(ret.num));
-	return 1;
+
+	return LuaStack::quickRetInt(L, static_cast<si32>(ret.num));
 }
 
-int BattleCbProxy::getTerrainType(lua_State * L, const BattleCb * object)
+int BattleCbProxy::getTerrainType(lua_State * L)
 {
 	LuaStack S(L);
+
+	const BattleCb * object;
+	if(!S.tryGet(1, object))
+		return S.retVoid();
+
 	auto ret = object->battleTerrainType();
-	S.push(static_cast<si32>(ret.num));
-	return 1;
+
+	return LuaStack::quickRetInt(L, static_cast<si32>(ret.num));
 }
 
-int BattleCbProxy::getUnitByPos(lua_State * L, const BattleCb * object)
+int BattleCbProxy::getUnitByPos(lua_State * L)
 {
 	LuaStack S(L);
 
+	const BattleCb * object;
+	if(!S.tryGet(1, object))
+		return S.retVoid();
+
 	BattleHex hex;
 
-	if(!S.tryGet(1, hex.hex))
+	if(!S.tryGet(2, hex.hex))
 		return S.retNil();
 
 	bool onlyAlive;
 
-	if(!S.tryGet(2, onlyAlive))
+	if(!S.tryGet(3, onlyAlive))
 		onlyAlive = true;//same as default value in battleGetUnitByPos
 
+	S.clear();
 	S.push(object->battleGetUnitByPos(hex, onlyAlive));
 	return 1;
 }

+ 3 - 4
scripting/lua/api/BattleCb.h

@@ -25,12 +25,11 @@ class BattleCbProxy : public OpaqueWrapper<const BattleCb, BattleCbProxy>
 public:
 	using Wrapper = OpaqueWrapper<const BattleCb, BattleCbProxy>;
 
-	static const std::vector<typename Wrapper::RegType> REGISTER;
 	static const std::vector<typename Wrapper::CustomRegType> REGISTER_CUSTOM;
 
-	static int getBattlefieldType(lua_State * L, const BattleCb * object);
-	static int getTerrainType(lua_State * L, const BattleCb * object);
-	static int getUnitByPos(lua_State * L, const BattleCb * object);
+	static int getBattlefieldType(lua_State * L);
+	static int getTerrainType(lua_State * L);
+	static int getUnitByPos(lua_State * L);
 };
 
 }

+ 85 - 62
scripting/lua/api/BonusSystem.cpp

@@ -25,85 +25,127 @@ namespace api
 
 VCMI_REGISTER_SCRIPT_API(BonusProxy, "Bonus");
 
-const std::vector<BonusProxy::RegType> BonusProxy::REGISTER =
-{
-	{"getType", &BonusProxy::getType},
-	{"getSubtype", &BonusProxy::getSubtype},
-	{"getDuration", &BonusProxy::getDuration},
-	{"getTurns", &BonusProxy::getTurns},
-	{"getValueType", &BonusProxy::getValueType},
-	{"getVal", &BonusProxy::getVal},
-	{"getSource", &BonusProxy::getSource},
-	{"getSourceID", &BonusProxy::getSourceID},
-	{"getEffectRange", &BonusProxy::getEffectRange},
-	{"getStacking", &BonusProxy::getStacking},
-	{"getDescription", &BonusProxy::getDescription},
-	{"toJsonNode", &BonusProxy::toJsonNode}
-};
-
 const std::vector<BonusProxy::CustomRegType> BonusProxy::REGISTER_CUSTOM =
 {
-
+	{"getType", &BonusProxy::getType, false},
+	{"getSubtype", &BonusProxy::getSubtype, false},
+	{"getDuration", &BonusProxy::getDuration, false},
+	{"getTurns", &BonusProxy::getTurns, false},
+	{"getValueType", &BonusProxy::getValueType, false},
+	{"getVal", &BonusProxy::getVal, false},
+	{"getSource", &BonusProxy::getSource, false},
+	{"getSourceID", &BonusProxy::getSourceID, false},
+	{"getEffectRange", &BonusProxy::getEffectRange, false},
+	{"getStacking", &BonusProxy::getStacking, false},
+	{"getDescription", &BonusProxy::getDescription, false},
+	{"toJsonNode", &BonusProxy::toJsonNode, false}
 };
 
-int BonusProxy::getType(lua_State * L, std::shared_ptr<const Bonus> object)
+int BonusProxy::getType(lua_State * L)
 {
+	LuaStack S(L);
+	std::shared_ptr<const Bonus> object;
+	if(!S.tryGet(1, object))
+		return S.retNil();
 	return LuaStack::quickRetInt(L, object->type);
 }
 
-int BonusProxy::getSubtype(lua_State * L, std::shared_ptr<const Bonus> object)
+int BonusProxy::getSubtype(lua_State * L)
 {
+	LuaStack S(L);
+	std::shared_ptr<const Bonus> object;
+	if(!S.tryGet(1, object))
+		return S.retNil();
 	return LuaStack::quickRetInt(L, object->subtype);
 }
 
-int BonusProxy::getDuration(lua_State * L, std::shared_ptr<const Bonus> object)
+int BonusProxy::getDuration(lua_State * L)
 {
+	LuaStack S(L);
+	std::shared_ptr<const Bonus> object;
+	if(!S.tryGet(1, object))
+		return S.retNil();
 	return LuaStack::quickRetInt(L, object->duration);
 }
 
-int BonusProxy::getTurns(lua_State * L, std::shared_ptr<const Bonus> object)
+int BonusProxy::getTurns(lua_State * L)
 {
+	LuaStack S(L);
+	std::shared_ptr<const Bonus> object;
+	if(!S.tryGet(1, object))
+		return S.retNil();
 	return LuaStack::quickRetInt(L, object->turnsRemain);
 }
 
-int BonusProxy::getValueType(lua_State * L, std::shared_ptr<const Bonus> object)
+int BonusProxy::getValueType(lua_State * L)
 {
+	LuaStack S(L);
+	std::shared_ptr<const Bonus> object;
+	if(!S.tryGet(1, object))
+		return S.retNil();
 	return LuaStack::quickRetInt(L, object->valType);
 }
 
-int BonusProxy::getVal(lua_State * L, std::shared_ptr<const Bonus> object)
+int BonusProxy::getVal(lua_State * L)
 {
+	LuaStack S(L);
+	std::shared_ptr<const Bonus> object;
+	if(!S.tryGet(1, object))
+		return S.retNil();
 	return LuaStack::quickRetInt(L, object->val);
 }
 
-int BonusProxy::getSource(lua_State * L, std::shared_ptr<const Bonus> object)
+int BonusProxy::getSource(lua_State * L)
 {
+	LuaStack S(L);
+	std::shared_ptr<const Bonus> object;
+	if(!S.tryGet(1, object))
+		return S.retNil();
 	return LuaStack::quickRetInt(L, object->source);
 }
 
-int BonusProxy::getSourceID(lua_State * L, std::shared_ptr<const Bonus> object)
+int BonusProxy::getSourceID(lua_State * L)
 {
+	LuaStack S(L);
+	std::shared_ptr<const Bonus> object;
+	if(!S.tryGet(1, object))
+		return S.retNil();
 	return LuaStack::quickRetInt(L, object->sid);
 }
 
-int BonusProxy::getEffectRange(lua_State * L, std::shared_ptr<const Bonus> object)
+int BonusProxy::getEffectRange(lua_State * L)
 {
+	LuaStack S(L);
+	std::shared_ptr<const Bonus> object;
+	if(!S.tryGet(1, object))
+		return S.retNil();
 	return LuaStack::quickRetInt(L, object->effectRange);
 }
 
-int BonusProxy::getStacking(lua_State * L, std::shared_ptr<const Bonus> object)
+int BonusProxy::getStacking(lua_State * L)
 {
+	LuaStack S(L);
+	std::shared_ptr<const Bonus> object;
+	if(!S.tryGet(1, object))
+		return S.retNil();
 	return LuaStack::quickRetStr(L, object->stacking);
 }
 
-int BonusProxy::getDescription(lua_State * L, std::shared_ptr<const Bonus> object)
+int BonusProxy::getDescription(lua_State * L)
 {
+	LuaStack S(L);
+	std::shared_ptr<const Bonus> object;
+	if(!S.tryGet(1, object))
+		return S.retNil();
 	return LuaStack::quickRetStr(L, object->description);
 }
 
-int BonusProxy::toJsonNode(lua_State * L, std::shared_ptr<const Bonus> object)
+int BonusProxy::toJsonNode(lua_State * L)
 {
 	LuaStack S(L);
+	std::shared_ptr<const Bonus> object;
+	if(!S.tryGet(1, object))
+		return S.retNil();
 	S.clear();
 	S.push(object->toJsonNode());
 	return 1;
@@ -133,67 +175,48 @@ void BonusProxy::adjustStaticTable(lua_State * L) const
 
 VCMI_REGISTER_SCRIPT_API(BonusListProxy, "BonusList");
 
-const std::vector<BonusListProxy::RegType> BonusListProxy::REGISTER =
-{
-
-};
-
 const std::vector<BonusListProxy::CustomRegType> BonusListProxy::REGISTER_CUSTOM =
 {
 
 };
 
-int BonusListProxy::index(lua_State * L)
+std::shared_ptr<const Bonus> BonusListProxy::index(std::shared_ptr<const BonusList> self, int key)
 {
 	//field = __index(self, key)
-	LuaStack S(L);
-
-	std::shared_ptr<const BonusList> self;
-	lua_Integer key = -1;
 
-	if(S.tryGet(1, self) && S.tryGetInteger(2, key))
-	{
-		if((key >= 1) && (key <= self->size()))
-		{
-			std::shared_ptr<const Bonus> ret = (*self)[key-1];
+	std::shared_ptr<const Bonus> ret;
 
-			S.clear();
-			S.push(ret);
-			return 1;
-		}
-	}
-
-	return S.retNil();
+	if((key >= 1) && (key <= self->size()))
+		ret = (*self)[key-1];
+	return ret;
 }
 
 void BonusListProxy::adjustMetatable(lua_State * L) const
 {
 	lua_pushstring(L, "__index");
-	lua_pushcfunction(L, &BonusListProxy::index);
+	lua_pushcclosure(L, LuaFunctionWrapper<decltype(&BonusListProxy::index), &BonusListProxy::index>::invoke, 0);
 	lua_rawset(L, -3);
 }
 
-
 VCMI_REGISTER_SCRIPT_API(BonusBearerProxy, "BonusBearer");
 
-const std::vector<BonusBearerProxy::RegType> BonusBearerProxy::REGISTER =
-{
-	{"getBonuses", &BonusBearerProxy::getBonuses},
-};
-
 const std::vector<BonusBearerProxy::CustomRegType> BonusBearerProxy::REGISTER_CUSTOM =
 {
-
+	{"getBonuses", &BonusBearerProxy::getBonuses, false},
 };
 
-int BonusBearerProxy::getBonuses(lua_State * L, const IBonusBearer * object)
+int BonusBearerProxy::getBonuses(lua_State * L)
 {
 	LuaStack S(L);
 
+	const IBonusBearer * object = nullptr;
+	if(!S.tryGet(1, object))
+		return S.retNil();
+
 	TConstBonusListPtr ret;
 
-	const bool hasSelector = S.isFunction(1);
-	const bool hasRangeSelector = S.isFunction(2);
+	const bool hasSelector = S.isFunction(2);
+	const bool hasRangeSelector = S.isFunction(3);
 
 	if(hasSelector)
 	{

+ 15 - 18
scripting/lua/api/BonusSystem.h

@@ -26,21 +26,20 @@ class BonusProxy : public SharedWrapper<const Bonus, BonusProxy>
 public:
 	using Wrapper = SharedWrapper<const Bonus, BonusProxy>;
 
-	static const std::vector<typename Wrapper::RegType> REGISTER;
 	static const std::vector<typename Wrapper::CustomRegType> REGISTER_CUSTOM;
 
-	static int getType(lua_State * L, std::shared_ptr<const Bonus> object);
-	static int getSubtype(lua_State * L, std::shared_ptr<const Bonus> object);
-	static int getDuration(lua_State * L, std::shared_ptr<const Bonus> object);
-	static int getTurns(lua_State * L, std::shared_ptr<const Bonus> object);
-	static int getValueType(lua_State * L, std::shared_ptr<const Bonus> object);
-	static int getVal(lua_State * L, std::shared_ptr<const Bonus> object);
-	static int getSource(lua_State * L, std::shared_ptr<const Bonus> object);
-	static int getSourceID(lua_State * L, std::shared_ptr<const Bonus> object);
-	static int getDescription(lua_State * L, std::shared_ptr<const Bonus> object);
-	static int getEffectRange(lua_State * L, std::shared_ptr<const Bonus> object);
-	static int getStacking(lua_State * L, std::shared_ptr<const Bonus> object);
-	static int toJsonNode(lua_State * L, std::shared_ptr<const Bonus> object);
+	static int getType(lua_State * L);
+	static int getSubtype(lua_State * L);
+	static int getDuration(lua_State * L);
+	static int getTurns(lua_State * L);
+	static int getValueType(lua_State * L);
+	static int getVal(lua_State * L);
+	static int getSource(lua_State * L);
+	static int getSourceID(lua_State * L);
+	static int getDescription(lua_State * L);
+	static int getEffectRange(lua_State * L);
+	static int getStacking(lua_State * L);
+	static int toJsonNode(lua_State * L);
 
 protected:
 	virtual void adjustStaticTable(lua_State * L) const override;
@@ -51,10 +50,9 @@ class BonusListProxy : public SharedWrapper<const BonusList, BonusListProxy>
 public:
 	using Wrapper = SharedWrapper<const BonusList, BonusListProxy>;
 
-	static const std::vector<typename Wrapper::RegType> REGISTER;
 	static const std::vector<typename Wrapper::CustomRegType> REGISTER_CUSTOM;
 
-	static int index(lua_State * L);
+	static std::shared_ptr<const Bonus> index(std::shared_ptr<const BonusList> self, int key);
 protected:
 	virtual void adjustMetatable(lua_State * L) const override;
 };
@@ -64,10 +62,9 @@ class BonusBearerProxy : public OpaqueWrapper<const IBonusBearer, BonusBearerPro
 public:
 	using Wrapper = OpaqueWrapper<const IBonusBearer, BonusBearerProxy>;
 
-	static int getBonuses(lua_State * L, const IBonusBearer * object);
-
-	static const std::vector<typename Wrapper::RegType> REGISTER;
 	static const std::vector<typename Wrapper::CustomRegType> REGISTER_CUSTOM;
+
+	static int getBonuses(lua_State * L);
 };
 
 

+ 30 - 34
scripting/lua/api/Creature.cpp

@@ -24,42 +24,38 @@ namespace api
 
 VCMI_REGISTER_CORE_SCRIPT_API(CreatureProxy, "Creature");
 
-const std::vector<CreatureProxy::RegType> CreatureProxy::REGISTER =
-{
-	{"getCost", LuaCallWrapper<const Creature>::createFunctor(&Creature::getCost)},
-	{"isDoubleWide", LuaCallWrapper<const Creature>::createFunctor(&Creature::isDoubleWide)},
-};
-
 const std::vector<CreatureProxy::CustomRegType> CreatureProxy::REGISTER_CUSTOM =
 {
-	{"getIconIndex", LuaMethodWrapper<Creature, int32_t(Entity:: *)()const, &Entity::getIconIndex>::invoke, false},
-	{"getIndex", LuaMethodWrapper<Creature, int32_t(Entity:: *)()const, &Entity::getIndex>::invoke, false},
-	{"getJsonKey", LuaMethodWrapper<Creature, const std::string &(Entity:: *)()const, &Entity::getJsonKey>::invoke, false},
-	{"getName", LuaMethodWrapper<Creature, const std::string &(Entity:: *)()const, &Entity::getName>::invoke, false},
-	{"accessBonuses", LuaMethodWrapper<Creature, const IBonusBearer *(EntityWithBonuses<CreatureID>:: *)()const, &EntityWithBonuses<CreatureID>::accessBonuses>::invoke, false},
-
-	{"getMaxHealth", LuaMethodWrapper<Creature, uint32_t(Creature:: *)()const, &Creature::getMaxHealth>::invoke, false},
-	{"getPluralName", LuaMethodWrapper<Creature, const std::string &(Creature:: *)()const, &Creature::getPluralName>::invoke, false},
-	{"getSingularName", LuaMethodWrapper<Creature, const std::string &(Creature:: *)()const, &Creature::getSingularName>::invoke, false},
-
-	{"getAdvMapAmountMin", LuaMethodWrapper<Creature, int32_t(Creature:: *)()const, &Creature::getAdvMapAmountMin>::invoke, false},
-	{"getAdvMapAmountMax", LuaMethodWrapper<Creature, int32_t(Creature:: *)()const, &Creature::getAdvMapAmountMax>::invoke, false},
-	{"getAIValue", LuaMethodWrapper<Creature, int32_t(Creature:: *)()const, &Creature::getAIValue>::invoke, false},
-	{"getFightValue", LuaMethodWrapper<Creature, int32_t(Creature:: *)()const, &Creature::getFightValue>::invoke, false},
-	{"getLevel", LuaMethodWrapper<Creature, int32_t(Creature:: *)()const, &Creature::getLevel>::invoke, false},
-	{"getGrowth", LuaMethodWrapper<Creature, int32_t(Creature:: *)()const, &Creature::getGrowth>::invoke, false},
-	{"getHorde", LuaMethodWrapper<Creature, int32_t(Creature:: *)()const, &Creature::getHorde>::invoke, false},
-	{"getFactionIndex", LuaMethodWrapper<Creature, int32_t(Creature:: *)()const, &Creature::getFactionIndex>::invoke, false},
-
-	{"getBaseAttack", LuaMethodWrapper<Creature, int32_t(Creature:: *)()const, &Creature::getBaseAttack>::invoke, false},
-	{"getBaseDefense", LuaMethodWrapper<Creature, int32_t(Creature:: *)()const, &Creature::getBaseDefense>::invoke, false},
-	{"getBaseDamageMin", LuaMethodWrapper<Creature, int32_t(Creature:: *)()const, &Creature::getBaseDamageMin>::invoke, false},
-	{"getBaseDamageMax", LuaMethodWrapper<Creature, int32_t(Creature:: *)()const, &Creature::getBaseDamageMax>::invoke, false},
-	{"getBaseHitPoints", LuaMethodWrapper<Creature, int32_t(Creature:: *)()const, &Creature::getBaseHitPoints>::invoke, false},
-	{"getBaseSpellPoints", LuaMethodWrapper<Creature, int32_t(Creature:: *)()const, &Creature::getBaseSpellPoints>::invoke, false},
-	{"getBaseSpeed", LuaMethodWrapper<Creature, int32_t(Creature:: *)()const, &Creature::getBaseSpeed>::invoke, false},
-	{"getBaseShots", LuaMethodWrapper<Creature, int32_t(Creature:: *)()const, &Creature::getBaseShots>::invoke, false},
-
+	{"getIconIndex", LuaMethodWrapper<Creature, decltype(&Entity::getIconIndex), &Entity::getIconIndex>::invoke, false},
+	{"getIndex", LuaMethodWrapper<Creature, decltype(&Entity::getIndex), &Entity::getIndex>::invoke, false},
+	{"getJsonKey", LuaMethodWrapper<Creature, decltype(&Entity::getJsonKey), &Entity::getJsonKey>::invoke, false},
+	{"getName", LuaMethodWrapper<Creature, decltype(&Entity::getName), &Entity::getName>::invoke, false},
+	{"accessBonuses", LuaMethodWrapper<Creature, decltype(&EntityWithBonuses<CreatureID>::accessBonuses), &EntityWithBonuses<CreatureID>::accessBonuses>::invoke, false},
+
+	{"getMaxHealth", LuaMethodWrapper<Creature,decltype(&Creature::getMaxHealth), &Creature::getMaxHealth>::invoke, false},
+	{"getPluralName", LuaMethodWrapper<Creature, decltype(&Creature::getPluralName), &Creature::getPluralName>::invoke, false},
+	{"getSingularName", LuaMethodWrapper<Creature, decltype(&Creature::getSingularName), &Creature::getSingularName>::invoke, false},
+
+	{"getAdvMapAmountMin", LuaMethodWrapper<Creature, decltype(&Creature::getAdvMapAmountMin), &Creature::getAdvMapAmountMin>::invoke, false},
+	{"getAdvMapAmountMax", LuaMethodWrapper<Creature, decltype(&Creature::getAdvMapAmountMax), &Creature::getAdvMapAmountMax>::invoke, false},
+	{"getAIValue", LuaMethodWrapper<Creature, decltype(&Creature::getAIValue), &Creature::getAIValue>::invoke, false},
+	{"getFightValue", LuaMethodWrapper<Creature, decltype(&Creature::getFightValue), &Creature::getFightValue>::invoke, false},
+	{"getLevel", LuaMethodWrapper<Creature, decltype(&Creature::getLevel), &Creature::getLevel>::invoke, false},
+	{"getGrowth", LuaMethodWrapper<Creature, decltype(&Creature::getGrowth), &Creature::getGrowth>::invoke, false},
+	{"getHorde", LuaMethodWrapper<Creature, decltype(&Creature::getHorde), &Creature::getHorde>::invoke, false},
+	{"getFactionIndex", LuaMethodWrapper<Creature, decltype(&Creature::getFactionIndex), &Creature::getFactionIndex>::invoke, false},
+
+	{"getBaseAttack", LuaMethodWrapper<Creature, decltype(&Creature::getBaseAttack), &Creature::getBaseAttack>::invoke, false},
+	{"getBaseDefense", LuaMethodWrapper<Creature, decltype(&Creature::getBaseDefense), &Creature::getBaseDefense>::invoke, false},
+	{"getBaseDamageMin", LuaMethodWrapper<Creature, decltype(&Creature::getBaseDamageMin), &Creature::getBaseDamageMin>::invoke, false},
+	{"getBaseDamageMax", LuaMethodWrapper<Creature, decltype(&Creature::getBaseDamageMax), &Creature::getBaseDamageMax>::invoke, false},
+	{"getBaseHitPoints", LuaMethodWrapper<Creature, decltype(&Creature::getBaseHitPoints), &Creature::getBaseHitPoints>::invoke, false},
+	{"getBaseSpellPoints", LuaMethodWrapper<Creature, decltype(&Creature::getBaseSpellPoints), &Creature::getBaseSpellPoints>::invoke, false},
+	{"getBaseSpeed", LuaMethodWrapper<Creature, decltype(&Creature::getBaseSpeed), &Creature::getBaseSpeed>::invoke, false},
+	{"getBaseShots", LuaMethodWrapper<Creature, decltype(&Creature::getBaseShots), &Creature::getBaseShots>::invoke, false},
+
+	{"getCost", LuaMethodWrapper<Creature, decltype(&Creature::getCost), &Creature::getCost>::invoke, false},
+	{"isDoubleWide", LuaMethodWrapper<Creature, decltype(&Creature::isDoubleWide), &Creature::isDoubleWide>::invoke, false},
 };
 
 }

+ 0 - 1
scripting/lua/api/Creature.h

@@ -24,7 +24,6 @@ class CreatureProxy : public OpaqueWrapper<const Creature, CreatureProxy>
 public:
 	using Wrapper = OpaqueWrapper<const Creature, CreatureProxy>;
 
-	static const std::vector<typename Wrapper::RegType> REGISTER;
 	static const std::vector<typename Wrapper::CustomRegType> REGISTER_CUSTOM;
 };
 

+ 5 - 7
scripting/lua/api/Faction.cpp

@@ -23,15 +23,13 @@ namespace api
 
 VCMI_REGISTER_CORE_SCRIPT_API(FactionProxy, "Faction");
 
-const std::vector<FactionProxy::RegType> FactionProxy::REGISTER = {};
-
 const std::vector<FactionProxy::CustomRegType> FactionProxy::REGISTER_CUSTOM =
 {
-	{"getIconIndex", LuaMethodWrapper<Faction, int32_t(Entity:: *)()const, &Entity::getIconIndex>::invoke, false},
-	{"getIndex", LuaMethodWrapper<Faction, int32_t(Entity:: *)()const, &Entity::getIndex>::invoke, false},
-	{"getJsonKey", LuaMethodWrapper<Faction, const std::string &(Entity:: *)()const, &Entity::getJsonKey>::invoke, false},
-	{"getName", LuaMethodWrapper<Faction, const std::string &(Entity:: *)()const, &Entity::getName>::invoke, false},
-	{"hasTown", LuaMethodWrapper<Faction, bool(Faction:: *)()const, &Faction::hasTown>::invoke, false},
+	{"getIconIndex", LuaMethodWrapper<Faction, decltype(&Entity::getIconIndex), &Entity::getIconIndex>::invoke, false},
+	{"getIndex", LuaMethodWrapper<Faction, decltype(&Entity::getIndex), &Entity::getIndex>::invoke, false},
+	{"getJsonKey", LuaMethodWrapper<Faction, decltype(&Entity::getJsonKey), &Entity::getJsonKey>::invoke, false},
+	{"getName", LuaMethodWrapper<Faction, decltype(&Entity::getName), &Entity::getName>::invoke, false},
+	{"hasTown", LuaMethodWrapper<Faction, decltype(&Faction::hasTown), &Faction::hasTown>::invoke, false},
 };
 
 }

+ 0 - 1
scripting/lua/api/Faction.h

@@ -23,7 +23,6 @@ class FactionProxy : public OpaqueWrapper<const Faction, FactionProxy>
 {
 public:
 	using Wrapper = OpaqueWrapper<const Faction, FactionProxy>;
-	static const std::vector<typename Wrapper::RegType> REGISTER;
 	static const std::vector<typename Wrapper::CustomRegType> REGISTER_CUSTOM;
 };
 

+ 7 - 9
scripting/lua/api/GameCb.cpp

@@ -24,19 +24,17 @@ namespace api
 
 VCMI_REGISTER_CORE_SCRIPT_API(GameCbProxy, "Game");
 
-const std::vector<GameCbProxy::RegType> GameCbProxy::REGISTER = {};
-
 const std::vector<GameCbProxy::CustomRegType> GameCbProxy::REGISTER_CUSTOM =
 {
-	{"getDate", LuaMethodWrapper<GameCb, int32_t(GameCb:: *)(Date::EDateType)const, &GameCb::getDate>::invoke, false},
-	{"isAllowed", LuaMethodWrapper<GameCb, bool(GameCb:: *)(int32_t, int32_t)const, &GameCb::isAllowed>::invoke, false},
-	{"getCurrentPlayer", LuaMethodWrapper<GameCb, PlayerColor(GameCb:: *)()const, &GameCb::getLocalPlayer>::invoke, false},
-	{"getPlayer", LuaMethodWrapper<GameCb, const Player * (GameCb:: *)(PlayerColor)const, &GameCb::getPlayer>::invoke, false},
+	{"getDate", LuaMethodWrapper<GameCb, decltype(&GameCb::getDate), &GameCb::getDate>::invoke, false},
+	{"isAllowed", LuaMethodWrapper<GameCb, decltype(&GameCb::isAllowed), &GameCb::isAllowed>::invoke, false},
+	{"getCurrentPlayer", LuaMethodWrapper<GameCb, decltype(&GameCb::getLocalPlayer), &GameCb::getLocalPlayer>::invoke, false},
+	{"getPlayer", LuaMethodWrapper<GameCb, decltype(&GameCb::getPlayer), &GameCb::getPlayer>::invoke, false},
 
-	{"getHero", LuaMethodWrapper<GameCb, const CGHeroInstance *(GameCb:: *)(ObjectInstanceID)const, &GameCb::getHero>::invoke, false},
-	{"getHeroWithSubid", LuaMethodWrapper<GameCb, const CGHeroInstance *(GameCb:: *)(int)const, &GameCb::getHeroWithSubid>::invoke, false},
+	{"getHero", LuaMethodWrapper<GameCb, decltype(&GameCb::getHero), &GameCb::getHero>::invoke, false},
+	{"getHeroWithSubid", LuaMethodWrapper<GameCb, decltype(&GameCb::getHeroWithSubid), &GameCb::getHeroWithSubid>::invoke, false},
 
-	{"getObj", LuaMethodWrapper<GameCb, const CGObjectInstance *(GameCb:: *)(ObjectInstanceID, bool)const, &GameCb::getObj>::invoke, false},
+	{"getObj", LuaMethodWrapper<GameCb, decltype(&GameCb::getObj), &GameCb::getObj>::invoke, false},
 };
 
 }

+ 0 - 1
scripting/lua/api/GameCb.h

@@ -25,7 +25,6 @@ class GameCbProxy : public OpaqueWrapper<const GameCb, GameCbProxy>
 public:
 	using Wrapper = OpaqueWrapper<const GameCb, GameCbProxy>;
 
-	static const std::vector<typename Wrapper::RegType> REGISTER;
 	static const std::vector<typename Wrapper::CustomRegType> REGISTER_CUSTOM;
 
 };

+ 4 - 6
scripting/lua/api/HeroClass.cpp

@@ -22,14 +22,12 @@ namespace api
 {
 VCMI_REGISTER_CORE_SCRIPT_API(HeroClassProxy, "HeroClass");
 
-const std::vector<HeroClassProxy::RegType> HeroClassProxy::REGISTER = {};
-
 const std::vector<HeroClassProxy::CustomRegType> HeroClassProxy::REGISTER_CUSTOM =
 {
-	{"getIconIndex", LuaMethodWrapper<HeroClass, int32_t(Entity:: *)()const, &Entity::getIconIndex>::invoke, false},
-	{"getIndex", LuaMethodWrapper<HeroClass, int32_t(Entity:: *)()const, &Entity::getIndex>::invoke, false},
-	{"getJsonKey", LuaMethodWrapper<HeroClass, const std::string &(Entity:: *)()const, &Entity::getJsonKey>::invoke, false},
-	{"getName", LuaMethodWrapper<HeroClass, const std::string &(Entity:: *)()const, &Entity::getName>::invoke, false},
+	{"getIconIndex", LuaMethodWrapper<HeroClass, decltype(&Entity::getIconIndex), &Entity::getIconIndex>::invoke, false},
+	{"getIndex", LuaMethodWrapper<HeroClass, decltype(&Entity::getIndex), &Entity::getIndex>::invoke, false},
+	{"getJsonKey", LuaMethodWrapper<HeroClass, decltype(&Entity::getJsonKey), &Entity::getJsonKey>::invoke, false},
+	{"getName", LuaMethodWrapper<HeroClass, decltype(&Entity::getName), &Entity::getName>::invoke, false},
 };
 
 }

+ 0 - 1
scripting/lua/api/HeroClass.h

@@ -23,7 +23,6 @@ class HeroClassProxy : public OpaqueWrapper<const HeroClass, HeroClassProxy>
 {
 public:
 	using Wrapper = OpaqueWrapper<const HeroClass, HeroClassProxy>;
-	static const std::vector<typename Wrapper::RegType> REGISTER;
 	static const std::vector<typename Wrapper::CustomRegType> REGISTER_CUSTOM;
 };
 

+ 2 - 4
scripting/lua/api/HeroInstance.cpp

@@ -22,12 +22,10 @@ namespace api
 {
 VCMI_REGISTER_CORE_SCRIPT_API(HeroInstanceProxy, "HeroInstance");
 
-const std::vector<HeroInstanceProxy::RegType> HeroInstanceProxy::REGISTER = {};
-
 const std::vector<HeroInstanceProxy::CustomRegType> HeroInstanceProxy::REGISTER_CUSTOM =
 {
-	{"getStack", LuaMethodWrapper<CGHeroInstance, const CStackInstance *(CCreatureSet:: *)(SlotID)const, &CCreatureSet::getStackPtr>::invoke, false},
-	{"getOwner", LuaMethodWrapper<CGHeroInstance, PlayerColor(CGObjectInstance:: *)()const, &CGObjectInstance::getOwner>::invoke, false},
+	{"getStack", LuaMethodWrapper<CGHeroInstance, decltype(&CCreatureSet::getStackPtr), &CCreatureSet::getStackPtr>::invoke, false},
+	{"getOwner", LuaMethodWrapper<CGHeroInstance, decltype(&CGObjectInstance::getOwner), &CGObjectInstance::getOwner>::invoke, false},
 };
 
 }

+ 0 - 1
scripting/lua/api/HeroInstance.h

@@ -25,7 +25,6 @@ class HeroInstanceProxy : public OpaqueWrapper<const CGHeroInstance, HeroInstanc
 {
 public:
 	using Wrapper = OpaqueWrapper<const CGHeroInstance, HeroInstanceProxy>;
-	static const std::vector<typename Wrapper::RegType> REGISTER;
 	static const std::vector<typename Wrapper::CustomRegType> REGISTER_CUSTOM;
 };
 

+ 4 - 6
scripting/lua/api/HeroType.cpp

@@ -23,14 +23,12 @@ namespace api
 
 VCMI_REGISTER_CORE_SCRIPT_API(HeroTypeProxy, "HeroType");
 
-const std::vector<HeroTypeProxy::RegType> HeroTypeProxy::REGISTER = {};
-
 const std::vector<HeroTypeProxy::CustomRegType> HeroTypeProxy::REGISTER_CUSTOM =
 {
-	{"getIconIndex", LuaMethodWrapper<HeroType, int32_t(Entity:: *)()const, &Entity::getIconIndex>::invoke, false},
-	{"getIndex", LuaMethodWrapper<HeroType, int32_t(Entity:: *)()const, &Entity::getIndex>::invoke, false},
-	{"getJsonKey", LuaMethodWrapper<HeroType, const std::string &(Entity:: *)()const, &Entity::getJsonKey>::invoke, false},
-	{"getName", LuaMethodWrapper<HeroType, const std::string &(Entity:: *)()const, &Entity::getName>::invoke, false},
+	{"getIconIndex", LuaMethodWrapper<HeroType, decltype(&Entity::getIconIndex), &Entity::getIconIndex>::invoke, false},
+	{"getIndex", LuaMethodWrapper<HeroType, decltype(&Entity::getIndex), &Entity::getIndex>::invoke, false},
+	{"getJsonKey", LuaMethodWrapper<HeroType, decltype(&Entity::getJsonKey), &Entity::getJsonKey>::invoke, false},
+	{"getName", LuaMethodWrapper<HeroType, decltype(&Entity::getName), &Entity::getName>::invoke, false},
 };
 
 

+ 0 - 1
scripting/lua/api/HeroType.h

@@ -23,7 +23,6 @@ class HeroTypeProxy : public OpaqueWrapper<const HeroType, HeroTypeProxy>
 {
 public:
 	using Wrapper = OpaqueWrapper<const HeroType, HeroTypeProxy>;
-	static const std::vector<typename Wrapper::RegType> REGISTER;
 	static const std::vector<typename Wrapper::CustomRegType> REGISTER_CUSTOM;
 };
 

+ 5 - 7
scripting/lua/api/ObjectInstance.cpp

@@ -22,15 +22,13 @@ namespace api
 {
 VCMI_REGISTER_CORE_SCRIPT_API(ObjectInstanceProxy, "ObjectInstance");
 
-const std::vector<ObjectInstanceProxy::RegType> ObjectInstanceProxy::REGISTER = {};
-
 const std::vector<ObjectInstanceProxy::CustomRegType> ObjectInstanceProxy::REGISTER_CUSTOM =
 {
-	{"getOwner", LuaMethodWrapper<CGObjectInstance, PlayerColor(IObjectInterface:: *)()const, &IObjectInterface::getOwner>::invoke, false},
-	{"getObjGroupIndex", LuaMethodWrapper<CGObjectInstance, int32_t(IObjectInterface:: *)()const, &IObjectInterface::getObjGroupIndex>::invoke, false},
-	{"getObjTypeIndex", LuaMethodWrapper<CGObjectInstance, int32_t(IObjectInterface:: *)()const, &IObjectInterface::getObjTypeIndex>::invoke, false},
-	{"getVisitablePosition", LuaMethodWrapper<CGObjectInstance, int3(IObjectInterface:: *)()const, &IObjectInterface::visitablePos>::invoke, false},
-	{"getPosition", LuaMethodWrapper<CGObjectInstance, int3(IObjectInterface:: *)()const, &IObjectInterface::getPosition>::invoke, false},
+	{"getOwner", LuaMethodWrapper<CGObjectInstance, decltype(&IObjectInterface::getOwner), &IObjectInterface::getOwner>::invoke, false},
+	{"getObjGroupIndex", LuaMethodWrapper<CGObjectInstance, decltype(&IObjectInterface::getObjGroupIndex), &IObjectInterface::getObjGroupIndex>::invoke, false},
+	{"getObjTypeIndex", LuaMethodWrapper<CGObjectInstance, decltype(&IObjectInterface::getObjTypeIndex), &IObjectInterface::getObjTypeIndex>::invoke, false},
+	{"getVisitablePosition", LuaMethodWrapper<CGObjectInstance, decltype(&IObjectInterface::visitablePos), &IObjectInterface::visitablePos>::invoke, false},
+	{"getPosition", LuaMethodWrapper<CGObjectInstance, decltype(IObjectInterface::getPosition), &IObjectInterface::getPosition>::invoke, false},
 };
 
 }

+ 0 - 1
scripting/lua/api/ObjectInstance.h

@@ -25,7 +25,6 @@ class ObjectInstanceProxy : public OpaqueWrapper<const CGObjectInstance, ObjectI
 {
 public:
 	using Wrapper = OpaqueWrapper<const CGObjectInstance, ObjectInstanceProxy>;
-	static const std::vector<typename Wrapper::RegType> REGISTER;
 	static const std::vector<typename Wrapper::CustomRegType> REGISTER_CUSTOM;
 };
 

+ 0 - 4
scripting/lua/api/Player.cpp

@@ -24,10 +24,6 @@ namespace api
 
 VCMI_REGISTER_CORE_SCRIPT_API(PlayerProxy, "Player");
 
-const std::vector<PlayerProxy::RegType> PlayerProxy::REGISTER =
-{
-};
-
 const std::vector<PlayerProxy::CustomRegType> PlayerProxy::REGISTER_CUSTOM =
 {
 //	virtual PlayerColor getColor() const = 0;

+ 0 - 2
scripting/lua/api/Player.h

@@ -23,8 +23,6 @@ class PlayerProxy : public OpaqueWrapper<const Player, PlayerProxy>
 {
 public:
 	using Wrapper = OpaqueWrapper<const Player, PlayerProxy>;
-
-	static const std::vector<typename Wrapper::RegType> REGISTER;
 	static const std::vector<typename Wrapper::CustomRegType> REGISTER_CUSTOM;
 
 };

+ 29 - 20
scripting/lua/api/ServerCb.cpp

@@ -22,38 +22,43 @@ namespace api
 
 VCMI_REGISTER_CORE_SCRIPT_API(ServerCbProxy, "Server");
 
-const std::vector<ServerCbProxy::RegType> ServerCbProxy::REGISTER =
+const std::vector<ServerCbProxy::CustomRegType> ServerCbProxy::REGISTER_CUSTOM =
 {
 	{
 		"addToBattleLog",
-		&ServerCbProxy::apply<BattleLogMessage>
+		&ServerCbProxy::apply<BattleLogMessage>,
+		false
 	},
 	{
 		"moveUnit",
-		&ServerCbProxy::apply<BattleStackMoved>
+		&ServerCbProxy::apply<BattleStackMoved>,
+		false
 	},
 	{
 		"changeUnits",
-		&ServerCbProxy::apply<BattleUnitsChanged>
+		&ServerCbProxy::apply<BattleUnitsChanged>,
+		false
 	},
 	{
 		"commitPackage",
-		&ServerCbProxy::commitPackage
+		&ServerCbProxy::commitPackage,
+		false
 	}
 };
 
-const std::vector<ServerCbProxy::CustomRegType> ServerCbProxy::REGISTER_CUSTOM =
+int ServerCbProxy::commitPackage(lua_State * L)
 {
+	LuaStack S(L);
 
-};
+	ServerCallback * object = nullptr;
+
+	if(!S.tryGet(1, object))
+		return S.retNil();
+
+	lua_remove(L, 1);
 
-int ServerCbProxy::commitPackage(lua_State * L, ServerCallback * object)
-{
 	if(lua_isuserdata(L, 1) != 1)
-	{
-		lua_settop(L, 0);
-		return 0;
-	}
+		return S.retVoid();
 
 	lua_getfield(L, 1, "toNetpackLight");
 	lua_insert(L, 1);
@@ -61,24 +66,28 @@ int ServerCbProxy::commitPackage(lua_State * L, ServerCallback * object)
 	int ret = lua_pcall(L, 1, 1, 0);
 
 	if(ret != 0 || !lua_islightuserdata(L, 1))
-	{
-		lua_settop(L, 0);
-		return 0;
-	}
+		return S.retVoid();
+
 
 	CPackForClient * pack = static_cast<CPackForClient *>(lua_touserdata(L, 1));
 
 	object->apply(pack);
 
-	lua_settop(L, 0);
-	return 0;
+	return S.retVoid();
 }
 
 template<typename NetPack>
-int ServerCbProxy::apply(lua_State * L, ServerCallback * object)
+int ServerCbProxy::apply(lua_State * L)
 {
 	LuaStack S(L);
 
+	ServerCallback * object = nullptr;
+
+	if(!S.tryGet(1, object))
+		return S.retNil();
+
+	lua_remove(L, 1);
+
 	std::shared_ptr<NetPack> pack;
 
 	if(!S.tryGet(1, pack))

+ 2 - 4
scripting/lua/api/ServerCb.h

@@ -24,13 +24,11 @@ class ServerCbProxy : public OpaqueWrapper<ServerCallback, ServerCbProxy>
 public:
 	using Wrapper = OpaqueWrapper<ServerCallback, ServerCbProxy>;
 
-	static int commitPackage(lua_State * L, ServerCallback * object);
-
-	static const std::vector<typename Wrapper::RegType> REGISTER;
 	static const std::vector<typename Wrapper::CustomRegType> REGISTER_CUSTOM;
 
 	template<typename NetPack>
-	static int apply(lua_State * L, ServerCallback * object);
+	static int apply(lua_State * L);
+	static int commitPackage(lua_State * L);
 };
 
 }

+ 14 - 54
scripting/lua/api/Services.cpp

@@ -33,104 +33,64 @@ namespace api
 
 VCMI_REGISTER_CORE_SCRIPT_API(ServicesProxy, "Services");
 
-const std::vector<ServicesProxy::RegType> ServicesProxy::REGISTER =
-{
-	{"artifacts", LuaCallWrapper<const Services>::createFunctor(&Services::artifacts)},
-	{"creatures", LuaCallWrapper<const Services>::createFunctor(&Services::creatures)},
-	{"factions", LuaCallWrapper<const Services>::createFunctor(&Services::factions)},
-	{"heroClasses", LuaCallWrapper<const Services>::createFunctor(&Services::heroClasses)},
-	{"heroTypes", LuaCallWrapper<const Services>::createFunctor(&Services::heroTypes)},
-	{"spells", LuaCallWrapper<const Services>::createFunctor(&Services::spells)},
-	{"skills", LuaCallWrapper<const Services>::createFunctor(&Services::skills)},
-};
-
 const std::vector<ServicesProxy::CustomRegType> ServicesProxy::REGISTER_CUSTOM =
 {
-
+	{"artifacts", LuaMethodWrapper<Services, decltype(&Services::artifacts), &Services::artifacts>::invoke, false},
+	{"creatures", LuaMethodWrapper<Services, decltype(&Services::creatures), &Services::creatures>::invoke, false},
+	{"factions", LuaMethodWrapper<Services, decltype(&Services::factions), &Services::factions>::invoke, false},
+	{"heroClasses", LuaMethodWrapper<Services, decltype(&Services::heroClasses), &Services::heroClasses>::invoke, false},
+	{"heroTypes", LuaMethodWrapper<Services,decltype(&Services::heroTypes), &Services::heroTypes>::invoke, false},
+	{"spells", LuaMethodWrapper<Services, decltype(&Services::spells), &Services::spells>::invoke, false},
+	{"skills", LuaMethodWrapper<Services,decltype(&Services::skills), &Services::skills>::invoke, false},
 };
 
 VCMI_REGISTER_CORE_SCRIPT_API(ArtifactServiceProxy, "Artifacts");
 
-const std::vector<ArtifactServiceProxy::RegType> ArtifactServiceProxy::REGISTER =
-{
-	{"getByIndex", LuaCallWrapper<const EntityServiceT<ArtifactID, Artifact>>::createFunctor(&ArtifactService::getByIndex)}
-};
-
 const std::vector<ArtifactServiceProxy::CustomRegType> ArtifactServiceProxy::REGISTER_CUSTOM =
 {
-
+	{"getByIndex", LuaMethodWrapper<ArtifactService, decltype(&ArtifactService::getByIndex), &ArtifactService::getByIndex>::invoke, false}
 };
 
 VCMI_REGISTER_CORE_SCRIPT_API(CreatureServiceProxy, "Creatures");
 
-const std::vector<CreatureServiceProxy::RegType> CreatureServiceProxy::REGISTER =
-{
-	{"getByIndex", LuaCallWrapper<const EntityServiceT<CreatureID, Creature>>::createFunctor(&CreatureService::getByIndex)}
-};
-
 const std::vector<CreatureServiceProxy::CustomRegType> CreatureServiceProxy::REGISTER_CUSTOM =
 {
-
+	{"getByIndex", LuaMethodWrapper<CreatureService, decltype(&CreatureService::getByIndex), &CreatureService::getByIndex>::invoke, false}
 };
 
 VCMI_REGISTER_CORE_SCRIPT_API(FactionServiceProxy, "Factions");
 
-const std::vector<FactionServiceProxy::RegType> FactionServiceProxy::REGISTER =
-{
-	{"getByIndex", LuaCallWrapper<const EntityServiceT<FactionID, Faction>>::createFunctor(&FactionService::getByIndex)}
-};
-
 const std::vector<FactionServiceProxy::CustomRegType> FactionServiceProxy::REGISTER_CUSTOM =
 {
-
+	{"getByIndex", LuaMethodWrapper<FactionService, decltype(&FactionService::getByIndex), &FactionService::getByIndex>::invoke, false}
 };
 
 VCMI_REGISTER_CORE_SCRIPT_API(HeroClassServiceProxy, "HeroClasses");
 
-const std::vector<HeroClassServiceProxy::RegType> HeroClassServiceProxy::REGISTER =
-{
-	{"getByIndex", LuaCallWrapper<const EntityServiceT<HeroClassID, HeroClass>>::createFunctor(&HeroClassService::getByIndex)}
-};
-
 const std::vector<HeroClassServiceProxy::CustomRegType> HeroClassServiceProxy::REGISTER_CUSTOM =
 {
-
+	{"getByIndex", LuaMethodWrapper<HeroClassService, decltype(&HeroClassService::getByIndex), &HeroClassService::getByIndex>::invoke, false}
 };
 
 VCMI_REGISTER_CORE_SCRIPT_API(HeroTypeServiceProxy, "HeroTypes");
 
-const std::vector<HeroTypeServiceProxy::RegType> HeroTypeServiceProxy::REGISTER =
-{
-	{"getByIndex", LuaCallWrapper<const EntityServiceT<HeroTypeID, HeroType>>::createFunctor(&HeroTypeService::getByIndex)}
-};
-
 const std::vector<HeroTypeServiceProxy::CustomRegType> HeroTypeServiceProxy::REGISTER_CUSTOM =
 {
-
+	{"getByIndex", LuaMethodWrapper<HeroTypeService, decltype(&HeroTypeService::getByIndex), &HeroTypeService::getByIndex>::invoke, false}
 };
 
 VCMI_REGISTER_CORE_SCRIPT_API(SkillServiceProxy, "Skills");
 
-const std::vector<SkillServiceProxy::RegType> SkillServiceProxy::REGISTER =
-{
-	{"getByIndex", LuaCallWrapper<const EntityServiceT<SecondarySkill, Skill>>::createFunctor(&SkillService::getByIndex)}
-};
-
 const std::vector<SkillServiceProxy::CustomRegType> SkillServiceProxy::REGISTER_CUSTOM =
 {
-
+	{"getByIndex", LuaMethodWrapper<SkillService, decltype(&SkillService::getByIndex), &SkillService::getByIndex>::invoke, false}
 };
 
 VCMI_REGISTER_CORE_SCRIPT_API(SpellServiceProxy, "Spells");
 
-const std::vector<SpellServiceProxy::RegType> SpellServiceProxy::REGISTER =
-{
-	{"getByIndex", LuaCallWrapper<const EntityServiceT<SpellID, spells::Spell>>::createFunctor(&spells::Service::getByIndex)}
-};
-
 const std::vector<SpellServiceProxy::CustomRegType> SpellServiceProxy::REGISTER_CUSTOM =
 {
-
+	{"getByIndex", LuaMethodWrapper<spells::Service, decltype(&spells::Service::getByIndex), &spells::Service::getByIndex>::invoke, false}
 };
 
 }

+ 0 - 8
scripting/lua/api/Services.h

@@ -31,7 +31,6 @@ class ServicesProxy : public OpaqueWrapper<const Services, ServicesProxy>
 {
 public:
 	using Wrapper = OpaqueWrapper<const Services, ServicesProxy>;
-	static const std::vector<typename Wrapper::RegType> REGISTER;
 	static const std::vector<typename Wrapper::CustomRegType> REGISTER_CUSTOM;
 };
 
@@ -39,7 +38,6 @@ class ArtifactServiceProxy : public OpaqueWrapper<const ArtifactService, Artifac
 {
 public:
 	using Wrapper = OpaqueWrapper<const ArtifactService, ArtifactServiceProxy>;
-	static const std::vector<typename Wrapper::RegType> REGISTER;
 	static const std::vector<typename Wrapper::CustomRegType> REGISTER_CUSTOM;
 };
 
@@ -47,7 +45,6 @@ class CreatureServiceProxy : public OpaqueWrapper<const CreatureService, Creatur
 {
 public:
 	using Wrapper = OpaqueWrapper<const CreatureService, CreatureServiceProxy>;
-	static const std::vector<typename Wrapper::RegType> REGISTER;
 	static const std::vector<typename Wrapper::CustomRegType> REGISTER_CUSTOM;
 };
 
@@ -55,7 +52,6 @@ class FactionServiceProxy : public OpaqueWrapper<const FactionService, FactionSe
 {
 public:
 	using Wrapper = OpaqueWrapper<const FactionService, FactionServiceProxy>;
-	static const std::vector<typename Wrapper::RegType> REGISTER;
 	static const std::vector<typename Wrapper::CustomRegType> REGISTER_CUSTOM;
 };
 
@@ -63,7 +59,6 @@ class HeroClassServiceProxy : public OpaqueWrapper<const HeroClassService, HeroC
 {
 public:
 	using Wrapper = OpaqueWrapper<const HeroClassService, HeroClassServiceProxy>;
-	static const std::vector<typename Wrapper::RegType> REGISTER;
 	static const std::vector<typename Wrapper::CustomRegType> REGISTER_CUSTOM;
 };
 
@@ -71,7 +66,6 @@ class HeroTypeServiceProxy : public OpaqueWrapper<const HeroTypeService, HeroTyp
 {
 public:
 	using Wrapper = OpaqueWrapper<const HeroTypeService, HeroTypeServiceProxy>;
-	static const std::vector<typename Wrapper::RegType> REGISTER;
 	static const std::vector<typename Wrapper::CustomRegType> REGISTER_CUSTOM;
 };
 
@@ -79,7 +73,6 @@ class SkillServiceProxy : public OpaqueWrapper<const SkillService, SkillServiceP
 {
 public:
 	using Wrapper = OpaqueWrapper<const SkillService, SkillServiceProxy>;
-	static const std::vector<typename Wrapper::RegType> REGISTER;
 	static const std::vector<typename Wrapper::CustomRegType> REGISTER_CUSTOM;
 };
 
@@ -87,7 +80,6 @@ class SpellServiceProxy : public OpaqueWrapper<const spells::Service, SpellServi
 {
 public:
 	using Wrapper = OpaqueWrapper<const spells::Service, SpellServiceProxy>;
-	static const std::vector<typename Wrapper::RegType> REGISTER;
 	static const std::vector<typename Wrapper::CustomRegType> REGISTER_CUSTOM;
 };
 

+ 4 - 6
scripting/lua/api/Skill.cpp

@@ -22,14 +22,12 @@ namespace api
 {
 VCMI_REGISTER_CORE_SCRIPT_API(SkillProxy, "Skill");
 
-const std::vector<SkillProxy::RegType> SkillProxy::REGISTER = {};
-
 const std::vector<SkillProxy::CustomRegType> SkillProxy::REGISTER_CUSTOM =
 {
-	{"getIconIndex", LuaMethodWrapper<Skill, int32_t(Entity:: *)()const, &Entity::getIconIndex>::invoke, false},
-	{"getIndex", LuaMethodWrapper<Skill, int32_t(Entity:: *)()const, &Entity::getIndex>::invoke, false},
-	{"getJsonKey", LuaMethodWrapper<Skill, const std::string &(Entity:: *)()const, &Entity::getJsonKey>::invoke, false},
-	{"getName", LuaMethodWrapper<Skill, const std::string &(Entity:: *)()const, &Entity::getName>::invoke, false},
+	{"getIconIndex", LuaMethodWrapper<Skill, decltype(&Entity::getIconIndex), &Entity::getIconIndex>::invoke, false},
+	{"getIndex", LuaMethodWrapper<Skill, decltype(&Entity::getIndex), &Entity::getIndex>::invoke, false},
+	{"getJsonKey", LuaMethodWrapper<Skill, decltype(&Entity::getJsonKey), &Entity::getJsonKey>::invoke, false},
+	{"getName", LuaMethodWrapper<Skill, decltype(&Entity::getName), &Entity::getName>::invoke, false},
 };
 
 }

+ 0 - 1
scripting/lua/api/Skill.h

@@ -23,7 +23,6 @@ class SkillProxy : public OpaqueWrapper<const Skill, SkillProxy>
 {
 public:
 	using Wrapper = OpaqueWrapper<const Skill, SkillProxy>;
-	static const std::vector<typename Wrapper::RegType> REGISTER;
 	static const std::vector<typename Wrapper::CustomRegType> REGISTER_CUSTOM;
 };
 

+ 19 - 23
scripting/lua/api/Spell.cpp

@@ -26,31 +26,27 @@ VCMI_REGISTER_CORE_SCRIPT_API(SpellProxy, "Spell");
 
 //TODO:calculateDamage,forEachSchool
 
-const std::vector<SpellProxy::RegType> SpellProxy::REGISTER =
-{
-	{"getCost", LuaCallWrapper<const Spell>::createFunctor(&Spell::getCost)},
-	{"getBasePower", LuaCallWrapper<const Spell>::createFunctor(&Spell::getBasePower)},
-	{"getLevelPower", LuaCallWrapper<const Spell>::createFunctor(&Spell::getLevelPower)},
-	{"getLevelDescription", LuaCallWrapper<const Spell>::createFunctor(&Spell::getLevelDescription)},
-};
-
 const std::vector<SpellProxy::CustomRegType> SpellProxy::REGISTER_CUSTOM =
 {
-	{"getIconIndex", LuaMethodWrapper<Spell, int32_t(Entity:: *)()const, &Entity::getIconIndex>::invoke, false},
-	{"getIndex", LuaMethodWrapper<Spell, int32_t(Entity:: *)()const, &Entity::getIndex>::invoke, false},
-	{"getJsonKey", LuaMethodWrapper<Spell, const std::string &(Entity:: *)()const, &Entity::getJsonKey>::invoke, false},
-	{"getName", LuaMethodWrapper<Spell, const std::string &(Entity:: *)()const, &Entity::getName>::invoke, false},
-
-	{"isAdventure", LuaMethodWrapper<Spell, bool(Spell:: *)()const, &Spell::isAdventure>::invoke, false},
-	{"isCombat", LuaMethodWrapper<Spell, bool(Spell:: *)()const, &Spell::isCombat>::invoke, false},
-	{"isCreatureAbility", LuaMethodWrapper<Spell, bool(Spell:: *)()const, &Spell::isCreatureAbility>::invoke, false},
-	{"isPositive", LuaMethodWrapper<Spell, bool(Spell:: *)()const, &Spell::isPositive>::invoke, false},
-	{"isNegative", LuaMethodWrapper<Spell, bool(Spell:: *)()const, &Spell::isNegative>::invoke, false},
-	{"isNeutral", LuaMethodWrapper<Spell, bool(Spell:: *)()const, &Spell::isNeutral>::invoke, false},
-	{"isDamage", LuaMethodWrapper<Spell, bool(Spell:: *)()const, &Spell::isDamage>::invoke, false},
-	{"isOffensive", LuaMethodWrapper<Spell, bool(Spell:: *)()const, &Spell::isOffensive>::invoke, false},
-	{"isSpecial", LuaMethodWrapper<Spell, bool(Spell:: *)()const, &Spell::isSpecial>::invoke, false},
-
+	{"getIconIndex", LuaMethodWrapper<Spell, decltype(&Entity::getIconIndex), &Entity::getIconIndex>::invoke, false},
+	{"getIndex", LuaMethodWrapper<Spell, decltype(&Entity::getIndex), &Entity::getIndex>::invoke, false},
+	{"getJsonKey", LuaMethodWrapper<Spell, decltype(&Entity::getJsonKey), &Entity::getJsonKey>::invoke, false},
+	{"getName", LuaMethodWrapper<Spell, decltype(&Entity::getName), &Entity::getName>::invoke, false},
+
+	{"isAdventure", LuaMethodWrapper<Spell, decltype(&Spell::isAdventure), &Spell::isAdventure>::invoke, false},
+	{"isCombat", LuaMethodWrapper<Spell, decltype(&Spell::isCombat), &Spell::isCombat>::invoke, false},
+	{"isCreatureAbility", LuaMethodWrapper<Spell, decltype(&Spell::isCreatureAbility), &Spell::isCreatureAbility>::invoke, false},
+	{"isPositive", LuaMethodWrapper<Spell, decltype(&Spell::isPositive), &Spell::isPositive>::invoke, false},
+	{"isNegative", LuaMethodWrapper<Spell, decltype(&Spell::isNegative), &Spell::isNegative>::invoke, false},
+	{"isNeutral", LuaMethodWrapper<Spell, decltype(&Spell::isNeutral), &Spell::isNeutral>::invoke, false},
+	{"isDamage", LuaMethodWrapper<Spell, decltype(&Spell::isDamage), &Spell::isDamage>::invoke, false},
+	{"isOffensive", LuaMethodWrapper<Spell, decltype(&Spell::isOffensive), &Spell::isOffensive>::invoke, false},
+	{"isSpecial", LuaMethodWrapper<Spell, decltype(&Spell::isSpecial), &Spell::isSpecial>::invoke, false},
+
+	{"getCost", LuaMethodWrapper<Spell, decltype(&Spell::getCost), &Spell::getCost>::invoke, false},
+	{"getBasePower", LuaMethodWrapper<Spell, decltype(&Spell::getBasePower), &Spell::getBasePower>::invoke, false},
+	{"getLevelPower", LuaMethodWrapper<Spell, decltype(&Spell::getLevelPower), &Spell::getLevelPower>::invoke, false},
+	{"getLevelDescription", LuaMethodWrapper<Spell, decltype(&Spell::getLevelDescription), &Spell::getLevelDescription>::invoke, false},
 };
 
 }

+ 0 - 1
scripting/lua/api/Spell.h

@@ -23,7 +23,6 @@ class SpellProxy : public OpaqueWrapper<const ::spells::Spell, SpellProxy>
 {
 public:
 	using Wrapper = OpaqueWrapper<const ::spells::Spell, SpellProxy>;
-	static const std::vector<typename Wrapper::RegType> REGISTER;
 	static const std::vector<typename Wrapper::CustomRegType> REGISTER_CUSTOM;
 };
 

+ 2 - 7
scripting/lua/api/StackInstance.cpp

@@ -23,15 +23,10 @@ namespace api
 {
 VCMI_REGISTER_CORE_SCRIPT_API(StackInstanceProxy, "StackInstance");
 
-const std::vector<StackInstanceProxy::RegType> StackInstanceProxy::REGISTER =
-{
-
-};
-
 const std::vector<StackInstanceProxy::CustomRegType> StackInstanceProxy::REGISTER_CUSTOM =
 {
-	{"getType", LuaMethodWrapper<CStackInstance, const Creature *(CStackBasicDescriptor:: *)()const, &CStackBasicDescriptor::getType>::invoke, false},
-	{"getCount", LuaMethodWrapper<CStackInstance, TQuantity(CStackBasicDescriptor:: *)()const, &CStackBasicDescriptor::getCount>::invoke, false},
+	{"getType", LuaMethodWrapper<CStackInstance, decltype(&CStackBasicDescriptor::getType), &CStackBasicDescriptor::getType>::invoke, false},
+	{"getCount", LuaMethodWrapper<CStackInstance, decltype(&CStackBasicDescriptor::getCount), &CStackBasicDescriptor::getCount>::invoke, false},
 };
 
 

+ 0 - 1
scripting/lua/api/StackInstance.h

@@ -25,7 +25,6 @@ class StackInstanceProxy : public OpaqueWrapper<const CStackInstance, StackInsta
 {
 public:
 	using Wrapper = OpaqueWrapper<const CStackInstance, StackInstanceProxy>;
-	static const std::vector<typename Wrapper::RegType> REGISTER;
 	static const std::vector<typename Wrapper::CustomRegType> REGISTER_CUSTOM;
 };
 

+ 6 - 29
scripting/lua/api/battle/UnitProxy.cpp

@@ -25,37 +25,14 @@ namespace battle
 
 VCMI_REGISTER_SCRIPT_API(UnitProxy, "battle.Unit")
 
-const std::vector<UnitProxy::RegType> UnitProxy::REGISTER =
-{
-	{
-		"getMinDamage",
-		LuaCallWrapper<const IBonusBearer>::createFunctor(&IBonusBearer::getMinDamage)
-	},
-	{
-		"getMaxDamage",
-		LuaCallWrapper<const IBonusBearer>::createFunctor(&IBonusBearer::getMaxDamage)
-	},
-	{
-		"getAttack",
-		LuaCallWrapper<const IBonusBearer>::createFunctor(&IBonusBearer::getAttack)
-	},
-	{
-		"getDefense",
-		LuaCallWrapper<const IBonusBearer>::createFunctor(&IBonusBearer::getDefense)
-	},
-	{
-		"isAlive",
-		LuaCallWrapper<const Unit>::createFunctor(&Unit::alive)
-	},
-	{
-		"unitId",
-		LuaCallWrapper<const IUnitInfo>::createFunctor(&IUnitInfo::unitId)
-	}
-};
-
 const std::vector<UnitProxy::CustomRegType> UnitProxy::REGISTER_CUSTOM =
 {
-
+	{"getMinDamage", LuaMethodWrapper<Unit, decltype(&IBonusBearer::getMinDamage), &IBonusBearer::getMinDamage>::invoke, false},
+	{"getMaxDamage", LuaMethodWrapper<Unit, decltype(&IBonusBearer::getMaxDamage), &IBonusBearer::getMaxDamage>::invoke, false},
+	{"getAttack", LuaMethodWrapper<Unit, decltype(&IBonusBearer::getAttack), &IBonusBearer::getAttack>::invoke, false},
+	{"getDefense", LuaMethodWrapper<Unit, decltype(&IBonusBearer::getDefense), &IBonusBearer::getDefense>::invoke, false},
+	{"isAlive", LuaMethodWrapper<Unit, decltype(&Unit::alive), &Unit::alive>::invoke, false},
+	{"unitId", LuaMethodWrapper<Unit, decltype(&IUnitInfo::unitId), &IUnitInfo::unitId>::invoke, false},
 };
 
 }

+ 0 - 2
scripting/lua/api/battle/UnitProxy.h

@@ -28,8 +28,6 @@ class UnitProxy : public OpaqueWrapper<const Unit, UnitProxy>
 {
 public:
 	using Wrapper = OpaqueWrapper<const Unit, UnitProxy>;
-
-	static const std::vector<typename Wrapper::RegType> REGISTER;
 	static const std::vector<typename Wrapper::CustomRegType> REGISTER_CUSTOM;
 };
 

+ 5 - 27
scripting/lua/api/events/AdventureEvents.cpp

@@ -25,35 +25,13 @@ namespace events
 
 VCMI_REGISTER_SCRIPT_API(ObjectVisitStartedProxy, "events.ObjectVisitStarted");
 
-const std::vector<ObjectVisitStartedProxy::RegType> ObjectVisitStartedProxy::REGISTER = {};
-
 const std::vector<ObjectVisitStartedProxy::CustomRegType> ObjectVisitStartedProxy::REGISTER_CUSTOM =
 {
-	{
-		"subscribeBefore",
-		&SubscriptionRegistryProxy<ObjectVisitStartedProxy>::subscribeBefore,
-		true
-	},
-	{
-		"subscribeAfter",
-		&SubscriptionRegistryProxy<ObjectVisitStartedProxy>::subscribeAfter,
-		true
-	},
-	{
-		"getPlayer",
-		LuaMethodWrapper<ObjectVisitStarted, PlayerColor(ObjectVisitStarted:: *)()const, &ObjectVisitStarted::getPlayer>::invoke,
-		false
-	},
-	{
-		"getHero",
-		LuaMethodWrapper<ObjectVisitStarted, ObjectInstanceID(ObjectVisitStarted:: *)()const, &ObjectVisitStarted::getHero>::invoke,
-		false
-	},
-	{
-		"getObject",
-		LuaMethodWrapper<ObjectVisitStarted, ObjectInstanceID(ObjectVisitStarted:: *)()const, &ObjectVisitStarted::getObject>::invoke,
-		false
-	},
+	{"subscribeBefore", &SubscriptionRegistryProxy<ObjectVisitStartedProxy>::subscribeBefore, true},
+	{"subscribeAfter", &SubscriptionRegistryProxy<ObjectVisitStartedProxy>::subscribeAfter,true},
+	{"getPlayer", LuaMethodWrapper<ObjectVisitStarted, decltype(&ObjectVisitStarted::getPlayer), &ObjectVisitStarted::getPlayer>::invoke, false},
+	{"getHero", LuaMethodWrapper<ObjectVisitStarted, decltype(&ObjectVisitStarted::getHero), &ObjectVisitStarted::getHero>::invoke, false},
+	{"getObject", LuaMethodWrapper<ObjectVisitStarted, decltype(&ObjectVisitStarted::getObject), &ObjectVisitStarted::getObject>::invoke, false},
 };
 
 }

+ 0 - 1
scripting/lua/api/events/AdventureEvents.h

@@ -29,7 +29,6 @@ class ObjectVisitStartedProxy : public OpaqueWrapper<ObjectVisitStarted, ObjectV
 {
 public:
 	using Wrapper = OpaqueWrapper<ObjectVisitStarted, ObjectVisitStartedProxy>;
-	static const std::vector<typename Wrapper::RegType> REGISTER;
 	static const std::vector<typename Wrapper::CustomRegType> REGISTER_CUSTOM;
 };
 

+ 20 - 19
scripting/lua/api/events/BattleEvents.cpp

@@ -27,38 +27,39 @@ using ::events::ApplyDamage;
 
 VCMI_REGISTER_SCRIPT_API(ApplyDamageProxy, "events.ApplyDamage");
 
-const std::vector<ApplyDamageProxy::RegType> ApplyDamageProxy::REGISTER =
+const std::vector<ApplyDamageProxy::CustomRegType> ApplyDamageProxy::REGISTER_CUSTOM =
 {
+	{
+		"subscribeBefore",
+		&SubscriptionRegistryProxy<ApplyDamageProxy>::subscribeBefore,
+		true
+	},
+	{
+		"subscribeAfter",
+		&SubscriptionRegistryProxy<ApplyDamageProxy>::subscribeAfter,
+		true
+	},
 	{
 		"getInitalDamage",
-		LuaCallWrapper<ApplyDamage>::createFunctor(&ApplyDamage::getInitalDamage)
+		LuaMethodWrapper<ApplyDamage, decltype(&ApplyDamage::getInitalDamage), &ApplyDamage::getInitalDamage>::invoke,
+		false
 	},
 	{
 		"getDamage",
-		LuaCallWrapper<ApplyDamage>::createFunctor(&ApplyDamage::getDamage)
+		LuaMethodWrapper<ApplyDamage, decltype(&ApplyDamage::getDamage), &ApplyDamage::getDamage>::invoke,
+		false
 	},
 	{
 		"setDamage",
-		LuaCallWrapper<ApplyDamage>::createFunctor(&ApplyDamage::setDamage)
+		LuaMethodWrapper<ApplyDamage, decltype(&ApplyDamage::setDamage), &ApplyDamage::setDamage>::invoke,
+		false
 	},
 	{
 		"getTarget",
-		LuaCallWrapper<ApplyDamage>::createFunctor(&ApplyDamage::getTarget)
-	}
-};
-
-const std::vector<ApplyDamageProxy::CustomRegType> ApplyDamageProxy::REGISTER_CUSTOM =
-{
-	{
-		"subscribeBefore",
-		&SubscriptionRegistryProxy<ApplyDamageProxy>::subscribeBefore,
-		true
+		LuaMethodWrapper<ApplyDamage, decltype(&ApplyDamage::getTarget), &ApplyDamage::getTarget>::invoke,
+		false
 	},
-	{
-		"subscribeAfter",
-		&SubscriptionRegistryProxy<ApplyDamageProxy>::subscribeAfter,
-		true
-	}
+
 };
 
 }

+ 0 - 1
scripting/lua/api/events/BattleEvents.h

@@ -27,7 +27,6 @@ class ApplyDamageProxy : public OpaqueWrapper<::events::ApplyDamage, ApplyDamage
 {
 public:
 	using Wrapper = OpaqueWrapper<::events::ApplyDamage, ApplyDamageProxy>;
-	static const std::vector<typename Wrapper::RegType> REGISTER;
 	static const std::vector<typename Wrapper::CustomRegType> REGISTER_CUSTOM;
 };
 

+ 0 - 1
scripting/lua/api/events/EventBusProxy.cpp

@@ -24,7 +24,6 @@ namespace events
 {
 //No methods here, just an empty metatable for type safety.
 VCMI_REGISTER_CORE_SCRIPT_API(EventBusProxy, "EventBus");
-const std::vector<EventBusProxy::RegType> EventBusProxy::REGISTER = {};
 const std::vector<EventBusProxy::CustomRegType> EventBusProxy::REGISTER_CUSTOM = {};
 
 }

+ 0 - 1
scripting/lua/api/events/EventBusProxy.h

@@ -25,7 +25,6 @@ class EventBusProxy : public OpaqueWrapper<::events::EventBus, EventBusProxy>
 {
 public:
 	using Wrapper = OpaqueWrapper<::events::EventBus, EventBusProxy>;
-	static const std::vector<typename Wrapper::RegType> REGISTER;
 	static const std::vector<typename Wrapper::CustomRegType> REGISTER_CUSTOM;
 };
 

+ 11 - 17
scripting/lua/api/events/GenericEvents.cpp

@@ -30,8 +30,6 @@ VCMI_REGISTER_SCRIPT_API(GameResumedProxy, "events.GameResumed");
 VCMI_REGISTER_SCRIPT_API(PlayerGotTurnProxy, "events.PlayerGotTurn");
 VCMI_REGISTER_SCRIPT_API(TurnStartedProxy, "events.TurnStarted");
 
-const std::vector<GameResumedProxy::RegType> GameResumedProxy::REGISTER = {};
-
 const std::vector<GameResumedProxy::CustomRegType> GameResumedProxy::REGISTER_CUSTOM =
 {
 	{
@@ -46,18 +44,6 @@ const std::vector<GameResumedProxy::CustomRegType> GameResumedProxy::REGISTER_CU
 	}
 };
 
-const std::vector<PlayerGotTurnProxy::RegType> PlayerGotTurnProxy::REGISTER =
-{
-	{
-		"getPlayer",
-		LuaCallWrapper<PlayerGotTurn>::createFunctor(&PlayerGotTurn::getPlayerIndex)
-	},
-	{
-		"setPlayer",
-		LuaCallWrapper<PlayerGotTurn>::createFunctor(&PlayerGotTurn::setPlayerIndex)
-	},
-};
-
 const std::vector<PlayerGotTurnProxy::CustomRegType> PlayerGotTurnProxy::REGISTER_CUSTOM =
 {
 	{
@@ -69,11 +55,19 @@ const std::vector<PlayerGotTurnProxy::CustomRegType> PlayerGotTurnProxy::REGISTE
 		"subscribeAfter",
 		&SubscriptionRegistryProxy<PlayerGotTurnProxy>::subscribeAfter,
 		true
-	}
+	},
+	{
+		"getPlayer",
+		LuaMethodWrapper<PlayerGotTurn, decltype(&PlayerGotTurn::getPlayerIndex), &PlayerGotTurn::getPlayerIndex>::invoke,
+		false
+	},
+	{
+		"setPlayer",
+		LuaMethodWrapper<PlayerGotTurn, decltype(&PlayerGotTurn::setPlayerIndex), &PlayerGotTurn::setPlayerIndex>::invoke,
+		false
+	},
 };
 
-const std::vector<TurnStartedProxy::RegType> TurnStartedProxy::REGISTER = {};
-
 const std::vector<TurnStartedProxy::CustomRegType> TurnStartedProxy::REGISTER_CUSTOM =
 {
 	{

+ 0 - 3
scripting/lua/api/events/GenericEvents.h

@@ -27,7 +27,6 @@ class GameResumedProxy : public OpaqueWrapper<::events::GameResumed, GameResumed
 {
 public:
 	using Wrapper = OpaqueWrapper<::events::GameResumed, GameResumedProxy>;
-	static const std::vector<typename Wrapper::RegType> REGISTER;
 	static const std::vector<typename Wrapper::CustomRegType> REGISTER_CUSTOM;
 };
 
@@ -35,7 +34,6 @@ class PlayerGotTurnProxy : public OpaqueWrapper<::events::PlayerGotTurn, PlayerG
 {
 public:
 	using Wrapper = OpaqueWrapper<::events::PlayerGotTurn, PlayerGotTurnProxy>;
-	static const std::vector<typename Wrapper::RegType> REGISTER;
 	static const std::vector<typename Wrapper::CustomRegType> REGISTER_CUSTOM;
 };
 
@@ -43,7 +41,6 @@ class TurnStartedProxy : public OpaqueWrapper<::events::TurnStarted, TurnStarted
 {
 public:
 	using Wrapper = OpaqueWrapper<::events::TurnStarted, TurnStartedProxy>;
-	static const std::vector<typename Wrapper::RegType> REGISTER;
 	static const std::vector<typename Wrapper::CustomRegType> REGISTER_CUSTOM;
 };
 

+ 0 - 1
scripting/lua/api/events/SubscriptionRegistryProxy.cpp

@@ -21,7 +21,6 @@ namespace events
 {
 //No methods here, just an empty metatable for type safety.
 VCMI_REGISTER_CORE_SCRIPT_API(EventSubscriptionProxy, "EventSubscription");
-const std::vector<EventSubscriptionProxy::RegType> EventSubscriptionProxy::REGISTER = {};
 const std::vector<EventSubscriptionProxy::CustomRegType> EventSubscriptionProxy::REGISTER_CUSTOM = {};
 }
 }

+ 0 - 1
scripting/lua/api/events/SubscriptionRegistryProxy.h

@@ -30,7 +30,6 @@ class EventSubscriptionProxy : public UniqueOpaqueWrapper<::events::EventSubscri
 {
 public:
 	using Wrapper = UniqueOpaqueWrapper<::events::EventSubscription, EventSubscriptionProxy>;
-	static const std::vector<typename Wrapper::RegType> REGISTER;
 	static const std::vector<typename Wrapper::CustomRegType> REGISTER_CUSTOM;
 };
 

+ 14 - 19
scripting/lua/api/netpacks/BattleLogMessage.cpp

@@ -24,34 +24,29 @@ namespace netpacks
 
 VCMI_REGISTER_SCRIPT_API(BattleLogMessageProxy, "netpacks.BattleLogMessage");
 
-const std::vector<BattleLogMessageProxy::RegType> BattleLogMessageProxy::REGISTER =
-{
-	{
-		"addText",
-		&BattleLogMessageProxy::addText
-	},
-	{
-		"toNetpackLight",
-		&PackForClientProxy<BattleLogMessageProxy>::toNetpackLight
-	},
-};
-
 const std::vector<BattleLogMessageProxy::CustomRegType> BattleLogMessageProxy::REGISTER_CUSTOM =
 {
-	{"new", &Wrapper::constructor, true}
+	{"new", &Wrapper::constructor, true},
+	{"addText", &BattleLogMessageProxy::addText, false},
+	{"toNetpackLight",&PackForClientProxy<BattleLogMessageProxy>::toNetpackLight, false}
 };
 
-int BattleLogMessageProxy::addText(lua_State * L, std::shared_ptr<BattleLogMessage> object)
+int BattleLogMessageProxy::addText(lua_State * L)
 {
 	LuaStack S(L);
 
-	std::string text;
+	std::shared_ptr<BattleLogMessage> object;
 
-	if(S.tryGet(1, text))
+	if(S.tryGet(1, object))
 	{
-		if(object->lines.empty())
-			object->lines.emplace_back();
-		object->lines.back() << text;
+		std::string text;
+
+		if(S.tryGet(2, text))
+		{
+			if(object->lines.empty())
+				object->lines.emplace_back();
+			object->lines.back() << text;
+		}
 	}
 
 	return S.retVoid();

+ 1 - 2
scripting/lua/api/netpacks/BattleLogMessage.h

@@ -24,10 +24,9 @@ class BattleLogMessageProxy : public SharedWrapper<BattleLogMessage, BattleLogMe
 public:
 	using Wrapper = SharedWrapper<BattleLogMessage, BattleLogMessageProxy>;
 
-	static const std::vector<Wrapper::RegType> REGISTER;
 	static const std::vector<typename Wrapper::CustomRegType> REGISTER_CUSTOM;
 
-	static int addText(lua_State * L, std::shared_ptr<BattleLogMessage> object);
+	static int addText(lua_State * L);
 };
 
 }

+ 28 - 33
scripting/lua/api/netpacks/BattleStackMoved.cpp

@@ -24,63 +24,58 @@ namespace netpacks
 
 VCMI_REGISTER_SCRIPT_API(BattleStackMovedProxy, "netpacks.BattleStackMoved");
 
-const std::vector<BattleStackMovedProxy::RegType> BattleStackMovedProxy::REGISTER =
-{
-	{
-		"addTileToMove",
-		&BattleStackMovedProxy::addTileToMove
-	},
-	{
-		"setUnitId",
-		&BattleStackMovedProxy::setUnitId
-	},
-	{
-		"setDistance",
-		&BattleStackMovedProxy::setDistance
-	},
-	{
-		"setTeleporting",
-		&BattleStackMovedProxy::setTeleporting
-	},
-	{
-		"toNetpackLight",
-		&PackForClientProxy<BattleStackMovedProxy>::toNetpackLight
-	}
-};
-
 const std::vector<BattleStackMovedProxy::CustomRegType> BattleStackMovedProxy::REGISTER_CUSTOM =
 {
-	{"new", &Wrapper::constructor, true}
+	{"new", &Wrapper::constructor, true},
+	{"addTileToMove", &BattleStackMovedProxy::addTileToMove, false},
+	{"setUnitId", &BattleStackMovedProxy::setUnitId, false},
+	{"setDistance", &BattleStackMovedProxy::setDistance, false},
+	{"setTeleporting", &BattleStackMovedProxy::setTeleporting, false},
+	{"toNetpackLight", &PackForClientProxy<BattleStackMovedProxy>::toNetpackLight, false}
 };
 
-int BattleStackMovedProxy::addTileToMove(lua_State * L, std::shared_ptr<BattleStackMoved> object)
+int BattleStackMovedProxy::addTileToMove(lua_State * L)
 {
 	LuaStack S(L);
+
+	std::shared_ptr<BattleStackMoved> object;
+	if(!S.tryGet(1, object))
+		return S.retVoid();
+
 	lua_Integer hex = 0;
-	if(!S.tryGetInteger(1, hex))
+	if(!S.tryGetInteger(2, hex))
 		return S.retVoid();
 	object->tilesToMove.emplace_back(hex);
 	return S.retVoid();
 }
 
-int BattleStackMovedProxy::setUnitId(lua_State * L, std::shared_ptr<BattleStackMoved> object)
+int BattleStackMovedProxy::setUnitId(lua_State * L)
 {
 	LuaStack S(L);
-	S.tryGet(1, object->stack);
+	std::shared_ptr<BattleStackMoved> object;
+	if(!S.tryGet(1, object))
+		return S.retVoid();
+	S.tryGet(2, object->stack);
 	return S.retVoid();
 }
 
-int BattleStackMovedProxy::setDistance(lua_State * L, std::shared_ptr<BattleStackMoved> object)
+int BattleStackMovedProxy::setDistance(lua_State * L)
 {
 	LuaStack S(L);
-	S.tryGet(1, object->distance);
+	std::shared_ptr<BattleStackMoved> object;
+	if(!S.tryGet(1, object))
+		return S.retVoid();
+	S.tryGet(2, object->distance);
 	return S.retVoid();
 }
 
-int BattleStackMovedProxy::setTeleporting(lua_State * L, std::shared_ptr<BattleStackMoved> object)
+int BattleStackMovedProxy::setTeleporting(lua_State * L)
 {
 	LuaStack S(L);
-	S.tryGet(1, object->teleporting);
+	std::shared_ptr<BattleStackMoved> object;
+	if(!S.tryGet(1, object))
+		return S.retVoid();
+	S.tryGet(2, object->teleporting);
 	return S.retVoid();
 }
 

+ 4 - 6
scripting/lua/api/netpacks/BattleStackMoved.h

@@ -24,14 +24,12 @@ class BattleStackMovedProxy : public SharedWrapper<BattleStackMoved, BattleStack
 public:
 	using Wrapper = SharedWrapper<BattleStackMoved, BattleStackMovedProxy>;
 
-	static const std::vector<Wrapper::RegType> REGISTER;
 	static const std::vector<typename Wrapper::CustomRegType> REGISTER_CUSTOM;
 
-	static int addTileToMove(lua_State * L, std::shared_ptr<BattleStackMoved> object);
-
-	static int setUnitId(lua_State * L, std::shared_ptr<BattleStackMoved> object);
-	static int setDistance(lua_State * L, std::shared_ptr<BattleStackMoved> object);
-	static int setTeleporting(lua_State * L, std::shared_ptr<BattleStackMoved> object);
+	static int addTileToMove(lua_State * L);
+	static int setUnitId(lua_State * L);
+	static int setDistance(lua_State * L);
+	static int setTeleporting(lua_State * L);
 };
 
 }

+ 35 - 35
scripting/lua/api/netpacks/BattleUnitsChanged.cpp

@@ -24,49 +24,35 @@ namespace netpacks
 
 VCMI_REGISTER_SCRIPT_API(BattleUnitsChangedProxy, "netpacks.BattleUnitsChanged");
 
-const std::vector<BattleUnitsChangedProxy::RegType> BattleUnitsChangedProxy::REGISTER =
-{
-	{
-		"toNetpackLight",
-		&PackForClientProxy<BattleUnitsChangedProxy>::toNetpackLight
-	},
-	{
-		"add",
-		&BattleUnitsChangedProxy::add
-	},
-	{
-		"update",
-		&BattleUnitsChangedProxy::update
-	},
-	{
-		"resetState",
-		&BattleUnitsChangedProxy::resetState
-	},
-	{
-		"remove",
-		&BattleUnitsChangedProxy::remove
-	}
-};
-
 const std::vector<BattleUnitsChangedProxy::CustomRegType> BattleUnitsChangedProxy::REGISTER_CUSTOM =
 {
-	{"new", &Wrapper::constructor, true}
+	{"new", &Wrapper::constructor, true},
+	{"add", &BattleUnitsChangedProxy::add, false},
+	{"update", &BattleUnitsChangedProxy::update, false},
+	{"resetState", &BattleUnitsChangedProxy::resetState, false},
+	{"remove", &BattleUnitsChangedProxy::remove, false},
+	{"toNetpackLight", &PackForClientProxy<BattleUnitsChangedProxy>::toNetpackLight, false}
 };
 
-int BattleUnitsChangedProxy::add(lua_State * L, std::shared_ptr<BattleUnitsChanged> object)
+int BattleUnitsChangedProxy::add(lua_State * L)
 {
 	LuaStack S(L);
+	std::shared_ptr<BattleUnitsChanged> object;
+
+	if(!S.tryGet(1, object))
+		return S.retVoid();
+
 	uint32_t id;
 
-	if(!S.tryGet(1, id))
+	if(!S.tryGet(2, id))
 		return S.retVoid();
 
 	UnitChanges changes(id, BattleChanges::EOperation::ADD);
 
-	if(!S.tryGet(2, changes.data))
+	if(!S.tryGet(3, changes.data))
 		return S.retVoid();
 
-	if(!S.tryGet(3, changes.healthDelta))
+	if(!S.tryGet(4, changes.healthDelta))
 		changes.healthDelta = 0;
 
 	object->changedStacks.push_back(changes);
@@ -74,21 +60,25 @@ int BattleUnitsChangedProxy::add(lua_State * L, std::shared_ptr<BattleUnitsChang
 	return S.retVoid();
 }
 
-int BattleUnitsChangedProxy::update(lua_State * L, std::shared_ptr<BattleUnitsChanged> object)
+int BattleUnitsChangedProxy::update(lua_State * L)
 {
 	LuaStack S(L);
+	std::shared_ptr<BattleUnitsChanged> object;
+
+	if(!S.tryGet(1, object))
+		return S.retVoid();
 
 	uint32_t id;
 
-	if(!S.tryGet(1, id))
+	if(!S.tryGet(2, id))
 		return S.retVoid();
 
 	UnitChanges changes(id, BattleChanges::EOperation::UPDATE);
 
-	if(!S.tryGet(2, changes.data))
+	if(!S.tryGet(3, changes.data))
 		return S.retVoid();
 
-	if(!S.tryGet(3, changes.healthDelta))
+	if(!S.tryGet(4, changes.healthDelta))
 		changes.healthDelta = 0;
 
 	object->changedStacks.push_back(changes);
@@ -96,15 +86,25 @@ int BattleUnitsChangedProxy::update(lua_State * L, std::shared_ptr<BattleUnitsCh
 	return S.retVoid();
 }
 
-int BattleUnitsChangedProxy::resetState(lua_State * L, std::shared_ptr<BattleUnitsChanged> object)
+int BattleUnitsChangedProxy::resetState(lua_State * L)
 {
 	LuaStack S(L);
+	std::shared_ptr<BattleUnitsChanged> object;
+
+	if(!S.tryGet(1, object))
+		return S.retVoid();
+	//todo
 	return S.retVoid();
 }
 
-int BattleUnitsChangedProxy::remove(lua_State * L, std::shared_ptr<BattleUnitsChanged> object)
+int BattleUnitsChangedProxy::remove(lua_State * L)
 {
 	LuaStack S(L);
+	std::shared_ptr<BattleUnitsChanged> object;
+
+	if(!S.tryGet(1, object))
+		return S.retVoid();
+	//todo
 	return S.retVoid();
 }
 

+ 4 - 5
scripting/lua/api/netpacks/BattleUnitsChanged.h

@@ -24,13 +24,12 @@ class BattleUnitsChangedProxy : public SharedWrapper<BattleUnitsChanged, BattleU
 public:
 	using Wrapper = SharedWrapper<BattleUnitsChanged, BattleUnitsChangedProxy>;
 
-	static const std::vector<Wrapper::RegType> REGISTER;
 	static const std::vector<typename Wrapper::CustomRegType> REGISTER_CUSTOM;
 
-	static int add(lua_State * L, std::shared_ptr<BattleUnitsChanged> object);
-	static int update(lua_State * L, std::shared_ptr<BattleUnitsChanged> object);
-	static int resetState(lua_State * L, std::shared_ptr<BattleUnitsChanged> object);
-	static int remove(lua_State * L, std::shared_ptr<BattleUnitsChanged> object);
+	static int add(lua_State * L);
+	static int update(lua_State * L);
+	static int resetState(lua_State * L);
+	static int remove(lua_State * L);
 };
 
 }

+ 11 - 17
scripting/lua/api/netpacks/EntitiesChanged.cpp

@@ -24,39 +24,33 @@ namespace netpacks
 
 VCMI_REGISTER_SCRIPT_API(EntitiesChangedProxy, "netpacks.EntitiesChanged");
 
-const std::vector<EntitiesChangedProxy::RegType> EntitiesChangedProxy::REGISTER =
-{
-	{
-		"update",
-		&EntitiesChangedProxy::update
-	},
-	{
-		"toNetpackLight",
-		&PackForClientProxy<EntitiesChangedProxy>::toNetpackLight
-	},
-};
-
 const std::vector<EntitiesChangedProxy::CustomRegType> EntitiesChangedProxy::REGISTER_CUSTOM =
 {
-	{"new", &Wrapper::constructor, true}
+	{"new", &Wrapper::constructor, true},
+	{"update", &EntitiesChangedProxy::update, false},
+	{"toNetpackLight", &PackForClientProxy<EntitiesChangedProxy>::toNetpackLight, false}
 };
 
-int EntitiesChangedProxy::update(lua_State * L, std::shared_ptr<EntitiesChanged> object)
+int EntitiesChangedProxy::update(lua_State * L)
 {
 	LuaStack S(L);
 
+	std::shared_ptr<EntitiesChanged> object;
+	if(!S.tryGet(1, object))
+		return S.retVoid();
+
 	EntityChanges changes;
 
 	int32_t metaIndex = 0;
 
-	if(!S.tryGet(1, metaIndex))
+	if(!S.tryGet(2, metaIndex))
 		return S.retVoid();
 	changes.metatype = static_cast<Metatype>(metaIndex);
 
-	if(!S.tryGet(2, changes.entityIndex))
+	if(!S.tryGet(3, changes.entityIndex))
 		return S.retVoid();
 
-	if(!S.tryGet(3, changes.data))
+	if(!S.tryGet(4, changes.data))
 		return S.retVoid();
 
 	object->changes.push_back(changes);

+ 1 - 2
scripting/lua/api/netpacks/EntitiesChanged.h

@@ -25,10 +25,9 @@ class EntitiesChangedProxy : public SharedWrapper<EntitiesChanged, EntitiesChang
 public:
 	using Wrapper = SharedWrapper<EntitiesChanged, EntitiesChangedProxy>;
 
-	static const std::vector<typename Wrapper::RegType> REGISTER;
 	static const std::vector<typename Wrapper::CustomRegType> REGISTER_CUSTOM;
 
-	static int update(lua_State * L, std::shared_ptr<EntitiesChanged> object);
+	static int update(lua_State * L);
 };
 
 }

+ 45 - 45
scripting/lua/api/netpacks/InfoWindow.cpp

@@ -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();

+ 3 - 4
scripting/lua/api/netpacks/InfoWindow.h

@@ -23,12 +23,11 @@ class InfoWindowProxy : public SharedWrapper<InfoWindow, InfoWindowProxy>
 {
 public:
 	using Wrapper = SharedWrapper<InfoWindow, InfoWindowProxy>;
-	static const std::vector<typename Wrapper::RegType> REGISTER;
 	static const std::vector<typename Wrapper::CustomRegType> REGISTER_CUSTOM;
 
-	static int addReplacement(lua_State * L, std::shared_ptr<InfoWindow> object);
-	static int addText(lua_State * L, std::shared_ptr<InfoWindow> object);
-	static int setPlayer(lua_State * L, std::shared_ptr<InfoWindow> object);
+	static int addReplacement(lua_State * L);
+	static int addText(lua_State * L);
+	static int setPlayer(lua_State * L);
 };
 
 }

+ 7 - 1
scripting/lua/api/netpacks/PackForClient.h

@@ -25,8 +25,14 @@ template <typename Derived>
 class PackForClientProxy
 {
 public:
-	static int toNetpackLight(lua_State * L, typename Derived::UDataType object)
+	static int toNetpackLight(lua_State * L)
 	{
+		typename Derived::UDataType object;
+		LuaStack S(L);
+
+		if(!S.tryGet(1, object))
+			return S.retVoid();
+
 		lua_settop(L, 0);
 		lua_pushlightuserdata(L, static_cast<CPackForClient *>(object.get()));
 		return 1;

+ 55 - 29
scripting/lua/api/netpacks/SetResources.cpp

@@ -24,68 +24,85 @@ namespace netpacks
 
 VCMI_REGISTER_SCRIPT_API(SetResourcesProxy, "netpacks.SetResources");
 
-const std::vector<SetResourcesProxy::RegType> SetResourcesProxy::REGISTER =
-{
-	{"getAbs",&SetResourcesProxy::getAbs},
-	{"setAbs",&SetResourcesProxy::setAbs},
-	{"getPlayer",&SetResourcesProxy::getPlayer},
-	{"setPlayer",&SetResourcesProxy::setPlayer},
-	{"setAmount",&SetResourcesProxy::setAmount},
-	{"getAmount",&SetResourcesProxy::getAmount},
-	{"clear",&SetResourcesProxy::clear},
-
-	{
-		"toNetpackLight",
-		&PackForClientProxy<SetResourcesProxy>::toNetpackLight
-	},
-};
-
 const std::vector<SetResourcesProxy::CustomRegType> SetResourcesProxy::REGISTER_CUSTOM =
 {
-	{"new", &Wrapper::constructor, true}
+	{"new", &Wrapper::constructor, true},
+	{"getAbs", &SetResourcesProxy::getAbs, false},
+	{"setAbs", &SetResourcesProxy::setAbs, false},
+	{"getPlayer", &SetResourcesProxy::getPlayer, false},
+	{"setPlayer", &SetResourcesProxy::setPlayer, false},
+	{"setAmount", &SetResourcesProxy::setAmount, false},
+	{"getAmount", &SetResourcesProxy::getAmount, false},
+	{"clear", &SetResourcesProxy::clear, false},
+	{"toNetpackLight", &PackForClientProxy<SetResourcesProxy>::toNetpackLight, false}
 };
 
-int SetResourcesProxy::getAbs(lua_State * L, std::shared_ptr<SetResources> object)
+int SetResourcesProxy::getAbs(lua_State * L)
 {
+	LuaStack S(L);
+	std::shared_ptr<SetResources> object;
+	if(!S.tryGet(1, object))
+		return S.retVoid();
+
 	return LuaStack::quickRetBool(L, object->abs);
 }
 
-int SetResourcesProxy::setAbs(lua_State * L, std::shared_ptr<SetResources> object)
+int SetResourcesProxy::setAbs(lua_State * L)
 {
 	LuaStack S(L);
+
+	std::shared_ptr<SetResources> object;
+	if(!S.tryGet(1, object))
+		return S.retVoid();
+
+
 	bool value = false;
-	if(S.tryGet(1, value))
+	if(S.tryGet(2, value))
 		object->abs = value;
 
 	return S.retVoid();
 }
 
-int SetResourcesProxy::getPlayer(lua_State * L, std::shared_ptr<SetResources> object)
+int SetResourcesProxy::getPlayer(lua_State * L)
 {
 	LuaStack S(L);
+
+	std::shared_ptr<SetResources> object;
+	if(!S.tryGet(1, object))
+		return S.retVoid();
+
 	S.clear();
 	S.push(object->player);
 	return 1;
 }
 
-int SetResourcesProxy::setPlayer(lua_State * L, std::shared_ptr<SetResources> object)
+int SetResourcesProxy::setPlayer(lua_State * L)
 {
 	LuaStack S(L);
+
+	std::shared_ptr<SetResources> 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();
 }
 
-int SetResourcesProxy::getAmount(lua_State * L, std::shared_ptr<SetResources> object)
+int SetResourcesProxy::getAmount(lua_State * L)
 {
 	LuaStack S(L);
 
+	std::shared_ptr<SetResources> object;
+	if(!S.tryGet(1, object))
+		return S.retVoid();
+
 	Res::ERes type = Res::ERes::INVALID;
 
-	if(!S.tryGet(1, type))
+	if(!S.tryGet(2, type))
 		return S.retVoid();
 
 	S.clear();
@@ -95,13 +112,17 @@ int SetResourcesProxy::getAmount(lua_State * L, std::shared_ptr<SetResources> ob
 	return 1;
 }
 
-int SetResourcesProxy::setAmount(lua_State * L, std::shared_ptr<SetResources> object)
+int SetResourcesProxy::setAmount(lua_State * L)
 {
 	LuaStack S(L);
 
+	std::shared_ptr<SetResources> object;
+	if(!S.tryGet(1, object))
+		return S.retVoid();
+
 	Res::ERes type = Res::ERes::INVALID;
 
-	if(!S.tryGet(1, type))
+	if(!S.tryGet(2, type))
 		return S.retVoid();
 
 	int typeIdx = static_cast<int>(type);
@@ -111,7 +132,7 @@ int SetResourcesProxy::setAmount(lua_State * L, std::shared_ptr<SetResources> ob
 
 	TQuantity amount = 0;
 
-	if(!S.tryGet(2, amount))
+	if(!S.tryGet(3, amount))
 		return S.retVoid();
 
 	object->res.at(typeIdx) = amount;
@@ -119,9 +140,14 @@ int SetResourcesProxy::setAmount(lua_State * L, std::shared_ptr<SetResources> ob
 	return S.retVoid();
 }
 
-int SetResourcesProxy::clear(lua_State * L, std::shared_ptr<SetResources> object)
+int SetResourcesProxy::clear(lua_State * L)
 {
 	LuaStack S(L);
+
+	std::shared_ptr<SetResources> object;
+	if(!S.tryGet(1, object))
+		return S.retVoid();
+
 	object->res.amin(0);
 	object->res.positive();
 	return S.retVoid();

+ 7 - 8
scripting/lua/api/netpacks/SetResources.h

@@ -24,16 +24,15 @@ class SetResourcesProxy : public SharedWrapper<SetResources, SetResourcesProxy>
 public:
 	using Wrapper = SharedWrapper<SetResources, SetResourcesProxy>;
 
-	static const std::vector<Wrapper::RegType> REGISTER;
 	static const std::vector<typename Wrapper::CustomRegType> REGISTER_CUSTOM;
 
-	static int getAbs(lua_State * L, std::shared_ptr<SetResources> object);
-	static int setAbs(lua_State * L, std::shared_ptr<SetResources> object);
-	static int getPlayer(lua_State * L, std::shared_ptr<SetResources> object);
-	static int setPlayer(lua_State * L, std::shared_ptr<SetResources> object);
-	static int getAmount(lua_State * L, std::shared_ptr<SetResources> object);
-	static int setAmount(lua_State * L, std::shared_ptr<SetResources> object);
-	static int clear(lua_State * L, std::shared_ptr<SetResources> object);
+	static int getAbs(lua_State * L);
+	static int setAbs(lua_State * L);
+	static int getPlayer(lua_State * L);
+	static int setPlayer(lua_State * L);
+	static int getAmount(lua_State * L);
+	static int setAmount(lua_State * L);
+	static int clear(lua_State * L);
 };
 
 }