*/}}

la_lualibs.cpp 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /*
  2. * LaGUI: A graphical application framework.
  3. * Copyright (C) 2022-2023 Wu Yiming
  4. *
  5. * This program is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #include "la_5.h"
  19. extern "C" const char* LA_LUA_LIB_COMMON=R"(
  20. function ddump(tbl, ...)
  21. if(type(tbl)~='table') then log("Not a table."); return end
  22. local levels=100
  23. local dtableonly=0
  24. local arg={...}
  25. if(select(1,...)) then levels=select(1,...) end
  26. if(select(2,...)) then dtableonly=select(2,...) end
  27. local checklist = {}
  28. local function print_kv(indent,k,v,t)
  29. log(indent..t.." "..k,v,""..(t==' ' and type(v) or ""))
  30. end
  31. local function innerdump(tbl,indent,lv)
  32. local tablelist={}; local funclist={}; local otherlist={}
  33. checklist[ tostring(tbl) ] = true
  34. for k,v in pairs(tbl) do
  35. if type(v)=="function" then funclist[k]={v,'f'}
  36. elseif type(v)=="table" then tablelist[k]={v,'t'}
  37. else otherlist[k]={v,' '} end
  38. end
  39. for k,v in pairs(tablelist) do
  40. print_kv(indent,k,v[1],v[2])
  41. if (lv<levels and not checklist[ tostring(v[1]) ]) then innerdump(v[1],indent.." ",lv+1) end
  42. end
  43. if(dtableonly==0) then for k,v in pairs(funclist) do print_kv(indent,k,v[1],v[2]) end end
  44. if(dtableonly==0) then for k,v in pairs(otherlist) do print_kv(indent,k,v[1],v[2]) end end
  45. end
  46. checklist[ tostring(tbl) ] = true
  47. innerdump( tbl, "", 0)
  48. end
  49. function tdump(t)
  50. ddump(t,100,1)
  51. end
  52. ffi = require("ffi")
  53. )";