cinterface.cpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #include "cinterface.h"
  23. #include "console/compiler.h"
  24. #include "windowManager/platformWindow.h"
  25. CInterface& CInterface::GetCInterface()
  26. {
  27. static CInterface INSTANCE;
  28. return INSTANCE;
  29. }
  30. bool CInterface::isMethod(const char* className, const char* methodName)
  31. {
  32. return GetCInterface()._isMethod(className, methodName);
  33. }
  34. const char* CInterface::CallFunction(const char* nameSpace, const char* name, const char **argv, int argc, bool *result)
  35. {
  36. return GetCInterface()._CallFunction(nameSpace, name, argv, argc, result);
  37. }
  38. const char* CInterface::CallMethod(SimObject* obj, const char* name, const char **argv, int argc, bool *res)
  39. {
  40. return GetCInterface()._CallMethod(obj->getClassName(), obj->getClassNamespace(), obj->getId(), name, argv, argc, res);
  41. }
  42. void CInterface::CallMain(bool *res)
  43. {
  44. GetCInterface()._CallMain(res);
  45. }
  46. bool CInterface::_isMethod(const char* className, const char* methodName) const
  47. {
  48. if (mIsMethodCallback)
  49. return mIsMethodCallback(className, methodName);
  50. return false;
  51. }
  52. const char* CInterface::_CallFunction(const char* nameSpace, const char* name, const char **argv, int argc, bool *result) const
  53. {
  54. if (mFunctionCallback)
  55. return mFunctionCallback(nameSpace, name, argv, argc, result);
  56. *result = false;
  57. return NULL;
  58. }
  59. const char* CInterface::_CallMethod(const char* className, const char* classNamespace, U32 object, const char* name, const char **argv, int argc, bool *res) const
  60. {
  61. if (mMethodCallback)
  62. return mMethodCallback(className, classNamespace, object, name, argv, argc, res);
  63. *res = false;
  64. return NULL;
  65. }
  66. void CInterface::_CallMain(bool *res) const
  67. {
  68. if (mMainCallback)
  69. {
  70. *res = true;
  71. mMainCallback();
  72. return;
  73. }
  74. *res = false;
  75. }
  76. TORQUE_API void SetCallbacks(void* ptr, void* methodPtr, void* isMethodPtr, void* mainPtr) {
  77. CInterface::GetCInterface().SetCallFunctionCallback(ptr);
  78. CInterface::GetCInterface().SetCallMethodCallback(methodPtr);
  79. CInterface::GetCInterface().SetCallIsMethodCallback(isMethodPtr);
  80. CInterface::GetCInterface().SetMainCallback(mainPtr);
  81. }