|
20 | 20 | //OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
21 | 21 | //SOFTWARE. |
22 | 22 |
|
23 | | -import {luaError, luaLenMetamethodSupported, luaRawLen} from "./luafuncs"; |
| 23 | +import {luaAssert, luaError, luaLenMetamethodSupported, luaRawLen} from "./luafuncs"; |
24 | 24 | import {Format} from "./format"; |
25 | 25 | import {Vars} from "./debugger"; |
26 | 26 | import {Thread, mainThread, mainThreadName} from "./thread"; |
@@ -197,6 +197,37 @@ export namespace Send { |
197 | 197 | send(dbgProperties); |
198 | 198 | } |
199 | 199 |
|
| 200 | + function getUpvalues(info: debug.FunctionInfo): { [name: string]: unknown } { |
| 201 | + const ups: { [name: string]: unknown } = { }; |
| 202 | + |
| 203 | + if (!info.nups || !info.func) { |
| 204 | + return ups; |
| 205 | + } |
| 206 | + |
| 207 | + for (const index of $range(1, info.nups)) { |
| 208 | + const [name, val] = debug.getupvalue(info.func, index); |
| 209 | + ups[luaAssert(name)] = val; |
| 210 | + } |
| 211 | + |
| 212 | + return ups; |
| 213 | + } |
| 214 | + |
| 215 | + // eslint-disable-next-line @typescript-eslint/ban-types |
| 216 | + export function functionUpvalues(f: Function): void { |
| 217 | + const dbgProperties: LuaDebug.Properties = { |
| 218 | + tag: "$luaDebug", |
| 219 | + type: "properties", |
| 220 | + properties: Format.makeExplicitArray() |
| 221 | + }; |
| 222 | + const upvalues = getUpvalues(debug.getinfo(f, "fu") as debug.FunctionInfo); |
| 223 | + for (const [key, val] of pairs(upvalues)) { |
| 224 | + const name = getPrintableValue(key); |
| 225 | + const dbgVar = buildVariable(name, val); |
| 226 | + table.insert(dbgProperties.properties, dbgVar); |
| 227 | + } |
| 228 | + send(dbgProperties); |
| 229 | + } |
| 230 | + |
200 | 231 | export function breakpoints(breaks: Breakpoint[]): void { |
201 | 232 | const breakpointList: LuaDebug.Breakpoint[] = []; |
202 | 233 | for (const breakpoint of breaks) { |
|
0 commit comments