HotfixFlags.cpp 959 B

12345678910111213141516171819202122232425262728293031323334353637
  1. #include <stddef.h>
  2. #include <stdlib.h>
  3. int* xlua_hotfix_flags = NULL;
  4. int xlua_hotfix_flags_len = 0;
  5. extern "C" {
  6. int xlua_get_hotfix_flag(int idx) {
  7. if (idx >= xlua_hotfix_flags_len) {
  8. return 0;
  9. } else {
  10. return xlua_hotfix_flags[idx];
  11. }
  12. }
  13. void xlua_set_hotfix_flag(int idx, int flag) {
  14. int i = 0;
  15. int* new_hotfix_flags = NULL;
  16. if (idx >= xlua_hotfix_flags_len) {
  17. if (xlua_hotfix_flags == NULL) {
  18. xlua_hotfix_flags = (int*)malloc((idx + 1) * sizeof(int));
  19. } else {
  20. new_hotfix_flags = (int*)realloc(xlua_hotfix_flags, (idx + 1) * sizeof(int));
  21. if (NULL == new_hotfix_flags) { // just skip operation
  22. return;
  23. }
  24. xlua_hotfix_flags = new_hotfix_flags;
  25. }
  26. for(i = xlua_hotfix_flags_len; i < (idx + 1); i++) {
  27. xlua_hotfix_flags[i] = 0;
  28. }
  29. xlua_hotfix_flags_len = idx + 1;
  30. }
  31. xlua_hotfix_flags[idx] = flag;
  32. }
  33. }