Skip to content

Commit 0e86c76

Browse files
authored
Merge pull request #105 from Zorono/patch-1
another fix for C2999 error
2 parents 1d2b9b4 + ab479c4 commit 0e86c76

File tree

1 file changed

+23
-17
lines changed

1 file changed

+23
-17
lines changed

amx-deps/src/syscalls.cpp

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -70,27 +70,33 @@ AMX_NATIVE boundNatives[MAX_SAMP_NATIVES];
7070

7171
template<size_t index>
7272
struct NativeGenerator {
73-
static const char* BoundNativeName;
74-
75-
static cell AMX_NATIVE_CALL DoNative(AMX* amx, const cell* params) {
76-
return n_samp(amx, params, BoundNativeName);
77-
}
78-
79-
static void Generate() {
80-
boundNativeNames[index] = &BoundNativeName;
81-
boundNatives[index] = reinterpret_cast<AMX_NATIVE>(&DoNative);
82-
83-
if constexpr (index + 1 < MAX_SAMP_NATIVES) {
84-
NativeGenerator<index + 1>::Generate();
85-
}
86-
}
73+
static const char* BoundNativeName;
74+
static cell AMX_NATIVE_CALL DoNative(AMX* amx, const cell* params) {
75+
return n_samp(amx, params, BoundNativeName);
76+
}
77+
78+
static void Register() {
79+
boundNativeNames[index] = &BoundNativeName;
80+
boundNatives[index] = reinterpret_cast<AMX_NATIVE>(&DoNative);
81+
}
8782
};
8883

89-
template<> struct NativeGenerator<MAX_SAMP_NATIVES> {};
90-
9184
template<size_t index>
9285
const char* NativeGenerator<index>::BoundNativeName = nullptr;
9386

87+
template<size_t Start, size_t End>
88+
struct RecursiveRegister {
89+
static void Run() {
90+
if constexpr (Start == End) {
91+
NativeGenerator<Start>::Register();
92+
} else {
93+
constexpr size_t Mid = Start + (End - Start) / 2;
94+
RecursiveRegister<Start, Mid>::Run();
95+
RecursiveRegister<Mid + 1, End>::Run();
96+
}
97+
}
98+
};
99+
94100
int callLuaMTRead(lua_State *luaVM) {
95101
luaL_checktype(luaVM, 1, LUA_TTABLE);
96102
lua_getfield(luaVM, 1, "amx");
@@ -463,7 +469,7 @@ void initSAMPSyscalls() {
463469
if(!mainVM || sampNatives)
464470
return;
465471

466-
NativeGenerator<0>::Generate();
472+
RecursiveRegister<0, MAX_SAMP_NATIVES - 1>::Run();
467473

468474
lua_getglobal(mainVM, "g_SAMPSyscallPrototypes");
469475
int numNatives = 0;

0 commit comments

Comments
 (0)