Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

133 lines
3.1 KiB

  1. /* see copyright notice in squirrel.h */
  2. #include <squirrel.h>
  3. #include <sqstdaux.h>
  4. #include <assert.h>
  5. #if defined(VSCRIPT_DLL_EXPORT) || defined(VSQUIRREL_TEST)
  6. #include "memdbgon.h"
  7. #endif
  8. void sqstd_printcallstack(HSQUIRRELVM v)
  9. {
  10. SQPRINTFUNCTION pf = sq_getprintfunc(v);
  11. if(pf) {
  12. SQStackInfos si;
  13. SQInteger i;
  14. SQBool b;
  15. SQFloat f;
  16. const SQChar *s;
  17. SQInteger level=1; //1 is to skip this function that is level 0
  18. const SQChar *name=0;
  19. SQInteger seq=0;
  20. pf(v,_SC("\nCALLSTACK\n"));
  21. while(SQ_SUCCEEDED(sq_stackinfos(v,level,&si)))
  22. {
  23. const SQChar *fn=_SC("unknown");
  24. const SQChar *src=_SC("unknown");
  25. if(si.funcname)fn=si.funcname;
  26. if(si.source)src=si.source;
  27. pf(v,_SC("*FUNCTION [%s()] %s line [%d]\n"),fn,src,si.line);
  28. level++;
  29. }
  30. level=0;
  31. pf(v,_SC("\nLOCALS\n"));
  32. for(level=0;level<10;level++){
  33. seq=0;
  34. while((name = sq_getlocal(v,level,seq)))
  35. {
  36. seq++;
  37. switch(sq_gettype(v,-1))
  38. {
  39. case OT_NULL:
  40. pf(v,_SC("[%s] NULL\n"),name);
  41. break;
  42. case OT_INTEGER:
  43. sq_getinteger(v,-1,&i);
  44. pf(v,_SC("[%s] %d\n"),name,i);
  45. break;
  46. case OT_FLOAT:
  47. sq_getfloat(v,-1,&f);
  48. pf(v,_SC("[%s] %.14g\n"),name,f);
  49. break;
  50. case OT_USERPOINTER:
  51. pf(v,_SC("[%s] USERPOINTER\n"),name);
  52. break;
  53. case OT_STRING:
  54. sq_getstring(v,-1,&s);
  55. pf(v,_SC("[%s] \"%s\"\n"),name,s);
  56. break;
  57. case OT_TABLE:
  58. pf(v,_SC("[%s] TABLE\n"),name);
  59. break;
  60. case OT_ARRAY:
  61. pf(v,_SC("[%s] ARRAY\n"),name);
  62. break;
  63. case OT_CLOSURE:
  64. pf(v,_SC("[%s] CLOSURE\n"),name);
  65. break;
  66. case OT_NATIVECLOSURE:
  67. pf(v,_SC("[%s] NATIVECLOSURE\n"),name);
  68. break;
  69. case OT_GENERATOR:
  70. pf(v,_SC("[%s] GENERATOR\n"),name);
  71. break;
  72. case OT_USERDATA:
  73. pf(v,_SC("[%s] USERDATA\n"),name);
  74. break;
  75. case OT_THREAD:
  76. pf(v,_SC("[%s] THREAD\n"),name);
  77. break;
  78. case OT_CLASS:
  79. pf(v,_SC("[%s] CLASS\n"),name);
  80. break;
  81. case OT_INSTANCE:
  82. pf(v,_SC("[%s] INSTANCE\n"),name);
  83. break;
  84. case OT_WEAKREF:
  85. pf(v,_SC("[%s] WEAKREF\n"),name);
  86. break;
  87. case OT_BOOL:{
  88. sq_getbool(v,-1,&b);
  89. pf(v,_SC("[%s] %s\n"),name,b?_SC("true"):_SC("false"));
  90. }
  91. break;
  92. default: Assert(0); break;
  93. }
  94. sq_pop(v,1);
  95. }
  96. }
  97. }
  98. }
  99. static SQInteger _sqstd_aux_printerror(HSQUIRRELVM v)
  100. {
  101. SQPRINTFUNCTION pf = sq_getprintfunc(v);
  102. if(pf) {
  103. const SQChar *sErr = 0;
  104. if(sq_gettop(v)>=1) {
  105. if(SQ_SUCCEEDED(sq_getstring(v,2,&sErr))) {
  106. pf(v,_SC("\nAN ERROR HAS OCCURED [%s]\n"),sErr);
  107. }
  108. else{
  109. pf(v,_SC("\nAN ERROR HAS OCCURED [unknown]\n"));
  110. }
  111. sqstd_printcallstack(v);
  112. }
  113. }
  114. return 0;
  115. }
  116. void _sqstd_compiler_error(HSQUIRRELVM v,const SQChar *sErr,const SQChar *sSource,SQInteger line,SQInteger column)
  117. {
  118. SQPRINTFUNCTION pf = sq_getprintfunc(v);
  119. if(pf) {
  120. pf(v,_SC("%s line = (%d) column = (%d) : error %s\n"),sSource,line,column,sErr);
  121. }
  122. }
  123. void sqstd_seterrorhandlers(HSQUIRRELVM v)
  124. {
  125. sq_setcompilererrorhandler(v,_sqstd_compiler_error);
  126. sq_newclosure(v,_sqstd_aux_printerror,0);
  127. sq_seterrorhandler(v);
  128. }