| 342 | } |
| 343 | |
| 344 | void PushDiagnosticToLua(lua_State *L, std::vector<LuaDiagnosticInfo> &diagnosticInfos) { |
| 345 | int count = 1; |
| 346 | lua_newtable(L); |
| 347 | for (auto &diagnosticInfo: diagnosticInfos) { |
| 348 | // 诊断信息表 |
| 349 | lua_newtable(L); |
| 350 | |
| 351 | //message |
| 352 | { |
| 353 | lua_pushstring(L, "message"); |
| 354 | lua_pushlstring(L, diagnosticInfo.Message.c_str(), diagnosticInfo.Message.size()); |
| 355 | lua_rawset(L, -3); |
| 356 | |
| 357 | lua_pushstring(L, "type"); |
| 358 | lua_pushstring(L, GetDiagnosisString(diagnosticInfo.Type).c_str()); |
| 359 | lua_rawset(L, -3); |
| 360 | |
| 361 | // data |
| 362 | if (!diagnosticInfo.Data.empty()) { |
| 363 | lua_pushstring(L, "data"); |
| 364 | lua_pushlstring(L, diagnosticInfo.Data.c_str(), diagnosticInfo.Data.size()); |
| 365 | lua_rawset(L, -3); |
| 366 | } |
| 367 | } |
| 368 | |
| 369 | // range |
| 370 | { |
| 371 | lua_pushstring(L, "range"); |
| 372 | //range table |
| 373 | lua_newtable(L); |
| 374 | |
| 375 | lua_pushstring(L, "start"); |
| 376 | // start table |
| 377 | lua_newtable(L); |
| 378 | lua_pushstring(L, "line"); |
| 379 | lua_pushinteger(L, diagnosticInfo.Start.Line); |
| 380 | lua_rawset(L, -3); |
| 381 | |
| 382 | lua_pushstring(L, "character"); |
| 383 | lua_pushinteger(L, diagnosticInfo.Start.Col); |
| 384 | lua_rawset(L, -3); |
| 385 | |
| 386 | lua_rawset(L, -3);// set start = {} |
| 387 | |
| 388 | lua_pushstring(L, "end"); |
| 389 | // end table |
| 390 | lua_newtable(L); |
| 391 | lua_pushstring(L, "line"); |
| 392 | lua_pushinteger(L, diagnosticInfo.End.Line); |
| 393 | lua_rawset(L, -3); |
| 394 | |
| 395 | lua_pushstring(L, "character"); |
| 396 | lua_pushinteger(L, diagnosticInfo.End.Col); |
| 397 | lua_rawset(L, -3); |
| 398 | |
| 399 | lua_rawset(L, -3);// set end = {} |
| 400 | |
| 401 | lua_rawset(L, -3);// set range = {} |
no test coverage detected