InternalCalls.cpp 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #include "il2cpp-config.h"
  2. #include "vm/InternalCalls.h"
  3. #include "vm/Runtime.h"
  4. #include <map>
  5. #include <string>
  6. typedef std::map<std::string, Il2CppMethodPointer> ICallMap;
  7. static ICallMap s_InternalCalls;
  8. namespace il2cpp
  9. {
  10. namespace vm
  11. {
  12. void InternalCalls::Add(const char* name, Il2CppMethodPointer method)
  13. {
  14. //ICallMap::iterator res = s_InternalCalls.find(name);
  15. // TODO: Don't assert right now because Unity adds some icalls multiple times.
  16. //if (res != icalls.end())
  17. // IL2CPP_ASSERT(0 && "Adding internal call twice!");
  18. IL2CPP_ASSERT(method);
  19. s_InternalCalls[name] = method;
  20. }
  21. Il2CppMethodPointer InternalCalls::Resolve(const char* name)
  22. {
  23. // Try to find the whole name first, then search using just type::method
  24. // if parameters were passed
  25. // ex: First, System.Foo::Bar(System.Int32)
  26. // Then, System.Foo::Bar
  27. ICallMap::iterator res = s_InternalCalls.find(name);
  28. if (res != s_InternalCalls.end())
  29. return res->second;
  30. std::string shortName(name);
  31. size_t index = shortName.find('(');
  32. if (index != std::string::npos)
  33. {
  34. shortName = shortName.substr(0, index);
  35. res = s_InternalCalls.find(shortName);
  36. if (res != s_InternalCalls.end())
  37. return res->second;
  38. }
  39. return NULL;
  40. }
  41. } /* namespace vm */
  42. } /* namespace il2cpp */