• Empty GM - From the Wiki
    3 replies, posted
After making this, I realized how inconsistent people name parameters... Output: [URL="http://puu.sh/58Pwc/3a4426ee0f.zip"]example.zip[/URL] -snip- Didn't realize how big those would be. [t]http://puu.sh/58Pcs/8500d01541.png[/t] [code] local CLIENTSIDE = {}; local SERVERSIDE = {}; local SHARED = {}; local CACHED = {}; local iTotal = 0; local iFinished = 0; local sTemplateArgs = [[--]] .. "[[\n" .. [[ ${func} ${desc} ]] .. "]]" .. [[-- function GM:${func}( ${args} ) return self.BaseClass.${func}( self, ${args} ); end ]]; local sTemplateNoArgs = [[--]] .. "[[\n" .. [[ ${func} ${desc} ]] .. "]]" .. [[-- function GM:${func}() return self.BaseClass.${func}( self ); end ]]; local function GrabContent( sString, sPrefix, sSuffix, Table, iOffset ) Table = Table or {}; iOffset = iOffset or 0; local iStart, iEnd, sFound = string.find( sString, sPrefix .. "(.-)" .. sSuffix, iOffset ); if ( isstring( sFound ) ) then table.insert( Table, string.Trim( sFound ) ); return GrabContent( sString, sPrefix, sSuffix, Table, iEnd ); end return Table; end local function Export( sName, tHooks ) local sFile = sName .. ".txt"; print( "EXPORTING " .. sFile ); file.Delete( sFile ); if ( sName == "init" ) then file.Append( sFile, "AddCSLuaFile( \"cl_init.lua\" );\nAddCSLuaFile( \"shared.lua\" );\ninclude( \"shared.lua\" );\n\n" ); elseif ( sName == "cl_init" ) then file.Append( sFile, "include( \"shared.lua\" );\n\n" ); elseif ( sName == "shared" ) then file.Append( sFile, "GM.Name\t\t= \"\";\nGM.Author\t= \"\";\nGM.Email\t= \"\";\nGM.Website\t= \"\";\n\n" ); end for k, v in SortedPairs( tHooks ) do if ( v == nil ) then continue; end local sOutput = v.args && #v.args > 0 and sTemplateArgs or sTemplateNoArgs; sOutput = string.Replace( sOutput, "${func}", k ); sOutput = string.Replace( sOutput, "${args}", ( v.args and table.concat( v.args, ", " ) ) or "" ); if ( v.desc ) then for k, s in pairs( v.desc ) do v.desc[ k ] = string.gsub( s, "<.->", "" ); end end sOutput = string.Replace( sOutput, "${desc}", v.desc and v.desc[1] or "" ); file.Append( sFile, sOutput ); end end local function Parse( tDest ) iFinished = 0; iTotal = 0; for k, v in SortedPairs( GAMEMODE ) do if ( type( v ) == "function" ) then iTotal = iTotal + 1; http.Fetch( "http://wiki.garrysmod.com/page/GM/" .. k, function( sBody ) if ( string.find( sBody, "There is currently no text in this page." ) ) then tDest[ k ] = {}; print( "Hook " .. k .. " needs to be documented." ); else tDest[ k ] = { args = GrabContent( sBody, "<span class=\"arg_chunk\">.-</a>", "</span>" ), desc = GrabContent( sBody, '>Description</span>.-<p>', "</p>" ) }; end if ( tDest[ k ] && tDest[ k ].args && #tDest[ k ].args > 0 ) then print( "GM:" .. k .. "( " .. table.concat( tDest[ k ].args, ", " ).. " )" ); else print( "GM:" .. k .. "()" ); end iFinished = iFinished + 1; if ( iFinished == iTotal ) then if ( SERVER ) then net.Start( "ShareHooks" ); net.WriteTable( SERVERSIDE ); net.Send( player.GetAll()[ 1 ] ); net.Start( "GetHooks" ); net.Send( player.GetAll()[ 1 ] ); else for k, v in pairs( SERVERSIDE ) do if ( CLIENTSIDE[ k ] ) then SHARED[ k ] = v; SERVERSIDE[ k ] = nil; CLIENTSIDE[ k ] = nil; end end Export( "init", SERVERSIDE ); Export( "cl_init", CLIENTSIDE ); Export( "shared", SHARED ); end end end); end end end concommand.Add( "generate_basegm", function( Player, sCommand, tArguments ) Parse( SERVERSIDE ); end ); if ( SERVER ) then util.AddNetworkString( "ShareHooks" ); util.AddNetworkString( "GetHooks" ); else net.Receive( "GetHooks", function( ) Parse( CLIENTSIDE ); end ); net.Receive( "ShareHooks", function( iLen ) SERVERSIDE = net.ReadTable(); end ); end[/code]
Ok and I thought I was good with Lua. What does that first function even mean? Why are there $'s? Much confuse.
it's probably wiki markup, whatever he's done has made Facepunch's syntax highlighting choke and die (I don't think it understands Lua's multiline string literals) and that's why it looks funny.
[QUOTE=bobbleheadbob;42762215]Ok and I thought I was good with Lua. What does that first function even mean? Why are there $'s? Much confuse.[/QUOTE] It's actually just a string with [[]]'s instead of quotation marks so I didn't have to use \t's and \n's. [QUOTE=Luni;42762631]it's probably wiki markup, whatever he's done has made Facepunch's syntax highlighting choke and die (I don't think it understands Lua's multiline string literals) and that's why it looks funny.[/QUOTE] Yep.
Sorry, you need to Log In to post a reply to this thread.