My problem is this. I am making a script engine using lua 5.1.4 for a game engine. At some point I want my script to be able to create an event for example a InitializeEvent (there are other events) which will be done through calling this method:
int ParticleSubSystem::GetIniEvent(lua_State* L) {
IEvent<InitializeEventArg>& e = en->InitializeEvent();
lua_pushlightuserdata(L, &e);
return 1;
}
Next I want the script to be able to create a listener on for example a InitializeEvent such as a ParticleSystem (there are other listeners). This is the code for this:
int ParticleSubSystem::GetParticleSystem(lua_State* L) {
OpenEngine::ParticleSystem::ParticleSystem* ps = new OpenEngine::ParticleSystem::ParticleSystem();
lua_pushlightuserdata(L, ps);
return 1;
}
Now I would like to attach the listener to the event but since all type information is lost when parsing stuff from and to lua I have the following problem:
int ParticleSubSystem::Attach(lua_State* L) {
IEvent<????????>* event = (IEvent<?????????>*) lua_touserdata(L, -1);
IListener<???????>* lis = (IListener<????????>*) lua_touserdata(L, -2);
event->Attach(lis);
return 0;
}
Is there any way to pass a type argument around so you can do this:
int ParticleSubSystem::Attach(lua_State* L) {
Type t = ......; //???????
IEvent<t>* event = (IEvent<t>*) lua_touserdata(L, -1);
IListener<t>* lis = (IListener<t>*) lua_touserdata(L, -2);
event->Attach(lis);
return 0;
}
I have tried using strings and macros but can't crack it. Also I have considered the typeid library but can't see any way to get a type argument out of a object using it. Any ideas or confirmation that it is impossible would be appreciated.