I am trying to write some code that wraps C++ functions into something that Lua can use. One of the main problems I'm trying to solve is passing values popped from the Lua stack into parameters for the C++ functions. The naive approach that has worked for me has been:
template<typename Ret, typename... Args>
int luaDRCall(lua_State* s) {
typedef RDelegate<Ret, Args...>* FunctionPtr;
FunctionPtr f = (FunctionPtr)popUpvalueObject(s);
Ret retValue = f->invoke(popValue<Args>(h)...);
return ScriptValueSender<Ret>::push(h, retValue);
}
However, this has caused me problems because "popValue(h)..." is not guaranteed to execute from right to left. Under a "Debug" build from MSVC, it works fine.... but the "Release" version calls the functions in reverse order. Therefore, I have written some code that is guaranteed to pop the values in correct order:
template<typename Ret, typename... Args>
int luaDRCall(lua_State* s) {
void* del = popUpvalueObject(s);
return fRCall<Ret, Args...>(s, del);
}
template<typename Ret, typename Arg, typename... Args>
int fRCall(EnvironmentHandle h, void* del) {
Arg v = popValue<Arg>(h);
return fRCall<Ret, Args..., Arg>(h, del, v);
}
template<typename Ret, typename Arg, typename... Args, typename... Popped>
int fRCall(EnvironmentHandle h, void* del, Popped... vPopped) {
Arg v = popValue<Arg>(h);
return fRCall<Ret, Args..., Popped..., Arg>(h, del, vPopped..., v);
}
template<typename Ret, typename... Args>
int fRCall(EnvironmentHandle h, void* del, Args... vPopped) {
typedef RDelegate<Ret, Args...>* FunctionPtr;
FunctionPtr f = (FunctionPtr)del;
Ret retValue = f->invoke(vPopped...);
return ScriptValueSender<Ret>::push(h, retValue);
}
Now, attempting to compile this code results in:
2>c:\induztry\git\vorb\include\script\Script.h(66): fatal error C1060: compiler is out of heap space
2>c1xx : fatal error C1063: INTERNAL COMPILER ERROR
2> Please choose the Technical Support command on the Visual C++
2> Help menu, or open the Technical Support help file for more information
Anybody have any ideas what is wrong and how I can fix it? Any other solutions to this problem would also be appreciated. Thank you.
Aucun commentaire:
Enregistrer un commentaire