new post | browse code | authors | help | about

LuaBin 2.0

Viewing file root / lua / FunctionDump.lua

  1.  
  2. // Outputs functions and stuff in wiki format
  3.  
  4. OUTPUT = ""
  5.  
  6. if ( SERVER ) then
  7.         xside = file.Read( "ClientFunctions.txt" )
  8. else
  9.         xside = file.Read( "ServerFunctions.txt" )
  10. end
  11.  
  12. xside = xside or ""
  13.  
  14. local function XSide( class, name )
  15.         if ( string.find( xside, class .. "." .. name ) ) then return "[[SHARED|SHD]]" end
  16.         if ( string.find( xside, class .. ":" .. name ) ) then return "[[SHARED|SHD]]" end
  17.        
  18.         if ( SERVER ) then return "[[SERVER|SRV]]" end
  19.        
  20.         return "[[CLIENT|CLI]]"
  21.        
  22. end
  23.  
  24.  
  25. local function GetFunctions( tab )
  26.  
  27.         local functions = {}
  28.  
  29.         for k, v in pairs( tab ) do
  30.  
  31.                 if ( type(v) == "function" ) then
  32.                
  33.                         table.insert( functions, tostring(k) )
  34.                
  35.                 end
  36.        
  37.         end
  38.        
  39.         table.sort( functions )
  40.         return functions
  41.  
  42. end
  43.  
  44.  
  45. local function DoMetaTable( name )
  46.        
  47.         OUTPUT = OUTPUT .. "\n\r==[["..name.."]] ([[Object]])==\n\r"
  48.         func = GetFunctions( _R[ name ] )
  49.        
  50.         if ( type(_R[ name ]) != "table" ) then
  51.                 Msg("Error: _R["..name.."] is not a table!\n")
  52.         end
  53.        
  54.         for k, v in pairs( func ) do
  55.                 OUTPUT = OUTPUT .. XSide( name, v ) .. " [["..name.."]]:[["..name.."."..v.."|"..v.."]]<br />\n"
  56.         end
  57.        
  58. end
  59.  
  60. local function DoLibrary( name )
  61.        
  62.         OUTPUT = OUTPUT .. "\n\r==[["..name.."]] ([[Library]])==\n\r"
  63.        
  64.         if ( type(_G[ name ]) != "table" ) then
  65.                 Msg("Error: _G["..name.."] is not a table!\n")
  66.         end
  67.        
  68.         func = GetFunctions( _G[ name ] )
  69.         for k, v in pairs( func ) do
  70.                 OUTPUT = OUTPUT .. XSide( name, v ) .. " [["..name.."]].[["..name.."."..v.."|"..v.."]]<br />\n"
  71.         end
  72.        
  73. end
  74.  
  75. local Ignores = { "mathx", "stringx", "_G", "_R", "_E", "GAMEMODE", "g_SBoxObjects", "tablex", "color_black",
  76.                                   "color_white", "utilx", "_LOADLIB", "_LOADED", "color_transparent", "filex", "func", "DOF_Ents",
  77.                                   "Morph", "_ENT" }
  78.  
  79. local t ={}
  80.  
  81. for k, v in pairs(_G) do
  82.         if ( type(v) == "table" && type(k) == "string" && !table.HasValue( Ignores, k ) ) then
  83.                 table.insert( t, tostring(k) )
  84.         end
  85. end
  86.  
  87. table.sort( t )
  88. for k, v in pairs( t ) do
  89.     Msg("Library: "..v.."\n")
  90.         DoLibrary( v )
  91. end
  92.  
  93.  
  94. local t = {}
  95.  
  96. for k, v in pairs(_R) do
  97.         if ( type(v) == "table" && type(k) == "string" && !table.HasValue( Ignores, k )  ) then
  98.                 table.insert( t, tostring(k) )
  99.         end
  100. end
  101.  
  102. table.sort( t )
  103. for k, v in pairs( t ) do
  104.         Msg("MetaTable: "..v.."\n")
  105.         DoMetaTable( v )
  106. end
  107.  
  108.  
  109. if ( SERVER ) then
  110.         file.Write( "ServerFunctions.txt", OUTPUT )
  111. else
  112.         file.Write( "ClientFunctions.txt", OUTPUT )
  113. end
  114.  
  115.