#ifndef _CORE_H_ #define _CORE_H_ #include #include #ifndef CTASSERT #define CTASSERT(x) typedef char __assert ## y[(x) ? 1 : -1]; #endif //use this to send a signal to the client. //it may not be completely fully-baked yet though void* ClientSignal(const char* type, void* obj, const char* _param, void* value); class EMUFILE_HAWK; //use this to print output to the client extern EMUFILE_HAWK* con; //this is supposedly illegal. but i say its perfectly legal, as long as im not using virtual functions. so stuff it. //well, since we're doing it illegally, we need to resist the urge to generalize the function pointer system (to emufile and disc) //since we may need to change all these later to work un-generalized //but seriously. before doing that, i would rather return sizeof(functionpointer) bytes as a token to the managed code and pass that back in //(MP stands for MEMBER POINTER) //we could also try using the FastDelegate. really, we probably should. template void* MP(const T& a) { union U{ void* vp; T t; } u; u.t = a; return u.vp; CTASSERT(sizeof(U)==4||(sizeof(U)==8&&sizeof(void*)==8)); } //this is a function pointer which can be assigned without having to type the function protoype again to cast it. template class __FP { private: template T MPX(void* a) { union U{ void* vp; T t; } u; u.vp = a; return u.t; CTASSERT(sizeof(U)==4||(sizeof(U)==8&&sizeof(void*)==8)); } //protected: public: T func; void set(void* val) { func = MPX(val); } }; //---------------- //these templates help us call a function pointer directly with () instead of fp.func() template struct FUNC0 : public __FP { public: R operator()() { return func(); } }; template struct FUNC1 : public __FP { public: R operator()(A1 a1) { return func(a1); } }; template struct FUNC2 : public __FP { public: R operator()(A1 a1, A2 a2) { return func(a1,a2); } }; template struct FUNC3 : public __FP { public: R operator()(A1 a1, A2 a2, A3 a3) { return func(a1,a2,a3); } }; template struct FUNC4 : public __FP { public: R operator()(A1 a1, A2 a2, A3 a3, A4 a4) { return func(a1,a2,a3,a4); } }; template class FUNC; template class FUNC : public FUNC0 {}; template class FUNC : public FUNC1 {}; template class FUNC : public FUNC2 {}; template class FUNC : public FUNC3 {}; template class FUNC : public FUNC4 {}; //---------------- void _registerFunction(const char* _name, void* _funcptr); struct FunctionRecord { FunctionRecord(const char* _name, void* _funcptr) { _registerFunction(_name,_funcptr); } }; //register a core object member function. put it in a global static array template FunctionRecord REG(const char* name, const T& a) { return FunctionRecord(name,MP(a)); } #endif //_CORE_H_