Debug.hx 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. /*
  2. * Copyright (C)2005-2017 Haxe Foundation
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a
  5. * copy of this software and associated documentation files (the "Software"),
  6. * to deal in the Software without restriction, including without limitation
  7. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8. * and/or sell copies of the Software, and to permit persons to whom the
  9. * Software is 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
  20. * DEALINGS IN THE SOFTWARE.
  21. */
  22. package lua;
  23. /**
  24. Externs for the "debug" class for Haxe lua
  25. **/
  26. import haxe.Constraints.Function;
  27. import lua.Table.AnyTable;
  28. @:native("debug")
  29. extern class Debug {
  30. /**
  31. This function returns the name and the value of the local variable with
  32. index local of the function at level level of the stack.
  33. **/
  34. public static function getlocal(stackLevel : Int, idx : Int) : Dynamic;
  35. /**
  36. This function assigns the value value to the local variable with index
  37. local of the function at level level of the stack.
  38. Call `getinfo` to check whether the level is valid.
  39. **/
  40. public static function setlocal(stackLevel : Int, varName: String, value: Dynamic) : Void;
  41. /**
  42. Returns a table with information about a function.
  43. **/
  44. public static function getinfo(stackLevel : Int) : DebugInfo;
  45. /**
  46. Sets the given function as a hook.
  47. When called without arguments, `Debug.sethook` turns off the hook.
  48. **/
  49. public static function sethook(?fun : Function, ?monitor : String) : Void;
  50. /**
  51. Enters an interactive mode with the user, running each string that the user enters.
  52. Using simple commands and other debug facilities, the user can inspect
  53. global and local variables, change their values, evaluate expressions,
  54. and so on. A line containing only the word `cont` finishes this function,
  55. so that the caller continues its execution.
  56. Note that commands for `Debug.debug` are not lexically nested within any
  57. function, and so have no direct access to local variables.
  58. **/
  59. public static function debug() : Void;
  60. /**
  61. Returns the current hook settings of the thread, as three values:
  62. the current hook function, the current hook mask, and the current hook count
  63. (as set by the `Debug.sethook` function).
  64. **/
  65. public static function gethook(thread : Thread) : Function;
  66. /**
  67. Returns the registry table.
  68. **/
  69. public static function getregistry() : AnyTable;
  70. /**
  71. Returns the metatable of the given `value` or `null` if it does not have a metatable.
  72. **/
  73. public static function getmetatable(value : AnyTable) : AnyTable;
  74. /**
  75. Sets the metatable for the given `value` to the given `table` (can be `null`).
  76. **/
  77. public static function setmetatable(value : AnyTable, table : AnyTable) : Void;
  78. /**
  79. This function returns the name and the value of the upvalue with index `up`
  80. of the function `f`. The function returns `null` if there is no upvalue with
  81. the given index.
  82. **/
  83. public static function getupvalue(f : Function, up : Int) : Dynamic;
  84. /**
  85. This function assigns the value value to the upvalue with index up of
  86. the function `f`. The function returns `null` if there is no upvalue with
  87. the given index. Otherwise, it returns the name of the upvalue.
  88. **/
  89. public static function setupvalue(f : Function, up : Int, val : Dynamic) : Void;
  90. /**
  91. Returns the Lua value associated to `val`.
  92. If `val` is not a `UserData`, returns `null`.
  93. **/
  94. public static function getuservalue(val : Dynamic) : Dynamic;
  95. /**
  96. Sets the given value as the Lua value associated to the given udata.
  97. `udata` must be a full `UserData`.
  98. **/
  99. public static function setuservalue(udata : Dynamic, val : Dynamic) : Void;
  100. /**
  101. Returns a string with a traceback of the call stack.
  102. @param message (optional) is appended at the beginning of the traceback.
  103. @param level (optional) tells at which level to start the traceback.
  104. default is `1`, the function calling traceback.
  105. **/
  106. public static function traceback(?thread : Thread, ?message : String, ?level : Int) : String;
  107. /**
  108. Returns a unique identifier (as a light userdata) for the upvalue numbered
  109. `n` from the given function `f`.
  110. **/
  111. public static function upvalueid(f : Function, n : Int) : Dynamic;
  112. /**
  113. Make the `n1`-th upvalue of the Lua closure `f1` refer to the `n2`-th
  114. upvalue of the Lua closure `f2`.
  115. **/
  116. public static function upvaluejoin(f1 : Function, n1 : Int, f2 : Function, n2 : Int) : Void;
  117. }
  118. /**
  119. A enumerator that describes the output of `Debug.getinfo()`.
  120. **/
  121. typedef DebugInfo = {
  122. currentline : Int,
  123. func : Function,
  124. istailcall : Bool,
  125. isvararg : Bool,
  126. lastlinedefined : Int,
  127. linedefined : Int,
  128. name : String,
  129. namewhat : String,
  130. nparams : Int,
  131. nups : Int,
  132. short_src : String,
  133. source : String,
  134. what : String
  135. }