NativeStackTrace.hx 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. package haxe;
  2. import haxe.CallStack.StackItem;
  3. /**
  4. Do not use manually.
  5. **/
  6. @:dox(hide)
  7. @:noCompletion
  8. class NativeStackTrace {
  9. @:ifFeature('haxe.NativeStackTrace.exceptionStack')
  10. static public inline function saveStack(exception:Any):Void {
  11. }
  12. static public function callStack():Array<String> {
  13. return switch lua.Debug.traceback() {
  14. case null: [];
  15. case s: s.split('\n').slice(3);
  16. }
  17. }
  18. static public function exceptionStack():Array<String> {
  19. return []; //Not implemented. Maybe try xpcal instead of pcal in genlua.
  20. }
  21. static public function toHaxe(native:Array<String>, skip:Int = 0):Array<StackItem> {
  22. var stack = [];
  23. var cnt = -1;
  24. for (item in native) {
  25. var parts = item.substr(1).split(":"); //`substr` to skip a tab at the beginning of a line
  26. var file = parts[0];
  27. if(file == '[C]') {
  28. continue;
  29. }
  30. ++cnt;
  31. if(skip > cnt) {
  32. continue;
  33. }
  34. var line = parts[1];
  35. var method = if(parts.length <= 2) {
  36. null;
  37. } else {
  38. var methodPos = parts[2].indexOf("'");
  39. if(methodPos < 0) {
  40. null;
  41. } else {
  42. Method(null, parts[2].substring(methodPos + 1, parts[2].length - 1));
  43. }
  44. }
  45. stack.push(FilePos(method, file, Std.parseInt(line)));
  46. }
  47. return stack;
  48. }
  49. }